Automation

Automation Chain

Updated: July 17, 2023

You can use Nuxeo Studio for contributing new automation chain graphically.

This page explains all the details of the necessary Platform contribution (that Studio produces) for an in-depth comprehension of the framework. Reading it is not necessary if you start with Automation.

An automation chain is a pipe of parametrized atomic operations. The automation chain specifies the parametrization of each operation in the chain, not only the list of operations to execute. Thanks to this, when running an automation chain, you only specify the chain's name. The chain will be fetched from the registry and its operations will be executed one after the other, using the parametrization.

Chain contribution is done via the Nuxeo extension point mechanism. The extension point name is chains and the component exposing the extension point is org.nuxeo.ecm.core.operation.OperationServiceComponent .

Here is an example of a chain extension:

  <extension target="org.nuxeo.ecm.core.operation.OperationServiceComponent" point="chains">
    <chain id="downloadAllChain">
      <param type="string" name="chainParameterName">chainParameterValue</param>
      <operation id="Context.FetchDocument"/>
      <operation id="Context.SetVar">
        <param type="string" name="name">aoname</param>
        <param type="object" name="value">@{Document["dc:title"]}</param>
      </operation>
      <operation id="Document.GetChildren"/>
      <operation id="Blob.Get">
        <param type="string" name="xpath">file:content</param>
      </operation>
      <operation id="Blob.CreateZip">
        <param type="string" name="filename">@{aoname}.zip</param>
      </operation>
      <operation id="WebUI.DownloadFile"/>
    </chain>
  </extension>

This is defining a chain that will do the following:

  • Fetching the current document in user interface and setting it as the input of the next operation.
  • Setting a context variable named "aoname" to the value of the input document title. The input document is returned as the input for the next operation.
  • Getting the children of the input document. The list of children documents is returned as the input of the next operation.
  • For each document in the list getting the attached blob (the blob property to use is specified using the xpath parameter) and returning the list of blobs as the input of the next operation.
  • Creating a zip from the input list of blobs. The filename parameter is setting the file name to be used for the zip. The value of the file name is retrieved from the "aoname" context variable that was set before in the chain. Returning the zip blob as the input of the next operation.
  • Setting-up the zip so it can be downloaded from the browser (this is a UI operation).

In a nutshel, this chain gets the current document in the user interface, extracts all blobs from its direct children, zips these blobs and offers to download the resulted zip file in the web browser.

You can see that the chain is setting the order in which each operation must be executed along with the parameter values to be used at runtime. The parameters are either hard coded strings or MVEL expressions that allow dynamic computation of actual values.

An atomic operation in a chain is uniquely identified by its ID. Each parameter should specify the name of the operation parameter to set (see @Param annotation in Contributing an Operation) and the type of the value to inject. The type is a hint to the chain compiler to correctly transform the string into an injectable Java object.

Since 5.7.2, all chains can contain parameters to be used from the automation context (such as the chainParameterName which can be fetched from the automation sub-context @{ChainParameters['chainParameterName ']}).

You can find the complete list of the supported types in Contributing an Operation.

Since 5.7.2, it is possible to create "composite operations": Adding chains into a chain.

Here is an example of how to contribute this kind of automation chain:

<extension point="chains"
    target="org.nuxeo.ecm.core.operation.OperationServiceComponent">
    <chain id="contributedchain">
      <operation id="contributedchainLeaf" />
      <param type="string" name="messageChain" />
      <operation id="operation1">
        <param type="string" name="message">Hello 1!</param>
      </operation>
      <operation id="operation2">
        <param type="string" name="message">Hello 2!</param>
      </operation>
      <operation id="operation3">
        <param type="string" name="message">{ChainParameters['messageChain']}</param>
      </operation>
    </chain>
    <chain id="contributedchainLeaf">
      <operation id="operation1">
        <param type="string" name="message">Hello 1!</param>
      </operation>
      <operation id="operation2">
        <param type="string" name="message">Hello 2!</param>
      </operation>
    </chain>
  </extension>

The contributedchainleaf chain is contributed with its operations and is included as an operation into contributedchain. During the execution of this chain, a validation is running to check if all inputs/outputs of the different chains/operations in the stack are matching.

 

In Automation you can add aliases for each chain:

  <extension target="org.nuxeo.ecm.core.operation.OperationServiceComponent" point="chains">
    <chain id="doc_create_chain_alias">
      <aliases>
        <alias>chainAlias1</alias>
        <alias>chainAlias2</alias>
      </aliases>
      <operation id="OperationWithParamNameAlias">
        <param type="string" name="paramName">Hello Chain Alias!</param>
      </operation>
    </chain>
  </extension>

 

 

Related topics in other documentation

Operations Index Automation How-To Index

Automation chains in Nuxeo Studio

Automation Automation Scripting