cancel
Showing results for 
Search instead for 
Did you mean: 

How to upload a new version using Java API ?

upforsin
Star Collaborator
Star Collaborator

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?

howkymike
Alfresco Developer
1 ACCEPTED ANSWER
2 REPLIES 2

AlfrescoZZZ
Star Collaborator
Star Collaborator

Did you find a solution ?

That should be still working with current versions:

https://github.com/keensoft/alfresco-firma-pdf/blob/64acee0a574e601000d290b0d5b8a5f8be563989/src/alf...

Hyland Developer Evangelist