Class OperationServiceImpl
java.lang.Object
org.nuxeo.ecm.automation.core.impl.OperationServiceImpl
- All Implemented Interfaces:
AutomationAdmin
,AutomationService
The operation registry is thread safe and optimized for modifications at startup and lookups at runtime.
- Author:
- Bogdan Stefanescu
-
Field Summary
Modifier and TypeFieldDescriptionprotected AdapterKeyedRegistry
Adapter registry.protected final AutomationFilterRegistry
protected final ChainExceptionRegistry
protected final OperationChainCompiler
static final String
protected final OperationTypeRegistry
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncompileChain
(Class<?> inputType, OperationChain chain) Builds the operation chain given a context.compileChain
(Class<?> inputType, OperationParameters... ops) Same as previous but takes an array of operation parametersvoid
Flush compiled chains to handle hot-reload<T> T
getAdaptedValue
(OperationContext ctx, Object toAdapt, Class<?> targetType) Adapts an object to a target type if possible otherwise throws an exception.protected CatchChainException
getCatchChainExceptionByPriority
(CatchChainException catchChainException, CatchChainException catchChainExceptionItem) getChainException
(String onChainId) protected String
getChainExceptionToRun
(OperationContext ctx, String operationTypeId, OperationException oe) Generates a documentation model for all registered operations.getOperation
(String id) Gets an operation type given its ID.protected OperationChain
Gets all operation types that was registered.getTypeAdapter
(Class<?> accept, Class<?> produce) Gets a type adapter for the input type accept and the output type produce.static Class<?>
getTypeForPrimitive
(Class<?> primitiveType) boolean
hasChainException
(String onChainId) boolean
hasOperation
(String id) boolean
isTypeAdaptable
(Class<?> typeToAdapt, Class<?> targetType) Checks whether or not the given type is adaptable into the target type.void
putAutomationFilter
(AutomationFilter automationFilter) void
putChainException
(ChainException exceptionChain) void
putOperation
(Class<?> type) Registers an operation given its class.void
putOperation
(Class<?> type, boolean replace) Registers an operation given its class.void
putOperation
(Class<?> type, boolean replace, String contributingComponent) Registers an operation given its class.void
putOperation
(Class<?> type, boolean replace, String contributingComponent, List<WidgetDefinition> widgetDefinitionList) void
putOperation
(OperationType op, boolean replace) Registers an operation given it's type.void
putTypeAdapter
(Class<?> accept, Class<?> produce, TypeAdapter adapter) Registers a new type adapter that can adapt an instance of the accepted type into one of the produced type.void
removeAutomationFilter
(AutomationFilter automationFilter) void
removeExceptionChain
(ChainException exceptionChain) void
removeOperation
(Class<?> key) Removes an operation given its class.void
removeOperation
(OperationType type) Removes an operation given it's type.void
removeTypeAdapter
(Class<?> accept, Class<?> produce) Removes a type adapterrun
(OperationContext ctx, String operationId) Same as previous but for managed chains identified by an ID.run
(OperationContext ctx, String operationId, Map<String, ?> args) Shortcut to execute a single operation described by the given ID and map of parametersrun
(OperationContext ctx, OperationChain chain) Builds and runs the operation chain given a context.runInNewTx
(OperationContext ctx, String chainId, Map<String, ?> chainParameters, Integer timeout, boolean rollbackGlobalOnError) This running method execute operation process through a new transaction.static OperationParameters[]
-
Field Details
-
EXPORT_ALIASES_CONFIGURATION_PARAM
- See Also:
-
operations
-
chainExceptionRegistry
-
automationFilterRegistry
-
compiler
-
adapters
Adapter registry.
-
-
Constructor Details
-
OperationServiceImpl
public OperationServiceImpl()
-
-
Method Details
-
run
Description copied from interface:AutomationService
Same as previous but for managed chains identified by an ID. For managed chains always use this method since the compiled chain is cached and run will be faster- Specified by:
run
in interfaceAutomationService
- Throws:
OperationException
-
run
public Object run(OperationContext ctx, String operationId, Map<String, ?> args) throws OperationExceptionDescription copied from interface:AutomationService
Shortcut to execute a single operation described by the given ID and map of parameters- Specified by:
run
in interfaceAutomationService
- Throws:
OperationException
-
run
Description copied from interface:AutomationService
Builds and runs the operation chain given a context. If the context input object or the chain cannot be resolved (no path can be found through all the operation in the chain) thenInvalidChainException
is thrown.- Specified by:
run
in interfaceAutomationService
- Throws:
OperationException
-
runInNewTx
public Object runInNewTx(OperationContext ctx, String chainId, Map<String, ?> chainParameters, Integer timeout, boolean rollbackGlobalOnError) throws OperationExceptionDescription copied from interface:AutomationService
This running method execute operation process through a new transaction.- Specified by:
runInNewTx
in interfaceAutomationService
- Parameters:
ctx
- the operation context.chainId
- the chain Id.chainParameters
- chain parameters.timeout
- Transaction timeout.rollbackGlobalOnError
- Rollback or not transaction after failing.- Throws:
OperationException
-
getChainExceptionToRun
protected String getChainExceptionToRun(OperationContext ctx, String operationTypeId, OperationException oe) throws OperationException - Throws:
OperationException
- Since:
- 5.7.3 Fetch the right chain id to run when catching exception for given chain failure.
-
getCatchChainExceptionByPriority
protected CatchChainException getCatchChainExceptionByPriority(CatchChainException catchChainException, CatchChainException catchChainExceptionItem) - Since:
- 5.7.3
-
toParams
-
getOperationChain
- Throws:
OperationNotFoundException
-
flushCompiledChains
public void flushCompiledChains()Description copied from interface:AutomationAdmin
Flush compiled chains to handle hot-reload- Specified by:
flushCompiledChains
in interfaceAutomationAdmin
-
putOperation
Description copied from interface:AutomationService
Registers an operation given its class. The operation class MUST be annotated usingOperation
annotation. If an operation having the same ID exists an exception will be thrown.- Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
putOperation
Description copied from interface:AutomationService
Registers an operation given its class. The operation class MUST be annotated usingOperation
annotation. If thereplace
argument is true then any existing operation having the same ID will replaced with this one.- Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
putOperation
public void putOperation(Class<?> type, boolean replace, String contributingComponent) throws OperationException Description copied from interface:AutomationService
Registers an operation given its class. The operation class MUST be annotated usingOperation
annotation. If thereplace
argument is true then any existing operation having the same ID will replaced with this one. Third argument represents the name of the component registring the operation- Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
putOperation
public void putOperation(Class<?> type, boolean replace, String contributingComponent, List<WidgetDefinition> widgetDefinitionList) throws OperationException - Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
putOperation
Description copied from interface:AutomationService
Registers an operation given it's type.- Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
removeOperation
Description copied from interface:AutomationService
Removes an operation given its class. If the operation was not registered does nothing.- Specified by:
removeOperation
in interfaceAutomationService
-
removeOperation
Description copied from interface:AutomationService
Removes an operation given it's type. If the operation was not registered does nothing.- Specified by:
removeOperation
in interfaceAutomationService
-
getOperations
Description copied from interface:AutomationService
Gets all operation types that was registered.- Specified by:
getOperations
in interfaceAutomationService
-
getOperation
Description copied from interface:AutomationService
Gets an operation type given its ID. Throws an exception if the operation is not found.- Specified by:
getOperation
in interfaceAutomationService
- Throws:
OperationNotFoundException
-
hasOperation
- Specified by:
hasOperation
in interfaceAutomationService
- Parameters:
id
- operation ID.- Returns:
- true if operation registry contains the given operation.
- Since:
- 5.7.2
-
compileChain
public CompiledChain compileChain(Class<?> inputType, OperationParameters... ops) throws OperationException Description copied from interface:AutomationService
Same as previous but takes an array of operation parameters- Specified by:
compileChain
in interfaceAutomationService
- Throws:
OperationException
-
compileChain
public CompiledChain compileChain(Class<?> inputType, OperationChain chain) throws OperationException Description copied from interface:AutomationService
Builds the operation chain given a context. If the context input object or the chain cannot be resolved (no path can be found through all the operation in the chain) thenInvalidChainException
is thrown. The returned object can be used to run the chain.- Specified by:
compileChain
in interfaceAutomationService
- Throws:
OperationException
-
putTypeAdapter
Description copied from interface:AutomationService
Registers a new type adapter that can adapt an instance of the accepted type into one of the produced type.- Specified by:
putTypeAdapter
in interfaceAutomationService
-
removeTypeAdapter
Description copied from interface:AutomationService
Removes a type adapter- Specified by:
removeTypeAdapter
in interfaceAutomationService
-
getTypeAdapter
Description copied from interface:AutomationService
Gets a type adapter for the input type accept and the output type produce. Returns null if no adapter was registered for these types.- Specified by:
getTypeAdapter
in interfaceAutomationService
-
isTypeAdaptable
Description copied from interface:AutomationService
Checks whether or not the given type is adaptable into the target type. An instance of an adaptable type can be converted into an instance of the target type.This is a shortcut to
getTypeAdapter(typeToAdapt, targetType) != null
- Specified by:
isTypeAdaptable
in interfaceAutomationService
-
getAdaptedValue
public <T> T getAdaptedValue(OperationContext ctx, Object toAdapt, Class<?> targetType) throws OperationException Description copied from interface:AutomationService
Adapts an object to a target type if possible otherwise throws an exception. The method must be called in an operation execution with a valid operation context.- Specified by:
getAdaptedValue
in interfaceAutomationService
- Throws:
OperationException
-
getDocumentation
Description copied from interface:AutomationService
Generates a documentation model for all registered operations. The documentation model is generated from operation annotations and can be used in UI tools to describe operations. The returned list is sorted using operation ID. Optional method.- Specified by:
getDocumentation
in interfaceAutomationService
- Throws:
OperationException
-
getTypeForPrimitive
-
putChainException
- Specified by:
putChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
removeExceptionChain
- Specified by:
removeExceptionChain
in interfaceAutomationService
- Since:
- 5.7.3
-
getChainExceptions
- Specified by:
getChainExceptions
in interfaceAutomationService
- Since:
- 5.7.3
-
getChainException
- Specified by:
getChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
hasChainException
- Specified by:
hasChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
putAutomationFilter
- Specified by:
putAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
removeAutomationFilter
- Specified by:
removeAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
getAutomationFilter
- Specified by:
getAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
getAutomationFilters
- Specified by:
getAutomationFilters
in interfaceAutomationService
- Since:
- 5.7.3
-