I work with a customer that needs to export the Nuxeo document tree to a file system daily. This was a perfect opportunity to implement a multi use case document exporter. The code is available on GitHub, and we will add it to the marketplace soon.
Plugin Organization
This plugin enables the user to export one chosen root structure of documents in Nuxeo to a specified File System repository.
The installation of the plugin will add a new operation in “Services” called “ExportStructureToFS”. This operation must be added to the registries in Studio and then can be used in an automation chain.
The JSON path is the following:
{ "operations" : [
{ "category" : "Services",
"description" : "This operation enables to export the structure contained in the Root
name path to the File System Target path. You can choose to export deleted documents or not
and You can declare your own query to choose the document being exported",
"id" : "ExportStructureToFS",
"label" : "ExportStructureToFS",
"params" : [ { "description" : "",
"name" : "Root Name",
"order" : 0,
"required" : true,
"type" : "string",
"values" : [ ],
"widget" : null
},
{ "description" : "",
"name" : "File System Target",
"order" : 0,
"required" : true,
"type" : "string",
"values" : [ ],
"widget" : null
},
{ "description" : "",
"name" : "Query",
"order" : 0,
"required" : false,
"type" : "string",
"values" : [ ],
"widget" : null
}
],
"requires" : null,
"signature" : [ "void",
"void"
],
"url" : "ExportStructureToFS"
} ] }
By default, the following rules are implemented:
- All documents of the chosen structure are exported,
- When a document exported is already existing in the File System directory, it will be prefixed with a timestamp. This way, no document will be deleted,
- Attached files to a document are exported to the same directory as the document. They are prefixed with the name of the document parent.
This plugin can be customized in different manners:
- Bychanging the default query used to retrieve the documents to be exported. The query can be changed by modifying a parameter of the operation - this can be done in Studio.
- By using the defined extension point “exportLogic” and by using the existing contribution or by defining a new contributionfor export. This contribution requires some Java code.
Default Behavior
The operation “ExportStructureToFS” has the following parameters:
- Root Name: The root name of the structure of the Nuxeo Platform that will be exported.
- File System Target: Where the export will be done on the File System.
- Query: An optional parameter. By default the query called by the exporter is: SELECT * FROM Document ecm:mixinType !=’HiddenInNavigation’ AND ecm:isCheckedInVersion = 0 AND ecm:currentLifeCycleState !=’deleted’.
By default, all documents don’t have the facet “HiddenInNavigation”, are non-version and are not in the ‘deleted’ state will be exported.
Customization 1: Changing the default query
If you want to change the list of documents that will be exported, you can define your own query and put it the in the Query parameter of the “ExportStructureToFS” operation.
For example, if you want to export all the documents, even the ones in “deleted” state, you can define this query in the field of the query parameter:
SELECT * FROM Document WHERE ecm:mixinType !=’HiddenInNavigation’ AND ecm:isCheckedInVersion = 0
To create your own query, you can take a look at the documentation page on the NXQL language that is used.
Customization 2: Using the extension point
If you want to change the export mechanism, the extension point “exportLogic” can be contributed with a custom class. For example, you might want to:
- Override existing documents (don’t use the timestamp prefix approach),
- Create an XML export of each document (provided as an example).
The following contribution has been implemented as an example: “CustomExporterPlugin”. It provides the default export (export all the documents under root name) and in addition, for each document exported, creates the XML version.
You can use it with the following XML extension in Studio :
<extension target="org.nuxeo.io.fsexporter.FSExporter" point="exportLogic">
<exportLogic class="org.nuxeo.io.fsexporter.CustomExporterPlugin" />
</extension>
Scheduling an Export
If you want to schedule the export, you can use a cron and schedule the call of the the Automation chain using cURL, or use the Nuxeo Platform internal cron service.