How to upload a new version using Java API ?

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
upforsin
Active Member II

How to upload a new version using Java API ?

Hello,

How can i upload a new version of the document using Java API?

There are two services which may be useful in this case. CheckOutCheckInService and VersionService.

The second one seemed to be more appropriate.

This was my initial code:

Version currentVersion = versionservice.getCurrentVersion(docNode);
Map<String, Serializable> versionProps = new HashMap<String, Serializable>();
versionProps.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
versionservice.createVersion(docNode, versionProps);
nodeService.setProperties(docNode, newprops); // after uploading new version I want to update also the metadata‍‍‍‍‍‍‍‍‍‍

And I encountered:

project-acs_1       |  org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: 08020024 The current version label of the node does not exist in the version history.‍‍

This error occurs AFTER the first version change (so only when this code is executed 2 or more times)

-------------------------------------------------

After seeing some errors i tried to add:

String newVersionLabel = String.valueOf(Float.valueOf( currentVersion.getVersionLabel() ) + 0.1);
versionprops.put(VersionModel.PROP_VERSION_LABEL, newVersionLabel);‍‍‍‍

But it resulted in other errors:

project-acs_1       |  org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Exception while invoking TaskListener: The version property name versionLabel clashes with a reserved verison property name.
‍‍‍‍‍

-------------------------------------------------------

I also tried to change the node ref:

NodeRef docNode = new NodeRef(versionservice.getVersionStoreReference(), docNode.getId()); ‍‍

But it does not exists and throws and error:

Caused by: org.activiti.engine.ActivitiException: Exception while invoking TaskListener: Node does not exist: workspace://version2Store/534aa85c-1466-4ead-a950-2d8b24e51945 (status:null)‍‍

I do not know how to get the proper node id (docNode.getId() returns diffrend id)

Does anyone know what am i doing wrong?