cancel
Showing results for 
Search instead for 
Did you mean: 

How to get specific document version

vipul_n
Champ in-the-making
Champ in-the-making
I am using CMIS Java API.
My query is how to get document object id for the specific version. I want to use this specific document version id when I next time fetch that specific version using the following API

Document doc = (Document) session.getObject(objectId);


I know there is an API i.e.
document.getAllVersions()
. But this will return all the version of the document and I guess it will flood the memory with all the version (Kindly clarify if this is not the case).


4 REPLIES 4

kaynezhang
World-Class Innovator
World-Class Innovator

You can use OperationContext to  filter the amount of information returned and control paging.

      OperationContext context = new OperationContextImpl();
      context.setMaxItemsPerPage(10);
      context.set***(***);
      d.getAllVersions(context);

vipul_n
Champ in-the-making
Champ in-the-making
Thanks kaynezhang for your quick response.
When we used
 document.getAllVersions() 
and got the id of each version object, then we got id in format like <drupal5><docId>;<versionLabel></drupal5>
e.g. workspace://SpacesStore/344da22e-1252-48bc-b3ee-2844dcb8b2d4;1.1

is it a good practice if we append version label to document id and then call
<java>session.getObject("<documentId>;<versionLabelId>");</java>

Because we could not find any specific API to get specific version and could not find version specific document id, will this hardcoded format work forever?

kaynezhang
World-Class Innovator
World-Class Innovator
The CMIS  specification says
<strong>
Note: When a document is versioned, each version of the document is a separate document object. Thus, for document objects, an object ID actually identifies a specific version of a document."
</strong>
So the id
workspace://SpacesStore/344da22e-1252-48bc-b3ee-2844dcb8b2d4;1.1
will definately identify only one  version node.
I think it is ok for you to use
 session.getObject("<documentId>;<versionLabelId>");
to  get specific version now,but you should use it with precaution,since you might take beblow risks:
1.Now alfresco construct an version object id based on the nodeid and versionLabel,alfresco may change the id construction policy later.
2.You should use the default version label policy instead of creating a version label policy.

I suggest you separate your code and make it as exteandable as possible.

vipul_n
Champ in-the-making
Champ in-the-making
kaynezhang,
Thank you very much for your valuable feedback.
This definitely clarifies my query.