cancel
Showing results for 
Search instead for 
Did you mean: 

Set content on node version?

nenad982
Champ on-the-rise
Champ on-the-rise
Hi all,

is there a way to set the content on the node version using Java API. For example I create node version using VersionService.java and I want to set the version content, is it possible and if yes how to do that?

Thanks…
6 REPLIES 6

mrogers
Star Contributor
Star Contributor
You have it backwards.  You create a version of the current content and properties not the other way around.

romschn
Star Collaborator
Star Collaborator
You can try following and see if it works for you or not.
Get the frozenStateNodeRef from the Version object you get after creating a new version using CreateVersion method and try setting up content property for this node.

nenad982
Champ on-the-rise
Champ on-the-rise
Hi romschn,

this works thank you. I now noticed that I have problems to set version labels to right values? Is it possible to set the label somehow on version creation, or to update version label?

Thanks a lot

romschn
Star Collaborator
Star Collaborator
okay, can you try simply setting up the ContentModel.PROP_VERSION_LABEL using nodeservice.setProperty method with your right values and see if it works for you or not?
this.nodeService.setProperty(nodeRef,ContentModel.PROP_VERSION_LABEL,"Label-1");

nenad982
Champ on-the-rise
Champ on-the-rise
That does not work,I already tried that. Also if you look at implementation of

VersionService#createVersion( NodeRef nodeRef,Map<String, Serializable> versionProperties);

you will see that setting label is not possible on version creation also. I found this also:

http://code.google.com/p/alfresco-bulk-filesystem-import/issues/detail?id=85

So it seams that it is not possible?!

Thanks

kaynezhang
World-Class Innovator
World-Class Innovator
In out of the Box alfresco design:
1.You can not set PROP_VERSION_LABEL property when you create a new version for a node,PROP_VERSION_LABEL property is  automatically  calculated by CalculateVersionLabelPolicy .If you want to change the default serial version label,you can customize a  CalculateVersionLabelPolicy for your custom type and use it to override the default one.
2.After a version is created ,you can't modify any properties(include PROP_VERSION_LABEL) unless you revert it ,and the content were not supposed to be updated at all.But it seems  alfresco overlooked this fact ,now you can get the reference to the node of the version and change it's content,it should be wrong to update it directly.

So ,
if you want to use version lable policy of your own ,please customize CalculateVersionLabelPolicy
if you really want to update a version node's property, you shoud implement a new NodeService class and use it as  the version store node service implementation