NemakiWare icon indicating copy to clipboard operation
NemakiWare copied to clipboard

CmisVersioningException when calling setContentStream two times in a row

Open nicolas-raoul opened this issue 9 years ago • 6 comments

        // make 2 changes
        Document doc = (Document)session.getObjectByPath(path);
        byte[] content = "Hello World!".getBytes();
        for (int i=0; i<2; i++) {
            InputStream stream = new ByteArrayInputStream(content);
            ContentStream contentStream = new ContentStreamImpl("test.txt", BigInteger.valueOf(content.length), "text/plain", stream);
            doc.setContentStream(contentStream, true);
        }

Result:

Exception in thread "main" org.apache.chemistry.opencmis.commons.exceptions.CmisVersioningException: The operation is not allowed on a non-current version of a document [cmis:objectId = fb4640f91aedea7932321219fef9afab]
    at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:508)
    at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.put(AbstractAtomPubService.java:750)
    at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.setOrAppendContent(ObjectServiceImpl.java:859)
    at org.apache.chemistry.opencmis.client.bindings.spi.atompub.ObjectServiceImpl.setContentStream(ObjectServiceImpl.java:739)
    at org.apache.chemistry.opencmis.client.runtime.DocumentImpl.setContentStream(DocumentImpl.java:459)
    at org.apache.chemistry.opencmis.client.runtime.DocumentImpl.setContentStream(DocumentImpl.java:438)
    at Main.main(Main.java:54)

Making only 1 change works correctly. Making 2 changes works with Alfresco.

nicolas-raoul avatar Jul 08 '16 02:07 nicolas-raoul

Because NemakiWare creates a new version of a document each time content stream is set to it.

Specification 2.2.4.18 notes: "A repository MAY automatically create new document versions as part of this service operations. Therefore, the objectId output NEED NOT be identical to the objectId input."

So you should get the latest version of the document after setContentStream if you want to use it again.

linzhixing avatar Jul 08 '16 03:07 linzhixing

This results in the same error though:

        // make 2 changes
        byte[] content = "Hello World!".getBytes();
        for (int i=0; i<2; i++) {
            Document doc = (Document)session.getObjectByPath(path);
            InputStream stream = new ByteArrayInputStream(content);
            ContentStream contentStream = new ContentStreamImpl("test.txt", BigInteger.valueOf(content.length), "text/plain", stream);
            doc.setContentStream(contentStream, true);
        }

nicolas-raoul avatar Jul 08 '16 03:07 nicolas-raoul

It may be caused by incomplete refresh of a cache.

nemakiCachePool.get(repositoryId).removeCmisCache(oldId);

but it also needs to eliminate content cache, which is on the lower layer and used by getObjectByPath.

linzhixing avatar Jul 08 '16 03:07 linzhixing

By the way, is there any workaround for now?

nicolas-raoul avatar Jul 08 '16 03:07 nicolas-raoul

Right now, call API to delete a cache completely: DELETE http://{host}:{port}/core/rest/repo/{repositoryId}/cache/{objectId} with Basic authentication.

But I found that an imcomplete cache might not be the true reason now... getObjectByPath step down along the path getting each node with no-cache way. If so, I have to examine CouchDB view generation etc.

linzhixing avatar Jul 08 '16 03:07 linzhixing

Thanks for the workaround! My current need is satisified for now, but I keep this issue open because I guess it requires a better solution in the future, right? Thank you! :-)

nicolas-raoul avatar Jul 08 '16 03:07 nicolas-raoul