Package org.nuxeo.ecm.automation
Class OperationContext
- All Implemented Interfaces:
AutoCloseable
,Map<String,
Object>
- Direct Known Subclasses:
RestOperationContext
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
Modifier and TypeFieldDescriptionprotected OperationCallback
protected boolean
Whether to save the session at the end of the chain execution.protected boolean
Whether this context should handle the transaction.protected Object
The execution input that will be updated after an operation run with the operation outputprotected LoginStack
A logins stack manage multiple logins and sessions in a single chain executionEach stack use a key the type of the objects in the stack: document, documents, blob or blobsA list of trace.The context variables. -
Constructor Summary
ModifierConstructorDescriptionOperationContext
(CoreSession session) protected
OperationContext
(CoreSession session, Map<String, Object> bindings) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T,
U> T 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()
entrySet()
the map API<T> T
getAdapter
(Class<T> type) getChainParameter
(String key) Gets the parameter associated with the given key from the chain parameters falling back on the global context.getInput()
getSubContext
(boolean isolate) getSubContext
(boolean isolate, Object input) getVars()
handleTransaction
(boolean handleTransaction) boolean
isCommit()
void
putChainParameters
(Map<String, ?> parameters) Evaluate the expression against this context if neededvoid
setCallback
(OperationCallback chainCallback) void
setCommit
(boolean commit) void
setCoreSession
(CoreSession session) void
void
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 Details
-
commit
protected boolean commitWhether to save the session at the end of the chain execution. The default is true. -
handleTransaction
protected boolean handleTransactionWhether this context should handle the transaction.- Since:
- 2021.18
-
vars
The context variables. -
stacks
Each stack use a key the type of the objects in the stack: document, documents, blob or blobs -
loginStack
A logins stack manage multiple logins and sessions in a single chain execution -
input
The execution input that will be updated after an operation run with the operation output -
trace
A list of trace. Since 5.7.3 messages is no longer useful for tracing. Use chain call backs to do it. -
callback
- Since:
- 5.7.3 Collect operation invokes.
-
-
Constructor Details
-
OperationContext
public OperationContext() -
OperationContext
-
OperationContext
-
-
Method Details
-
setCoreSession
-
setCommit
public void setCommit(boolean commit) -
isCommit
public boolean isCommit() -
handleTransaction
- Since:
- 2021.18
-
getCoreSession
-
getLoginStack
-
getPrincipal
-
setInput
-
getInput
-
push
-
peek
-
pop
-
pull
-
getAdapter
-
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 -
getVars
-
get
the map API -
put
-
remove
-
getChainParameters
-
putChainParameters
-
removeChainParameters
-
getChainParameter
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 OperationExceptionCalls 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
-
entrySet
-
getCallback
- Since:
- 5.7.3
-
setCallback
- Since:
- 5.7.3
-
getSubContext
- Parameters:
isolate
- define if keeps context variables for the subcontextinput
- an input object- Returns:
- a subcontext
- Since:
- 5.7.3
-
getSubContext
- Parameters:
isolate
- define if keeps context variables for the subcontext- Returns:
- a subcontext
- Since:
- 9.1
-
resolve
Evaluate the expression against this context if needed- Returns:
- the resolved value
- Since:
- 9.1
-