Arun M R Nair
Arun M R Nair

Reputation: 653

Can't update document with version in cmis

I am trying to update a document (with version support) in cmis-alfresco. Normal document update successfully. But when I tried to update a document that have a relation, its getting a error.

            newFileProps = new HashMap<String, String>();
            newFileProps.put(PropertyIds.OBJECT_TYPE_ID,
                    "D:cmiscustom:document");
            newFileProps.put(PropertyIds.NAME, "ADGFileSource1");
            Document sourceDoc = folderAssociations.createDocument(
                    newFileProps, null, VersioningState.MAJOR);

            newFileProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
            newFileProps.put(PropertyIds.NAME, "ADGFileTarget1");
            newFileProps.put(PropertyIds.OBJECT_TYPE_ID,
                    "D:cmiscustom:document");
            Document targetDoc = folderAssociations.createDocument(
                    newFileProps, null, VersioningState.MAJOR);


            Map<String, String> relProps = new HashMap<String, String>();
            relProps.put("cmis:sourceId", sourceDoc.getId());
            relProps.put("cmis:targetId", targetDoc.getId());
            relProps.put("cmis:objectTypeId", "R:cmiscustom:assoc");
            ObjectId relId = session.createRelationship(relProps, null,
                    null, null);


             if (sourceDoc.getAllowableActions().getAllowableActions().contains(org.apache.chemistry.opencmis.commons.enums.Action.CAN_CHECK_OUT)) {
                 sourceDoc.refresh();
                String testName = sourceDoc.getContentStream().getFileName();
                ObjectId idOfCheckedOutDocument = sourceDoc.checkOut();
                Document pwc = (Document) session.getObject(idOfCheckedOutDocument);

                String docText = "This is a sample document with an UPDATE";
                byte[] content = docText.getBytes();

                ByteArrayInputStream stream = new ByteArrayInputStream(content);         
                String filename=sourceDoc.getName();
                ContentStream contentStream = session.getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream);          
                ObjectId objectId = pwc.checkIn(false, null, contentStream, "just a minor change");
             }  

error:

Constraint violation: 00190010 Found 1 integrity violations:
The association source multiplicity has been violated: 

Upvotes: 0

Views: 876

Answers (1)

fhelmer
fhelmer

Reputation: 21

I had the same problem and was fairly desperate as it used to worked prior to Alfresco 5.x. Also updating the chemistry and import org.alfresco.cmis.client.AlfrescoDocument packages did not help.

But I found the following workaround. Our Alfresco installation had always been configured to auto-version, so I went around the checkout/update/checkin procedure by simply setting a new content to the document:

theDoc.setContentStream(contentStream, true);

Be aware, that this will add a new version in our configuration and thus "theDoc" points to an old version of the document from now on. Therefore, you maybe need to fetch the document again to have it point to the latest version to avoid "Document is not the latest version" error.

Upvotes: 2

Related Questions