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
You can use Nuxeo's extension system to do that just that. For instance you could create a file called
in the following location:
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
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.
doPostCreatereceives has APIs like
getPropertyValuethat you can use to get values from the document.