Class OperationServiceImpl
- java.lang.Object
-
- org.nuxeo.ecm.automation.core.impl.OperationServiceImpl
-
- All Implemented Interfaces:
AutomationAdmin
,AutomationService
public class OperationServiceImpl extends Object implements AutomationService, AutomationAdmin
The operation registry is thread safe and optimized for modifications at startup and lookups at runtime.- Author:
- Bogdan Stefanescu
-
-
Field Summary
Fields Modifier and Type Field Description protected AdapterKeyedRegistry
adapters
Adapter registry.protected AutomationFilterRegistry
automationFilterRegistry
protected ChainExceptionRegistry
chainExceptionRegistry
protected OperationChainCompiler
compiler
static String
EXPORT_ALIASES_CONFIGURATION_PARAM
protected OperationTypeRegistry
operations
-
Constructor Summary
Constructors Constructor Description OperationServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledChain
compileChain(Class<?> inputType, OperationChain chain)
Builds the operation chain given a context.CompiledChain
compileChain(Class<?> inputType, OperationParameters... ops)
Same as previous but takes an array of operation parametersvoid
flushCompiledChains()
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.AutomationFilter
getAutomationFilter(String id)
AutomationFilter[]
getAutomationFilters()
protected CatchChainException
getCatchChainExceptionByPriority(CatchChainException catchChainException, CatchChainException catchChainExceptionItem)
ChainException
getChainException(String onChainId)
ChainException[]
getChainExceptions()
protected String
getChainExceptionToRun(OperationContext ctx, String operationTypeId, OperationException oe)
List<OperationDocumentation>
getDocumentation()
Generates a documentation model for all registered operations.OperationType
getOperation(String id)
Gets an operation type given its ID.OperationChain
getOperationChain(String id)
Gets a registered operation chain.List<OperationChain>
getOperationChains()
Gets a list of all registered chainsOperationType[]
getOperations()
Gets all operation types that was registered.TypeAdapter
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
putOperationChain(OperationChain chain)
Registers a parametrized operation chain.void
putOperationChain(OperationChain chain, boolean replace)
Registers a parametrized operation chain.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
removeOperationChain(String id)
Removes a registered operation chain given its ID.void
removeTypeAdapter(Class<?> accept, Class<?> produce)
Removes a type adapterObject
run(OperationContext ctx, String operationId)
Same as previous but for managed chains identified by an ID.Object
run(OperationContext ctx, String operationId, Map<String,?> args)
Shortcut to execute a single operation described by the given ID and map of parametersObject
run(OperationContext ctx, OperationChain chain)
Builds and runs the operation chain given a context.Object
runInNewTx(OperationContext ctx, String chainId, Map<String,?> chainParameters, Integer timeout, boolean rollbackGlobalOnError)
This running method execute operation process through a new transaction.static OperationParameters[]
toParams(String... ids)
-
-
-
Field Detail
-
EXPORT_ALIASES_CONFIGURATION_PARAM
public static final String EXPORT_ALIASES_CONFIGURATION_PARAM
- See Also:
- Constant Field Values
-
operations
protected final OperationTypeRegistry operations
-
chainExceptionRegistry
protected final ChainExceptionRegistry chainExceptionRegistry
-
automationFilterRegistry
protected final AutomationFilterRegistry automationFilterRegistry
-
compiler
protected final OperationChainCompiler compiler
-
adapters
protected AdapterKeyedRegistry adapters
Adapter registry.
-
-
Method Detail
-
run
public Object run(OperationContext ctx, String operationId) throws OperationException
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 OperationException
Description 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
public Object run(OperationContext ctx, OperationChain chain) throws OperationException
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 OperationException
Description 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
public static OperationParameters[] toParams(String... ids)
-
putOperationChain
public void putOperationChain(OperationChain chain) throws OperationException
Description copied from interface:AutomationService
Registers a parametrized operation chain. This chain can be executed later by callingrun
and passing the chain ID. If a chain having the same ID exists an exception is thrown- Specified by:
putOperationChain
in interfaceAutomationService
- Throws:
OperationException
-
putOperationChain
public void putOperationChain(OperationChain chain, boolean replace) throws OperationException
Description copied from interface:AutomationService
Registers a parametrized operation chain. This chain can be executed later by callingrun
and passing the chain ID. If the replace attribute is true then any chain already registered under the same id will be replaced otherwise an exception is thrown.- Specified by:
putOperationChain
in interfaceAutomationService
- Throws:
OperationException
-
removeOperationChain
public void removeOperationChain(String id)
Description copied from interface:AutomationService
Removes a registered operation chain given its ID. Do nothing if the chain was not registered.- Specified by:
removeOperationChain
in interfaceAutomationService
-
getOperationChain
public OperationChain getOperationChain(String id) throws OperationNotFoundException
Description copied from interface:AutomationService
Gets a registered operation chain.- Specified by:
getOperationChain
in interfaceAutomationService
- Throws:
OperationNotFoundException
-
getOperationChains
public List<OperationChain> getOperationChains()
Description copied from interface:AutomationService
Gets a list of all registered chains- Specified by:
getOperationChains
in interfaceAutomationService
- Returns:
- the list or an empty list if no registered chains exists
-
flushCompiledChains
public void flushCompiledChains()
Description copied from interface:AutomationAdmin
Flush compiled chains to handle hot-reload- Specified by:
flushCompiledChains
in interfaceAutomationAdmin
-
putOperation
public void putOperation(Class<?> type) throws OperationException
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
public void putOperation(Class<?> type, boolean replace) 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.- 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
public void putOperation(OperationType op, boolean replace) throws OperationException
Description copied from interface:AutomationService
Registers an operation given it's type.- Specified by:
putOperation
in interfaceAutomationService
- Throws:
OperationException
-
removeOperation
public void removeOperation(Class<?> key)
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
public void removeOperation(OperationType type)
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
public OperationType[] getOperations()
Description copied from interface:AutomationService
Gets all operation types that was registered.- Specified by:
getOperations
in interfaceAutomationService
-
getOperation
public OperationType getOperation(String id) throws OperationNotFoundException
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
public boolean hasOperation(String id)
- 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
public void putTypeAdapter(Class<?> accept, Class<?> produce, TypeAdapter adapter)
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
public void removeTypeAdapter(Class<?> accept, Class<?> produce)
Description copied from interface:AutomationService
Removes a type adapter- Specified by:
removeTypeAdapter
in interfaceAutomationService
-
getTypeAdapter
public TypeAdapter getTypeAdapter(Class<?> accept, Class<?> produce)
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
public boolean isTypeAdaptable(Class<?> typeToAdapt, Class<?> targetType)
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
public List<OperationDocumentation> getDocumentation() throws OperationException
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
-
putChainException
public void putChainException(ChainException exceptionChain)
- Specified by:
putChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
removeExceptionChain
public void removeExceptionChain(ChainException exceptionChain)
- Specified by:
removeExceptionChain
in interfaceAutomationService
- Since:
- 5.7.3
-
getChainExceptions
public ChainException[] getChainExceptions()
- Specified by:
getChainExceptions
in interfaceAutomationService
- Since:
- 5.7.3
-
getChainException
public ChainException getChainException(String onChainId)
- Specified by:
getChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
hasChainException
public boolean hasChainException(String onChainId)
- Specified by:
hasChainException
in interfaceAutomationService
- Since:
- 5.7.3
-
putAutomationFilter
public void putAutomationFilter(AutomationFilter automationFilter)
- Specified by:
putAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
removeAutomationFilter
public void removeAutomationFilter(AutomationFilter automationFilter)
- Specified by:
removeAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
getAutomationFilter
public AutomationFilter getAutomationFilter(String id)
- Specified by:
getAutomationFilter
in interfaceAutomationService
- Since:
- 5.7.3
-
getAutomationFilters
public AutomationFilter[] getAutomationFilters()
- Specified by:
getAutomationFilters
in interfaceAutomationService
- Since:
- 5.7.3
-
-