AnsweredAssumed Answered

Problem with checkIn: CmisRuntimeException: Use CheckOutCheckInservice to manipulate working copies.

Question asked by jade81 on Jan 15, 2019

Hi all,

when I try to update a document in my Alfresco repository (version  Community - 5.0.0) I get this exception:

 

Caused by: org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Use CheckOutCheckInservice to manipulate working copies.
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.convertStatusCode(AbstractAtomPubService.java:523)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.put(AbstractAtomPubService.java:750)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.AbstractAtomPubService.put(AbstractAtomPubService.java:737)
at org.apache.chemistry.opencmis.client.bindings.spi.atompub.VersioningServiceImpl.checkIn(VersioningServiceImpl.java:215)
at org.apache.chemistry.opencmis.client.runtime.DocumentImpl.checkIn(DocumentImpl.java:347)
at org.apache.chemistry.opencmis.client.runtime.DocumentImpl.checkIn(DocumentImpl.java:650)

 

My code is the following:

 

Session session = alfrescosession.getSession();
Document newdocument = null;

try{
   Folder folder = getFolder(session, info.getPath(), true);

   String oldid = info.getId();

   Map<String, Object> newDocumentProps = new HashMap<String, Object>();
   newDocumentProps.put(PropertyIds.OBJECT_TYPE_ID, BaseTypeId.CMIS_DOCUMENT.value());
   newDocumentProps.put("cm:title", info.getName());
   ArrayList<String> secIds = new ArrayList<String>();
   secIds.add("P:cm:titled");
   newDocumentProps.put("cmis:secondaryObjectTypeIds", secIds);

   InputStream is = null;
   try {
      is = new FileInputStream(info.getFileHandler().getFile());
      ContentStream contentStream = session.getObjectFactory().createContentStream(
      info.getFileHandler().getName(),
      info.getFileHandler().getFile().length(),
      info.getFileHandler().getContentType(), is);

      if (oldid==null) {
         String name = getUniqueName(session, folder, info.getFileHandler());
         newDocumentProps.put(PropertyIds.NAME, name);

         // Create versioned document object
         Document document = folder.createDocument(newDocumentProps, contentStream, VersioningState.MAJOR);
         String[] versions = AlfrescoUtility.removeVersionFromId(document.getId());
         info.setId(versions[0]);
      } else {

         Document document = session.getLatestDocumentVersion(oldid);
         ObjectId newid = document.checkOut();
         newdocument = (Document)session.getObject(newid);
         newdocument.checkIn(false, newDocumentProps, contentStream, null);

      }

   } catch (Exception ioe) {
      throw ioe;
   } finally {
      try {newdocument.cancelCheckOut();} catch(Exception e1) {}
      try {is.close();} catch(Exception e1) {};
   }

}catch(AlfrescoException e){
   throw e;
}catch(Exception e){
   throw new AlfrescoGenericException("Errore in caricamento: "+ info, e);
}

 

I get the exception on newdocument.checkIn(false, newDocumentProps, contentStream, null).

 

Could someone help me? What is the problem?

Using other istance of Alfresco (version  Community - 5.2.0) this code works for me, maybe there is some configurations to do?

Thanks 

Outcomes