Package org.nuxeo.ecm.automation
Class OperationContext
- java.lang.Object
-
- java.util.AbstractMap<String,Object>
-
- org.nuxeo.ecm.automation.OperationContext
-
- All Implemented Interfaces:
AutoCloseable
,Map<String,Object>
- Direct Known Subclasses:
RestOperationContext
public class OperationContext extends AbstractMap<String,Object> implements AutoCloseable
An operation context. Holds context objects, a context parameters map and a list of operations to run.Context objects are:
- The Operation Chain Input - optional. It will be used as the input for the first operation in the chain. If input is null then only VOID methods in the first operation will be matched.
- A Core Session - which is optional and should be provided by the caller. (either at creation time as a
constructor argument, either using the
setCoreSession(CoreSession)
method. When running the operation chain in asynchronous mode another session will be created by preserving the current session credentials.
Each entry in the operation list contains the ID of the operation to be run and a map of operation parameters to use when initializing the operation.
The context parameters map can be filled with contextual information by the caller. Each operation will be able to access the contextual data at runtime and to update it if needed.
- Author:
- Bogdan Stefanescu
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Field Summary
Fields Modifier and Type Field Description protected OperationCallback
callback
protected boolean
commit
Whether to save the session at the end of the chain execution.protected boolean
handleTransaction
Whether this context should handle the transaction.protected Object
input
The execution input that will be updated after an operation run with the operation outputprotected LoginStack
loginStack
A logins stack manage multiple logins and sessions in a single chain executionprotected Map<String,Deque<Object>>
stacks
Each stack use a key the type of the objects in the stack: document, documents, blob or blobsprotected List<String>
trace
A list of trace.protected Map<String,Object>
vars
The context variables.
-
Constructor Summary
Constructors Modifier Constructor Description OperationContext()
OperationContext(CoreSession session)
protected
OperationContext(CoreSession session, Map<String,Object> bindings)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected <T,U>
Tcall(Callable<T> callable, Callable<U> initialize, Consumer<U> restore)
Calls the givencallable
after having backed up the initial state as a result ofinitialize
and restores the initial state afterwards by callingrestore
.<T> T
callWithChainParameters(Callable<T> callable, Map<String,Object> parameters)
Calls the givencallable
after having merged the givenparameters
with the chain parameters stored in theConstants.VAR_RUNTIME_CHAIN
context variable and restores the initial chain parameters afterwards.<T> T
callWithContextVar(Callable<T> callable, String key, Object value)
Calls the givencallable
after having put a variable withkey=value
in the current context and restores the initial context afterwards.void
close()
Set<Map.Entry<String,Object>>
entrySet()
Object
get(Object key)
the map API<T> T
getAdapter(Class<T> type)
OperationCallback
getCallback()
Object
getChainParameter(String key)
Gets the parameter associated with the given key from the chain parameters falling back on the global context.Map<String,Object>
getChainParameters()
CoreSession
getCoreSession()
Object
getInput()
LoginStack
getLoginStack()
NuxeoPrincipal
getPrincipal()
OperationContext
getSubContext(boolean isolate)
OperationContext
getSubContext(boolean isolate, Object input)
Map<String,Object>
getVars()
OperationContext
handleTransaction(boolean handleTransaction)
boolean
isCommit()
Object
peek(String type)
Object
pop(String type)
Object
pull(String type)
void
push(String type, Object obj)
Object
put(String key, Object value)
Map<String,Object>
putChainParameters(Map<String,?> parameters)
Object
remove(Object key)
Map<String,Object>
removeChainParameters()
Object
resolve(Object obj)
Evaluate the expression against this context if neededvoid
setCallback(OperationCallback chainCallback)
void
setCommit(boolean commit)
void
setCoreSession(CoreSession session)
void
setInput(Object input)
void
setRollback()
Set the rollback mark on the current tx.-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Field Detail
-
commit
protected boolean commit
Whether to save the session at the end of the chain execution. The default is true.
-
handleTransaction
protected boolean handleTransaction
Whether this context should handle the transaction.- Since:
- 2021.18
-
stacks
protected final Map<String,Deque<Object>> stacks
Each stack use a key the type of the objects in the stack: document, documents, blob or blobs
-
loginStack
protected LoginStack loginStack
A logins stack manage multiple logins and sessions in a single chain execution
-
input
protected Object input
The execution input that will be updated after an operation run with the operation output
-
trace
protected List<String> trace
A list of trace. Since 5.7.3 messages is no longer useful for tracing. Use chain call backs to do it.
-
callback
protected OperationCallback callback
- Since:
- 5.7.3 Collect operation invokes.
-
-
Constructor Detail
-
OperationContext
public OperationContext()
-
OperationContext
public OperationContext(CoreSession session)
-
OperationContext
protected OperationContext(CoreSession session, Map<String,Object> bindings)
-
-
Method Detail
-
setCoreSession
public void setCoreSession(CoreSession session)
-
setCommit
public void setCommit(boolean commit)
-
isCommit
public boolean isCommit()
-
handleTransaction
public OperationContext handleTransaction(boolean handleTransaction)
- Since:
- 2021.18
-
getCoreSession
public CoreSession getCoreSession()
-
getLoginStack
public LoginStack getLoginStack()
-
getPrincipal
public NuxeoPrincipal getPrincipal()
-
setInput
public void setInput(Object input)
-
getInput
public Object getInput()
-
getAdapter
public <T> T getAdapter(Class<T> type)
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
setRollback
public void setRollback()
Set the rollback mark on the current tx. This will cause the transaction to rollback. Also this is setting the session commit flag on false
-
getChainParameter
public Object getChainParameter(String key)
Gets the parameter associated with the given key from the chain parameters falling back on the global context.- Since:
- 10.2
-
callWithChainParameters
public <T> T callWithChainParameters(Callable<T> callable, Map<String,Object> parameters) throws OperationException
Calls the givencallable
after having merged the givenparameters
with the chain parameters stored in theConstants.VAR_RUNTIME_CHAIN
context variable and restores the initial chain parameters afterwards.- Throws:
OperationException
- Since:
- 10.2
-
callWithContextVar
public <T> T callWithContextVar(Callable<T> callable, String key, Object value) throws OperationException
Calls the givencallable
after having put a variable withkey=value
in the current context and restores the initial context afterwards.- Throws:
OperationException
- Since:
- 10.2
-
call
protected <T,U> T call(Callable<T> callable, Callable<U> initialize, Consumer<U> restore) throws OperationException
Calls the givencallable
after having backed up the initial state as a result ofinitialize
and restores the initial state afterwards by callingrestore
.- Throws:
OperationException
-
getCallback
public OperationCallback getCallback()
- Since:
- 5.7.3
-
setCallback
public void setCallback(OperationCallback chainCallback)
- Since:
- 5.7.3
-
getSubContext
public OperationContext getSubContext(boolean isolate, Object input)
- Parameters:
isolate
- define if keeps context variables for the subcontextinput
- an input object- Returns:
- a subcontext
- Since:
- 5.7.3
-
getSubContext
public OperationContext getSubContext(boolean isolate)
- Parameters:
isolate
- define if keeps context variables for the subcontext- Returns:
- a subcontext
- Since:
- 9.1
-
-