aegif / NemakiWare

Light-weight, highly customizable CMIS server powered by NoSQL

Home Page:http://nemakiware.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CmisVersioningException when calling setContentStream two times in a row

nicolas-raoul opened this issue · 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.

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.

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);
        }

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.

By the way, is there any workaround for now?

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.

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! :-)