Nuxeo Server

Calling Automation from Java

Updated: March 18, 2024

On server side, AutomationService can be used to:

  • Run a contributed chain with chain/operations
  • Run a runtime chain created on the fly
  • Run a contributed operation

The Automation service provides chain(s)/operation(s) parameters setting and OperationContext instantiation to inject Automation input(s).

Run Contributed Chain with Chain/Operations

Chain Contribution:

<extension point="chains"
             target="org.nuxeo.ecm.core.operation.OperationServiceComponent">
<chain id="contributedchain">
      <param type="string" name="paramChain" />
      <operation id="o1">
        <param type="string" name="param1">Hello 1!</param>
      </operation>
      <operation id="o2">
        <param type="string" name="param2">Hello 2!</param>
      </operation>
</chain>
</extension>

Automation Service API - with chain parameter setting:

org.nuxeo.ecm.core.api.DocumentModel doc;
org.nuxeo.ecm.automation.AutomationService service;
org.nuxeo.ecm.core.api.CoreSession session;

// Input setting
org.nuxeo.ecm.automation.OperationContext ctx = new OperationContext(session);
ctx.setInput(doc);
// Setting parameters of the chain
Map<String, Object> params = new HashMap<String, Object>();
params.put("paramChain", "Hello i'm a parameter chain!");
// Run Automation service
service.run(ctx, "contributedchain", params);

Run Runtime Chain Created on the Fly

Automation Service API - with chain/operations parameters setting:

org.nuxeo.ecm.core.api.DocumentModel doc;
org.nuxeo.ecm.automation.AutomationService service;
org.nuxeo.ecm.core.api.CoreSession session;

// Input setting
org.nuxeo.ecm.automation.OperationContext ctx = new OperationContext(session);
ctx.setInput(doc);
org.nuxeo.ecm.automation.OperationChain chain = new OperationChain("notRegisteredChain");
// Adding operations - operations parameters setting
chain.add("Document.Fetch");
chain.add("o1").set("param1", "Hello 1!");
chain.add("o2").set("param2", "Hello 2!");
// Setting parameters of the chain
Map<String, Object> params = new HashMap<String, Object>();
params.put("messageChain", "Hello i'm a chain!");
chain.addChainParameters(params);
// Run Automation service
service.run(ctx, chain);

Run Contributed Operation

Operation Contribution:

  <extension point="operations"
             target="org.nuxeo.ecm.core.operation.OperationServiceComponent">
    <operation class="org.nuxeo.ecm.automation.core.test.Operation1" />
  </extension>

Java Class Operation:

@Operation(id = "o1")
public class Operation1 {

    @Param(name = "message")
    protected String message;

    @OperationMethod
    public DocumentModel run(DocumentModel doc) throws Exception {
        return doc;
    }

}

Automation Service API - with operations parameters setting:

org.nuxeo.ecm.core.api.DocumentModel doc;
org.nuxeo.ecm.automation.AutomationService service;
org.nuxeo.ecm.core.api.CoreSession session;

// Input setting
org.nuxeo.ecm.automation.OperationContext ctx = new OperationContext(session);
ctx.setInput(doc);
// Operation1 parameter setting
Map<String,Object> params = new HashMap<String,Object>();
params.put("message","messageValue");
service.run(ctx, "o1", params);