How to import a document and put it in Nuxeo in version 12 as initial version?

As part of the migration of existing documents in Nuxeo, we have to manage documents that already have an existing version.

How to import a document and put it in Nuxeo in version 12? Is it possible without having to click 12 times on “Increment major version”?

Do you have some hints to help us to developing this feature?

Thanks a lot

0 votes

2 answers

1973 views

ANSWER



You can use Nuxeo's extension system to do that just that. For instance you could create a file called

versioning-override-config.xml

in the following location:

<NUXEO_HOME>/nxserver/config

Then fill it with the following contents:

  <?xml version="1.0"?>
   <component name="org.nuxeo.ecm.platform.versionoverride" version="1.0">
     <extension target="org.nuxeo.ecm.core.versioning.VersioningService" point="versioningRules">
       <defaultVersioningRule>
         <initialState major="12" minor="0" />
        </defaultVersioningRule>
      </extension>
   </component>

and restart your server.

You can find more documentation and other possible applications of the versioning service: here

1 votes



This solution will put each new documents in version 12. We need to be able to choose the initial version when we import the documents. Do you have other ideas?
05/15/2012

After i tried this solution on Nuxeo-dm5.6 i get a HTTP internal 500 error…
10/08/2012


So you have two possible solution here.

You can filter the versioning rule per document if that's enough for you. Every document of this type will start with version defined in the versioning rule.

    <versioningRule typeName="File" enabled="true">
     <initialState major="12" minor="0" />
    </versioningRule>

This way every File document start with version 12.0 . You can always remove this contribution after the import.

Another solution would be to define your own versioningService. This way you can override the doPostCreate called every time a document is created by the method CoreSession#createDocument(DocumentModel) . The option Map it takes as parameter is the one from DocumentModel#getContextData . You can define your own versioningService with a contribution like this:

<extension target="org.nuxeo.ecm.core.versioning.VersioningService" point="versioningService">
    <service class="yourVersioningservice" />
</extension>

Hope it helps.

0 votes



I overwrite doPostCreate method from VersioningService class. I am able to change the version of the document with a hard coded value. I want to retrieve a value from a field in create_document view. Options parameters doesn't contains anything about context data. Thanks a lot. I am new to nuxeo development.
05/16/2012

Just to be clear, each document that I import doesn't have the same version number. I need to have a way to chose the version number when I import it. I don't want to click X times on "Increment major version" to go to version X. Thanks.
05/17/2012

The Document object that doPostCreate receives has APIs like getPropertyValue that you can use to get values from the document.
05/21/2012