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,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OperationCallbackprotected booleanWhether to save the session at the end of the chain execution.protected booleanWhether this context should handle the transaction.protected ObjectThe execution input that will be updated after an operation run with the operation outputprotected LoginStackA 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
ConstructorsModifierConstructorDescriptionOperationContext(CoreSession session) protectedOperationContext(CoreSession session, Map<String, Object> bindings) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T,U> T Calls the givencallableafter having backed up the initial state as a result ofinitializeand restores the initial state afterwards by callingrestore.<T> TcallWithChainParameters(Callable<T> callable, Map<String, Object> parameters) Calls the givencallableafter having merged the givenparameterswith the chain parameters stored in theConstants.VAR_RUNTIME_CHAINcontext variable and restores the initial chain parameters afterwards.<T> TcallWithContextVar(Callable<T> callable, String key, Object value) Calls the givencallableafter having put a variable withkey=valuein the current context and restores the initial context afterwards.voidclose()entrySet()the map API<T> TgetAdapter(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) booleanisCommit()voidputChainParameters(Map<String, ?> parameters) Evaluate the expression against this context if neededvoidsetCallback(OperationCallback chainCallback) voidsetCommit(boolean commit) voidsetCoreSession(CoreSession session) voidvoidSet 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, valuesMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
closein 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 givencallableafter having merged the givenparameterswith the chain parameters stored in theConstants.VAR_RUNTIME_CHAINcontext 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 givencallableafter having put a variable withkey=valuein 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 givencallableafter having backed up the initial state as a result ofinitializeand 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
-