Document Versioning

Table of Contents

16.1. Setting the version of a document
16.2. Modifying automatically the version of a document
16.3. Accessing document from previous version
16.4. The versioning service implementation

16.1. Setting the version of a document

The versioning information are stored in the DocumentModel under the fields major_version and minor_version of the uid.xsd schema. Set the version as you would any other field:

documentModel.setProperty("uid","major_version",1);
documentModel.setProperty("uid","minor_version",1);

The field used for version is adaptable via the properties extension point of the org.nuxeo.ecm.platform.versioning.service.VersioningService component. It allows to define which properties should be used to set versions for a given document type.

<versioningProperties>
  <majorVersion>my:major_version</majorVersion>
  <minorVersion>my:minor_version</minorVersion>
  <documentType>File</documentType>
  <documentType>Note</documentType>
</versioningProperties>

16.2. Modifying automatically the version of a document

Event such as saving a document or following a life cycle transition can change the document's version number. To use this feature you need first to define which event should be listened to and then how the version number should behave.

The CoreEventListenerService is used to define which event to listen to. The default declaration is in nuxeo-platform-versioning-core:

<listener name="versioninglistener"
    class="org.nuxeo.ecm.platform.versioning.listeners.DocVersioningListener">
  <eventId>lifecycle_transition_event</eventId>
  <eventId>documentCreated</eventId>
  <eventId>beforeDocumentModification</eventId>
  <eventId>documentUpdated</eventId>
  <eventId>documentRestored</eventId>
</listener>
<listener name="versioningChangelistener"
  class="org.nuxeo.ecm.platform.versioning.listeners.VersioningChangeListener" />

The class org.nuxeo.ecm.platform.versioning.listeners.DocVersioningListener implements the behavior of the versioning when those events happen.

To modify the version of a document when a life cycle state is reach you need to define rules with the behavior(increment major, minor or do nothing) using the extension rules from org.nuxeo.ecm.platform.versioning.service.VersioningService:

<versioningRuleEdit name="sampleEditRuleProject" action="ask_user"
    lifecycleState="project">
  <option value="no_inc" default="true" />
  <option value="inc_minor" />
  <option value="inc_major" />
</versioningRuleEdit>

The default behavior for all type but File and Note is to increase the minor version for each life cycle change. You need to override one of the default rules if you add a new type. The order is important, the list of rules is read and the first match is used.

<versioningRuleEdit name="sampleEditRuleAnyState" action="ask_user"
      lifecycleState="*">
  <includeDocType>File</includeDocType>
  <includeDocType>Note</includeDocType>
  <includeDocType>MyNewType</includeDocType>
  <option value="no_inc" default="true" />
  <option value="inc_minor" />
  <option value="inc_major" />
</versioningRuleEdit>

16.3. Accessing document from previous version

The CoreSession or the seam component documentVersioning and versionedActions allow to access document from previous version. On CoreSession, the method getVersions return all the versions of a document.

16.4. The versioning service implementation

The versioning service manages the version inside Nuxeo. Two implementations are available:

  • The custom Nuxeo service, more flexible and used by default

  • The default JackRabbit implementation.

To modify this setting edit the file config/default-versioning-config.xml:

<!--property name="versioningService" value="org.nuxeo.ecm.core.repository.jcr.versioning.JCRVersioningService"/-->
<property name="versioningService" value="org.nuxeo.ecm.core.versioning.custom.CustomVersioningService"/>

This section shows how to use the versioning module, how to modify the version of a document automatically or manually and how to use a document from a previous version.