Nuxeo Server

Bulk Actions Directory

Updated: August 9, 2019 Page Information Edit on GitHub

Directory

Nuxeo provides several actions for the Bulk Action Framework:

Action name Description Parameters Java Class
setProperties Allow to set several properties on each document Parameters represent the couple (xpath, value) to set SetPropertiesAction
csvExport Allow to export several documents as a csv file Parameters represent the options (schemas, xpaths, zip/sort, lang) CSVExportAction
automation Allow to run an automation on each document Parameters represent the automation to run and parameters to give to it (operationId/parameters) AutomationBulkAction

Examples

Let's see some examples of bulk actions in use.

SetPropertiesAction

The following example shows how to use setPropertiesAction with Java Service:

// build command
BulkCommand command = new BulkCommand.Builder(SetPropertiesAction.ACTION_NAME,
        "SELECT * from Document").repository("default")
                                 .user("Administrator")
                                 .param("dc:nature", "article")
                                 .param("dc:subjects", Collections.singletonList("art/architecture"))
                                 // default is FALSE
                                 .param(SetPropertiesAction.PARAM_DISABLE_AUDIT, Boolean.TRUE)
                                 // default is null - only NONE can be set
                                 .param(SetPropertiesAction.PARAM_VERSIONING_OPTION, "NONE")
                                 .build();

// run command
BulkService bulkService = Framework.getService(BulkService.class);
String commandId = bulkService.submit(command);

// await end of computation
bulkService.await(commandId, Duration.ofMinutes(1));

// get status
BulkStatus status = bulkService.getStatus(commandId);

You can submit the same command through REST and Search endpoint:

curl -u Administrator:Administrator \
     -H 'Content-Type: application/json' \
     -X POST 'http://localhost:8080/nuxeo/api/v1/search/bulk/setProperties?query=SELECT * FROM Document' \
     -d '{
           "dc:nature": "article",
           "dc:subjects": ["art/architecture"],
           "disableAuditLogger": true,
           "versioningOption": "NONE"
         }'

To allow enhanced performances, 2 optional parameters can be passed to the SetPropertiesAction:

  • disableAuditLogger, from NXAuditEventsService.DISABLE_AUDIT_LOGGER, disables audit logging and is meant to be used with true and is false by default.
  • VersioningOption, from VersioningService.VERSIONING_OPTION, disables auto versioning and is meant to be used with NONE.

For example:

BulkCommand command = new BulkCommand.Builder(SetPropertiesAction.ACTION_NAME, "SELECT * from Document")
        .repository("default")
        .user("Administrator")
        .param("dc:nature", "article")
        .param("dc:subjects", ImmutableList.of("art/architecture"))
        .param("disableAuditLogger", Boolean.TRUE) // Disables audit logging
        .param("VersioningOption", "NONE") // Disables auto versioning
        .build();

CSVExportAction

It exports requested documents as a CSV File which can be sorted and zipped.

System properties are always exported as first columns, then all the properties from provided schemas and xpaths are exported if they can be found.

For exported multi-valued properties, the values are separated from each other with the pipe | character.

... ,dc:contributors, ...
... , user1 | user2 , ...  

For vocabulary properties, the value is exported as a column and the label is also exported within a second column sideway labeled property [label]

The following example shows how to use csvExportAction with Java Service:

// build command
ImmutableList<String> xpaths = ImmutableList.of("file:content/name", "file:content/length");
BulkCommand command = new BulkCommand.Builder(CSVExportAction.ACTION_NAME, "SELECT * from Document")
        .repository("default")
        .user("Administrator")
        .param(CSVProjectionComputation.PARAM_SCHEMAS, Collections.singletonList("dublincore"))
        .param(CSVProjectionComputation.PARAM_XPATHS, xpaths)
        .param(CSVProjectionComputation.PARAM_LANG, "fr") // default is context Locale
        .param(SortBlob.SORT_PARAMETER, Boolean.FALSE) // default is TRUE
        .param(ZipBlob.ZIP_PARAMETER, Boolean.TRUE) // default is FALSE
        .build();



// run command
BulkService bulkService = Framework.getService(BulkService.class);
String commandId = bulkService.submit(command);

// await end of computation
bulkService.await(commandId, Duration.ofMinutes(1));

// get status
BulkStatus status = bulkService.getStatus(commandId);

You can submit the same command through REST and Search endpoint:

curl -u Administrator:Administrator \
     -H 'Content-Type: application/json' \
     -X POST 'http://localhost:8080/nuxeo/api/v1/search/bulk/csvExport?query=SELECT * FROM Document' \
     -d '{
           "schemas": ["dublincore"],
           "xpaths": ["file:content/name", "file:content/length"],
           "lang": "fr",
           "sort": false,
           "zip": true
         }'

And then get the status containing the URL to the result:

curl -u Administrator:Administrator \
     -H 'Content-Type: application/json' \
     -X GET 'http://localhost:8080/nuxeo/api/v1/bulk/<id-from-previous-command>'

AutomationBulkAction

The following example shows how to bulk edit document using automation action and Search endpoint:

curl -u Administrator:Administrator \
     -H 'Content-Type: application/json' \
     -X POST 'http://localhost:8080/nuxeo/api/v1/search/bulk/automation?query=SELECT * FROM Document' \
     -d '{
           "operationId": "Document.Update",
           "parameters": {
             "properties": "dc:nature=article"
           }
         }'
a month ago Manon Lumeau Fix wording
History: Created by Manon Lumeau

We'd love to hear your thoughts!

All fields required