Question

How can I find if a Document is versionable in alfresco using OpenCMIS code?

Was it helpful?

Solution

The way that skuro points out works. An alternative is to use the fact that all objects know what their allowable actions are. So you can just ask, like this (run this in the OpenCMIS Workbench Groovy Console):

doc = session.getObjectByPath("/cmis-demo/temp.txt")
allowableActions = doc.getAllowableActions().getAllowableActions()
if (allowableActions.contains(Action.CAN_CHECK_OUT)) {
    print "Versionable!"
}

If a document is not versionable, for whatever reason, it will not have the CAN_CHECK_OUT allowable action.

OTHER TIPS

In a pure CMIS way, the following code snippet would accomplish the goal:

// For how to get a Session see:
// http://chemistry.apache.org/java/opencmis-client-api.html#sessions
Session session = getSession();

CmisObject object = session.getObjectByPath("/path/to/object");
ObjectType type = object.getType();
Boolean isVersionable = type instanceOf DocumentType && ((DocumentType)type).isVersionable();

In facts, cmis:document nodes are always marked as versionable in Alfresco, while in reality Alfresco uses the cm:versionable aspect to mark a node to be subdue to versioning. This is incompatible with the standard CMIS domain model where versionability is statically derived from the object type definition.

I believe that the cm:versionable aspect is automatically added by Alfresco when issuing versioning CMIS calls to nodes that miss it, so that the above incompatibility shouldn't result in any real issue.

Another, more Alfresco specific solution would require you to use the Alfresco OpenCMIS Extension:

CmisObject object = session.getObjectByPath("/path/to/object");
Boolean isVersionable = object instanceof AlfrescoDocument && ((AlfrescoDocument)object).hasAspect("cm:versionable");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top