About document.updateProperties() and versioning

Showing results for 
Search instead for 
Did you mean: 
Established Member

About document.updateProperties() and versioning

I am using CMIS 1.1 API, Alfresco Community 5.1

I have our custom model, and in the model, I did not do anything with versioning related flags.

Our model extends cm:content. And we have a custom aspect with set of properties associated.

However, it is documented that CMIS API automatically turn on versioning on (binary) content changes, and not on update of (meta/custom) properties.

Let us say, I have a (custom aspect) property in my document called Roll.

After I created a document as shown in the code below, when I print the details of the properties, I see the version as 1.0, and value of the Roll property is "1".

ContentStream contentStream = cmisSession.getObjectFactory().createContentStream(
mDocument.getFileName(), Long.valueOf(content.length), mimeType, stream);
insertedDocument = entityFolder.createDocument(cmisProperties, contentStream, VersioningState.MAJOR);

Now, afterwards, say I did call document.updateProperties(), by setting the value of the Roll property to "2". Please note that I do not have versioning turned on for property updates.

Even then, when I print the details of the document after updating the properties, it shows the Roll property value as "2" for version 1.0.

I also used CMIS workbench directly to check on the value of the Roll property, and it says "2" for version 1.0.

Now, say I am uploading a new content for this document, with a value of "3" for the Roll property 

Document existingDocument = getAlfrescoCMISDocumentByProperties(uniqueProperties, user);
if (!existingDocument.isLatestVersion()) {
     existingDocument = existingDocument.getObjectOfLatestVersion(false);

String pwcId = null;
if (existingDocument.isVersionSeriesCheckedOut()) {
    pwcId = existingDocument.getVersionSeriesCheckedOutId();
else {
   ObjectId oId = existingDocument.checkOut();
   pwcId = oId.getId();

Document pwc = (Document) cmisSession.getObject(pwcId);


ContentStream contentStream = cmisSession.getObjectFactory().createContentStream(
       mDocument.getFileName(), Long.valueOf(content.length), mimeType, stream);
ObjectId insertedDocumentObjectId = pwc.checkIn(false, cmisProperties, contentStream, user);     

Now after I do the above, I have two versions in the repository: Version 1.0 and Version 1.1 

Version 1.0 has the value of Roll property as "1"

Version 1.1 has the value of Roll property as "3"

The challenging/misleading thing is, CMIS/Alfresco was showing the value as "2" for the Roll property up until I created version 1.1. Once it created version 1.1, then 1.0's Roll property value went back to "1" which was the value when it was originally created in the first place, and not the updated value (which is "2")....

I have asked this question once before. Please pardon me for repeating.

However, besides Alfresco, our product integrates with Documentum, KwikTag, Oracle IP/M, Sharepoint, etc.

I have verified that the Documentum, takes the property updates and maintains them against the current version we are working with. Even after making a new version 1.1, it has the latest values for the version 1.0. In the above case, after creating version 1.1, we have the following data.

Version 1.0 has the value of Roll property as "2".

Version 1.1 has the value of Roll property as "3"

Documentum behaves like it allows property updates on a version ("current version") that was created a while ago and keeps it updated with all property changes, at least until we create another version.

I just want to confirm once more that this is the behavior in Alfresco, with my case explained.

I want to rule out the situation that I do not know how to do updateProperties or creating a new version of a document.

I do not want to conclude things prematurely and do something wrong...

Could you please help me?

Gnanasekaran Sakthivel
2 Replies
Established Member

Re: About document.updateProperties() and versioning

I resorted to versioning the document in its latest updated state, before creating a new (different) version as initiated by the user.

This worked for me as now.

Without clear API Javadoc comments, it took me a while to learn that the following statement will create a new version of the current document as is. May be I am not looking into the right place.

pwc.checkIn(false, null, null, "Preserving properties update");

Action 1 - Let us say the user created a document, which will be version 1.0.

Action 2 - Then let us say user updates the (custom meta) properties few times. 

Action 3 - Then the user initiates creates a new version

While completing action-3 in code, we version the document that is at the end of action-2, before creating a version for action-3.

Here is the extract of the code anyways...

Date createDate = new Date(existingDocument.getCreationDate().getTimeInMillis());
Date lastModifiedDate = new Date(existingDocument.getLastModificationDate().getTimeInMillis());
if (lastModifiedDate.after(createDate)) {
     createANewVersionOfTheDocument (existingDocument);

// ... elsewhere

private void createANewVersionOfTheDocument(Document theDocument)
  if (theDocument == null) return;
  String pwcId = null;
  ObjectId objectId = theDocument.checkOut();
  pwcId = objectId.getId();
  try {
   Document pwc = (Document) cmisSession.getObject(pwcId);
   ObjectId newVersionObjectId = pwc.checkIn(false, null, null, "Preserving properties update");
   Document insertedDocument = (Document) cmisSession.getObject(newVersionObjectId);
  catch (Exception inExc) {
   log.error("@createANewVersionOfTheDocument - Error occurred during creation of a new version");
  finally {
Gnanasekaran Sakthivel
Established Member

Re: About document.updateProperties() and versioning

Hi @sepgs2004 ,

I am trying to do the same thing. Did it worked for you ?

properties are not updating for the current version, it gets updated on the new uploaded version.
I have tried cm:autoVersionOnUpdateProps but dont want multiple versions for every time on update properties.
Please guide how to customize this to update properties on the current version too.