http://doc.nuxeo.com/display/NXDOC/Contributing+an+Operation
http://doc.nuxeo.com/display/NXDOC/Coding+your+first+operation
org.nuxeo.ecm.automation.core.annotations.*
Operations are stateless. Each time a new instance is created.
Create : New Nuxeo Artifact > Operation > input project / java package / Name (class name) / ID (shown in studio) / Category (where it can be found in studio interface) / requires seam context / Input / Output / Iterable Operation
Operation is class annotated with @Operation,
Operation method(s) is annotated with @OperationMethod, input provided as parameter. More than one operation method can be given, with different input/outputs. However no two operation method both accept Void, for that causes confusion.
Operation is chained so long as previous one's output matches later one's input. Void (operation method with nop parameters) method match any input.
Operation can be injected an OperationContext, through which it can store / retrieve operation states (key/value).
@Context
public OperationContext context;
......
context.put(key, value);
@Context also allows injection an instance of org.nuxeo.ecm.core.api.CoreSession, the current user, etc.
It's recommended to be injected a CoreSession and does not need to close the session - it will be closed by automation service when needed.
Operation can be given parameters when being assembled in a Studio project by an user.
@Param(name = "parameter_name", required=true)
public String some_parameter;
Operation can invoke another operation or operation chain, follow codes in Technical Document reference. However in normal cases this is not necessary.
From Nuxeo Studio, click Export operation icon, select targeted studio project, IDE project, then operations to export.
Specifying parameter value
EL language (See Java EE) can be used to specify value.
XPath is used to identify metadata property
See http://doc.nuxeo.com/display/Studio/Use+of+MVEL+in+Automation+chains and http://doc.nuxeo.com/display/Studio/Understand+Expression+and+Scripting+Languages+Used+in+Nuxeo to understand what can be used (context) in expressions in specifying operation's parameter value.
If given value does not match type of parameter, attempt to use a registered TypeAdapters. If not found exception is thrown. Otherwise value is (adapted and) injected.
With adapter, string values can be adapted into almost all field types:
(Also see Nuxeo studio document "How-tos / Understand Expression and Scripting Languages Used in Nuxeo")
Can be launched in different contexts:
Executed as a unique transaction - if one operation fails, nothing is changed