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 AdapterKeyedRegistryadaptersAdapter registry.protected AutomationFilterRegistryautomationFilterRegistryprotected ChainExceptionRegistrychainExceptionRegistryprotected OperationChainCompilercompilerstatic StringEXPORT_ALIASES_CONFIGURATION_PARAMprotected OperationTypeRegistryoperations
-
Constructor Summary
Constructors Constructor Description OperationServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description CompiledChaincompileChain(Class<?> inputType, OperationChain chain)Builds the operation chain given a context.CompiledChaincompileChain(Class<?> inputType, OperationParameters... ops)Same as previous but takes an array of operation parametersvoidflushCompiledChains()Flush compiled chains to handle hot-reload<T> TgetAdaptedValue(OperationContext ctx, Object toAdapt, Class<?> targetType)Adapts an object to a target type if possible otherwise throws an exception.AutomationFiltergetAutomationFilter(String id)AutomationFilter[]getAutomationFilters()protected CatchChainExceptiongetCatchChainExceptionByPriority(CatchChainException catchChainException, CatchChainException catchChainExceptionItem)ChainExceptiongetChainException(String onChainId)ChainException[]getChainExceptions()protected StringgetChainExceptionToRun(OperationContext ctx, String operationTypeId, OperationException oe)List<OperationDocumentation>getDocumentation()Generates a documentation model for all registered operations.OperationTypegetOperation(String id)Gets an operation type given its ID.OperationChaingetOperationChain(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.TypeAdaptergetTypeAdapter(Class<?> accept, Class<?> produce)Gets a type adapter for the input type accept and the output type produce.static Class<?>getTypeForPrimitive(Class<?> primitiveType)booleanhasChainException(String onChainId)booleanhasOperation(String id)booleanisTypeAdaptable(Class<?> typeToAdapt, Class<?> targetType)Checks whether or not the given type is adaptable into the target type.voidputAutomationFilter(AutomationFilter automationFilter)voidputChainException(ChainException exceptionChain)voidputOperation(Class<?> type)Registers an operation given its class.voidputOperation(Class<?> type, boolean replace)Registers an operation given its class.voidputOperation(Class<?> type, boolean replace, String contributingComponent)Registers an operation given its class.voidputOperation(Class<?> type, boolean replace, String contributingComponent, List<WidgetDefinition> widgetDefinitionList)voidputOperation(OperationType op, boolean replace)Registers an operation given it's type.voidputOperationChain(OperationChain chain)Registers a parametrized operation chain.voidputOperationChain(OperationChain chain, boolean replace)Registers a parametrized operation chain.voidputTypeAdapter(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.voidremoveAutomationFilter(AutomationFilter automationFilter)voidremoveExceptionChain(ChainException exceptionChain)voidremoveOperation(Class<?> key)Removes an operation given its class.voidremoveOperation(OperationType type)Removes an operation given it's type.voidremoveOperationChain(String id)Removes a registered operation chain given its ID.voidremoveTypeAdapter(Class<?> accept, Class<?> produce)Removes a type adapterObjectrun(OperationContext ctx, String operationId)Same as previous but for managed chains identified by an ID.Objectrun(OperationContext ctx, String operationId, Map<String,?> args)Shortcut to execute a single operation described by the given ID and map of parametersObjectrun(OperationContext ctx, OperationChain chain)Builds and runs the operation chain given a context.ObjectrunInNewTx(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:AutomationServiceSame 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:
runin interfaceAutomationService- Throws:
OperationException
-
run
public Object run(OperationContext ctx, String operationId, Map<String,?> args) throws OperationException
Description copied from interface:AutomationServiceShortcut to execute a single operation described by the given ID and map of parameters- Specified by:
runin interfaceAutomationService- Throws:
OperationException
-
run
public Object run(OperationContext ctx, OperationChain chain) throws OperationException
Description copied from interface:AutomationServiceBuilds 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) thenInvalidChainExceptionis thrown.- Specified by:
runin interfaceAutomationService- Throws:
OperationException
-
runInNewTx
public Object runInNewTx(OperationContext ctx, String chainId, Map<String,?> chainParameters, Integer timeout, boolean rollbackGlobalOnError) throws OperationException
Description copied from interface:AutomationServiceThis running method execute operation process through a new transaction.- Specified by:
runInNewTxin 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:AutomationServiceRegisters a parametrized operation chain. This chain can be executed later by callingrunand passing the chain ID. If a chain having the same ID exists an exception is thrown- Specified by:
putOperationChainin interfaceAutomationService- Throws:
OperationException
-
putOperationChain
public void putOperationChain(OperationChain chain, boolean replace) throws OperationException
Description copied from interface:AutomationServiceRegisters a parametrized operation chain. This chain can be executed later by callingrunand 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:
putOperationChainin interfaceAutomationService- Throws:
OperationException
-
removeOperationChain
public void removeOperationChain(String id)
Description copied from interface:AutomationServiceRemoves a registered operation chain given its ID. Do nothing if the chain was not registered.- Specified by:
removeOperationChainin interfaceAutomationService
-
getOperationChain
public OperationChain getOperationChain(String id) throws OperationNotFoundException
Description copied from interface:AutomationServiceGets a registered operation chain.- Specified by:
getOperationChainin interfaceAutomationService- Throws:
OperationNotFoundException
-
getOperationChains
public List<OperationChain> getOperationChains()
Description copied from interface:AutomationServiceGets a list of all registered chains- Specified by:
getOperationChainsin interfaceAutomationService- Returns:
- the list or an empty list if no registered chains exists
-
flushCompiledChains
public void flushCompiledChains()
Description copied from interface:AutomationAdminFlush compiled chains to handle hot-reload- Specified by:
flushCompiledChainsin interfaceAutomationAdmin
-
putOperation
public void putOperation(Class<?> type) throws OperationException
Description copied from interface:AutomationServiceRegisters an operation given its class. The operation class MUST be annotated usingOperationannotation. If an operation having the same ID exists an exception will be thrown.- Specified by:
putOperationin interfaceAutomationService- Throws:
OperationException
-
putOperation
public void putOperation(Class<?> type, boolean replace) throws OperationException
Description copied from interface:AutomationServiceRegisters an operation given its class. The operation class MUST be annotated usingOperationannotation. If thereplaceargument is true then any existing operation having the same ID will replaced with this one.- Specified by:
putOperationin interfaceAutomationService- Throws:
OperationException
-
putOperation
public void putOperation(Class<?> type, boolean replace, String contributingComponent) throws OperationException
Description copied from interface:AutomationServiceRegisters an operation given its class. The operation class MUST be annotated usingOperationannotation. If thereplaceargument 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:
putOperationin interfaceAutomationService- Throws:
OperationException
-
putOperation
public void putOperation(Class<?> type, boolean replace, String contributingComponent, List<WidgetDefinition> widgetDefinitionList) throws OperationException
- Specified by:
putOperationin interfaceAutomationService- Throws:
OperationException
-
putOperation
public void putOperation(OperationType op, boolean replace) throws OperationException
Description copied from interface:AutomationServiceRegisters an operation given it's type.- Specified by:
putOperationin interfaceAutomationService- Throws:
OperationException
-
removeOperation
public void removeOperation(Class<?> key)
Description copied from interface:AutomationServiceRemoves an operation given its class. If the operation was not registered does nothing.- Specified by:
removeOperationin interfaceAutomationService
-
removeOperation
public void removeOperation(OperationType type)
Description copied from interface:AutomationServiceRemoves an operation given it's type. If the operation was not registered does nothing.- Specified by:
removeOperationin interfaceAutomationService
-
getOperations
public OperationType[] getOperations()
Description copied from interface:AutomationServiceGets all operation types that was registered.- Specified by:
getOperationsin interfaceAutomationService
-
getOperation
public OperationType getOperation(String id) throws OperationNotFoundException
Description copied from interface:AutomationServiceGets an operation type given its ID. Throws an exception if the operation is not found.- Specified by:
getOperationin interfaceAutomationService- Throws:
OperationNotFoundException
-
hasOperation
public boolean hasOperation(String id)
- Specified by:
hasOperationin 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:AutomationServiceSame as previous but takes an array of operation parameters- Specified by:
compileChainin interfaceAutomationService- Throws:
OperationException
-
compileChain
public CompiledChain compileChain(Class<?> inputType, OperationChain chain) throws OperationException
Description copied from interface:AutomationServiceBuilds 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) thenInvalidChainExceptionis thrown. The returned object can be used to run the chain.- Specified by:
compileChainin interfaceAutomationService- Throws:
OperationException
-
putTypeAdapter
public void putTypeAdapter(Class<?> accept, Class<?> produce, TypeAdapter adapter)
Description copied from interface:AutomationServiceRegisters a new type adapter that can adapt an instance of the accepted type into one of the produced type.- Specified by:
putTypeAdapterin interfaceAutomationService
-
removeTypeAdapter
public void removeTypeAdapter(Class<?> accept, Class<?> produce)
Description copied from interface:AutomationServiceRemoves a type adapter- Specified by:
removeTypeAdapterin interfaceAutomationService
-
getTypeAdapter
public TypeAdapter getTypeAdapter(Class<?> accept, Class<?> produce)
Description copied from interface:AutomationServiceGets 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:
getTypeAdapterin interfaceAutomationService
-
isTypeAdaptable
public boolean isTypeAdaptable(Class<?> typeToAdapt, Class<?> targetType)
Description copied from interface:AutomationServiceChecks 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:
isTypeAdaptablein interfaceAutomationService
-
getAdaptedValue
public <T> T getAdaptedValue(OperationContext ctx, Object toAdapt, Class<?> targetType) throws OperationException
Description copied from interface:AutomationServiceAdapts 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:
getAdaptedValuein interfaceAutomationService- Throws:
OperationException
-
getDocumentation
public List<OperationDocumentation> getDocumentation() throws OperationException
Description copied from interface:AutomationServiceGenerates 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:
getDocumentationin interfaceAutomationService- Throws:
OperationException
-
putChainException
public void putChainException(ChainException exceptionChain)
- Specified by:
putChainExceptionin interfaceAutomationService- Since:
- 5.7.3
-
removeExceptionChain
public void removeExceptionChain(ChainException exceptionChain)
- Specified by:
removeExceptionChainin interfaceAutomationService- Since:
- 5.7.3
-
getChainExceptions
public ChainException[] getChainExceptions()
- Specified by:
getChainExceptionsin interfaceAutomationService- Since:
- 5.7.3
-
getChainException
public ChainException getChainException(String onChainId)
- Specified by:
getChainExceptionin interfaceAutomationService- Since:
- 5.7.3
-
hasChainException
public boolean hasChainException(String onChainId)
- Specified by:
hasChainExceptionin interfaceAutomationService- Since:
- 5.7.3
-
putAutomationFilter
public void putAutomationFilter(AutomationFilter automationFilter)
- Specified by:
putAutomationFilterin interfaceAutomationService- Since:
- 5.7.3
-
removeAutomationFilter
public void removeAutomationFilter(AutomationFilter automationFilter)
- Specified by:
removeAutomationFilterin interfaceAutomationService- Since:
- 5.7.3
-
getAutomationFilter
public AutomationFilter getAutomationFilter(String id)
- Specified by:
getAutomationFilterin interfaceAutomationService- Since:
- 5.7.3
-
getAutomationFilters
public AutomationFilter[] getAutomationFilters()
- Specified by:
getAutomationFiltersin interfaceAutomationService- Since:
- 5.7.3
-
-