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.AbstractMapAbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected OperationCallbackcallbackprotected booleancommitWhether to save the session at the end of the chain execution.protected booleanhandleTransactionWhether this context should handle the transaction.protected ObjectinputThe execution input that will be updated after an operation run with the operation outputprotected LoginStackloginStackA logins stack manage multiple logins and sessions in a single chain executionprotected Map<String,Deque<Object>>stacksEach stack use a key the type of the objects in the stack: document, documents, blob or blobsprotected List<String>traceA list of trace.protected Map<String,Object>varsThe context variables.
 - 
Constructor SummaryConstructors Modifier Constructor Description OperationContext()OperationContext(CoreSession session)protectedOperationContext(CoreSession session, Map<String,Object> bindings)
 - 
Method SummaryAll 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 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()Set<Map.Entry<String,Object>>entrySet()Objectget(Object key)the map API<T> TgetAdapter(Class<T> type)OperationCallbackgetCallback()ObjectgetChainParameter(String key)Gets the parameter associated with the given key from the chain parameters falling back on the global context.Map<String,Object>getChainParameters()CoreSessiongetCoreSession()ObjectgetInput()LoginStackgetLoginStack()NuxeoPrincipalgetPrincipal()OperationContextgetSubContext(boolean isolate)OperationContextgetSubContext(boolean isolate, Object input)Map<String,Object>getVars()OperationContexthandleTransaction(boolean handleTransaction)booleanisCommit()Objectpeek(String type)Objectpop(String type)Objectpull(String type)voidpush(String type, Object obj)Objectput(String key, Object value)Map<String,Object>putChainParameters(Map<String,?> parameters)Objectremove(Object key)Map<String,Object>removeChainParameters()Objectresolve(Object obj)Evaluate the expression against this context if neededvoidsetCallback(OperationCallback chainCallback)voidsetCommit(boolean commit)voidsetCoreSession(CoreSession session)voidsetInput(Object input)voidsetRollback()Set the rollback mark on the current tx.- 
Methods inherited from class java.util.AbstractMapclear, clone, containsKey, containsValue, equals, hashCode, isEmpty, keySet, putAll, size, toString, values
 - 
Methods inherited from class java.lang.Objectfinalize, getClass, notify, notifyAll, wait, wait, wait
 - 
Methods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
 
- 
 
- 
- 
- 
Field Detail- 
commitprotected boolean commit Whether to save the session at the end of the chain execution. The default is true.
 - 
handleTransactionprotected boolean handleTransaction Whether this context should handle the transaction.- Since:
- 2021.18
 
 - 
stacksprotected final Map<String,Deque<Object>> stacks Each stack use a key the type of the objects in the stack: document, documents, blob or blobs
 - 
loginStackprotected LoginStack loginStack A logins stack manage multiple logins and sessions in a single chain execution
 - 
inputprotected Object input The execution input that will be updated after an operation run with the operation output
 - 
traceprotected 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.
 - 
callbackprotected OperationCallback callback - Since:
- 5.7.3 Collect operation invokes.
 
 
- 
 - 
Constructor Detail- 
OperationContextpublic OperationContext() 
 - 
OperationContextpublic OperationContext(CoreSession session) 
 - 
OperationContextprotected OperationContext(CoreSession session, Map<String,Object> bindings) 
 
- 
 - 
Method Detail- 
setCoreSessionpublic void setCoreSession(CoreSession session) 
 - 
setCommitpublic void setCommit(boolean commit) 
 - 
isCommitpublic boolean isCommit() 
 - 
handleTransactionpublic OperationContext handleTransaction(boolean handleTransaction) - Since:
- 2021.18
 
 - 
getCoreSessionpublic CoreSession getCoreSession() 
 - 
getLoginStackpublic LoginStack getLoginStack() 
 - 
getPrincipalpublic NuxeoPrincipal getPrincipal() 
 - 
setInputpublic void setInput(Object input) 
 - 
getInputpublic Object getInput() 
 - 
getAdapterpublic <T> T getAdapter(Class<T> type) 
 - 
closepublic void close() - Specified by:
- closein interface- AutoCloseable
 
 - 
setRollbackpublic 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
 - 
getChainParameterpublic 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
 
 - 
callWithChainParameterspublic <T> T callWithChainParameters(Callable<T> callable, Map<String,Object> parameters) throws OperationException Calls 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
 
 - 
callWithContextVarpublic <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
 
 - 
callprotected <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
 
 - 
getCallbackpublic OperationCallback getCallback() - Since:
- 5.7.3
 
 - 
setCallbackpublic void setCallback(OperationCallback chainCallback) - Since:
- 5.7.3
 
 - 
getSubContextpublic OperationContext getSubContext(boolean isolate, Object input) - Parameters:
- isolate- define if keeps context variables for the subcontext
- input- an input object
- Returns:
- a subcontext
- Since:
- 5.7.3
 
 - 
getSubContextpublic OperationContext getSubContext(boolean isolate) - Parameters:
- isolate- define if keeps context variables for the subcontext
- Returns:
- a subcontext
- Since:
- 9.1
 
 
- 
 
-