Unable to Unlock Alfresco Document using CMIS

583 Views Asked by At

I'm using CMIS to make changes to alfresco document, I need to add new aspect to document, but I'm facing:

org.apache.chemistry.opencmis.commons.exceptions.CmisUpdateConflictException: Update conflict: 06160811 Cannot perform operation since the node (id:88289ea7-16b7-40ff-938b-b2888ef5bca5) is locked.

Below is the code I'm trying to unlock the document, but it's not successful. kindly suggest other alternatives to unlock a locked document using CMIS

       for (QueryResult result : results) {
            String objectId = result.getPropertyValueByQueryName(PropertyIds.OBJECT_ID);
            AlfrescoDocument document = (AlfrescoDocument) session.getObject(session.createObjectId(objectId));
            if (document != null) {
                if(document.hasAspect("P:cm:lockable")) {
                    System.out.println(document.getName());
                    document.removeAspect("P:cm:lockable");
                }
            } else {
                System.out.println("Document is null");
            }
        }
2

There are 2 best solutions below

1
On

Use LockService.

lockService.unlock("nodeRef of the node to unlock")

2
On

What version of Alfresco and CMIS are you using? It looks like you might be using the Alfresco CMIS extension JAR, but you should not be using that at all if you are using Alfresco 5.2 (or higher) and CMIS 1.1.

If you are using CMIS 1.1, the way to remove an aspect is to remove the name of the aspect from the array of values in the cmis:secondaryObjectTypeIds array, then update the properties with the trimmed list of aspects.

With all of that said, that would just remove the lockable aspect from the document. You are trying to actually unlock the document, not remove its ability to be locked/unlocked. So instead of trying to directly manipulate the aspect, you should just call cancelCheckout() if you want to unlock the document, like:

    Document doc = (Document) getSession().getObjectByPath(filePath);
    doc.cancelCheckOut();

Obviously you'll need to use credentials of someone who has the permissions to do this.