Working with Versions
CMIS 1.0 CMIS 1.1 Spec 2.1.13
Only documents can be versioned and only if the type of the document is marked as versionable.
To check whether a document type is verionable or not, use the following code.
OpenCMIS (Java)
DocumentType documentType = (DocumentType) session.getTypeDefinition("my:documentType");
boolean isVersionable = Boolean.TRUE.equals(documentType.isVersionable());
PortCMIS (C#)
IDocumentType documentType = session.GetTypeDefinition("my:documentType") as IDocumentType;
bool isVersionable = documentType.Versionable == true;
Retrieving the Version History
The code snippets below show how to retrieve the version history of a document. The returned list is ordered by creation date (cmis:creationDate). The newest version is on the top of the list, the first version on the bottom. If the version series is checked-out, a PWC exists and the user is allowed to see the PWC, then this PWC is the first entry in the list.
Use an Operation Context to define which details of the version objects should be returned. getAllVersions
does not support paging. Only the complete version history can be requested.
OpenCMIS (Java)
Document document = ...
for (Document version: document.getAllVersions())
{
System.out.println(child.getVersionLabel());
}
PortCMIS (C#)
IDocument document = ...
foreach (IDocument version in document.GetAllVersions())
{
Console.WriteLine(child.VersionLabel);
}
Getting the Latest Version
The version that has the most recent last modification date (cmis:lastModificationDate) is called the latest version of the version series.
If you already have a version document object from a version series, you can test if it is the latest version and if not, get the latest version.
Note
The test if the document is the latest verion depends on the property cmis:isLatestVersion. The property has to loaded with document object to make this check work. See the page about the Operation Context to learn how to accomplish that.
OpenCMIS (Java)
Document document = ...
Document latest;
if (Boolean.TRUE.equals(document.isLatestVersion())) {
latest = document;
} else {
latest = document.getObjectOfLatestVersion(false); // major = false
}
PortCMIS (C#)
IDocument document = ...
IDocument latest;
if (document.LatestVersion == true) {
latest = document;
} else {
latest = document.GetObjectOfLatestVersion(false); // major = false
}
If you only have a document ID, you can use the following code to get latest version.
OpenCMIS (Java)
Document latest = session.getLatestDocumentVersion(docId);
PortCMIS (C#)
IDocument latest = Session.GetLatestDocumentVersion(docId);
Creating Versions
To create a new version, the version series has to be checked out, updated and checked in. Many repositories allow a check out only on the latest version.
The check-out creates a PWC (Private Working Copy). The PWC can (usually) only be seen and updated by the user who checked out the version series. There can be only one PWC per version series, which means that version series is locked while it is checked out.
To check if a version series is already checked out, use this snippet.
OpenCMIS (Java)
Document document = ...
boolean isCheckedOut = Boolean.TRUE.equals(document.isVersionSeriesCheckedOut());
String checkedOutBy = document.getVersionSeriesCheckedOutBy(); // not all repositories provide this
PortCMIS (C#)
IDocument document = ...
bool isCheckedOut = document.IsVersionSeriesCheckedOut == true;
string checkedOutBy = document.VersionSeriesCheckedOutBy; // not all repositories provide this
Check-out
OpenCMIS (Java)
Document document = ...
ObjectId pwcId = document.checkOut();
Document pwc = session.getObject(pwcId); // get PWC document
PortCMIS (C#)
IDocument document = ...
IObjectId pwcId = document.CheckOut();
IDocument pwc = session.GetObject(pwcId); // get PWC document
Cancel Check-out
OpenCMIS (Java)
Document pwc = ...
pwc.cancelCheckOut();
PortCMIS (C#)
IDocument pwc = ...
pwc.CancelCheckOut();
Check-in
OpenCMIS (Java)
Document pwc = ...
ObjectId newVersionId = pwc.checkIn(true, null, null, "new version");
PortCMIS (C#)
IDocument pwc = ...
IObjectId newVersionId = pwc.CheckIn(true, null, null, "new version");