Question

I use OpenCmis in-memory for testing. But when I create a document I am not allowed to set the versioningState to something else then versioningState.NONE.

The doc created is not versionable some way... I used the code from http://chemistry.apache.org/java/examples/example-create-update.html

The test method:

public void test() {
    String filename = "test123";
    Folder folder = this.session.getRootFolder();

    // Create a doc
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:document");
    properties.put(PropertyIds.NAME, filename);
    String docText = "This is a sample document";
    byte[] content = docText.getBytes();
    InputStream stream = new ByteArrayInputStream(content);
    ContentStream contentStream = this.session.getObjectFactory().createContentStream(filename, Long.valueOf(content.length), "text/plain", stream);

    Document doc = folder.createDocument(
            properties,
            contentStream,
            VersioningState.MAJOR);
}

The exception I get:

org.apache.chemistry.opencmis.commons.exceptions.CmisConstraintException: The versioning state flag is imcompatible to the type definition.

What am I missing?

Was it helpful?

Solution

I found the reason...

By executing the following code I discovered that the OBJECT_TYPE_ID 'cmis:document' don't allow versioning.

Code to view all available OBJECT_TYPE_ID's (source):

    boolean includePropertyDefintions = true;
      for (t in session.getTypeDescendants(
            null, // start at the top of the tree
            -1, // infinite depth recursion
            includePropertyDefintions // include prop defs
            )) {
         printTypes(t, "");
      }

   static void printTypes(Tree tree, String tab) {          
      ObjectType objType = tree.getItem();
      println(tab + "TYPE:" + objType.getDisplayName() +
            " (" + objType.getDescription() + ")");
      // Print some of the common attributes for this type
      print(tab + " Id:" + objType.getId());                            
      print(" Fileable:" + objType.isFileable());
      print(" Queryable:" + objType.isQueryable());

      if (objType instanceof DocumentType) {                            
         print(" [DOC Attrs->] Versionable:" +
            ((DocumentType)objType).isVersionable());
         print(" Content:" +
            ((DocumentType)objType).getContentStreamAllowed());
      }
      println(""); // end the line
      for (t in tree.getChildren()) {
         // there are more - call self for next level
         printTypes(t, tab + " ");
      }
   }

This resulted in a list like this:

TYPE:CMIS Folder (Description of CMIS Folder Type) Id:cmis:folder Fileable:true Queryable:true

TYPE:CMIS Document (Description of CMIS Document Type) Id:cmis:document Fileable:true Queryable:true [DOC Attrs->] Versionable:false Content:ALLOWED

TYPE:My Type 1 Level 1 (Description of My Type 1 Level 1 Type)
Id:MyDocType1 Fileable:true Queryable:true [DOC Attrs->] Versionable:false Content:ALLOWED

TYPE:VersionedType (Description of VersionedType Type)
Id:VersionableType Fileable:true Queryable:true [DOC Attrs->] Versionable:true Content:ALLOWED

As you can see the last OBJECT_TYPE_ID has versionable: true... and when I use that it does work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top