1

我使用内存中的OpenCmis进行测试。但是当我创建一个文档时,我不允许将 versioningState 设置为 versioningState.NONE。

创建的文档在某种程度上是不可版本化的......我使用了来自http://chemistry.apache.org/java/examples/example-create-update.html的代码

测试方法:

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

我得到的例外:

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

我错过了什么?

4

1 回答 1

1

我找到了原因...

通过执行以下代码,我发现 OBJECT_TYPE_ID 'cmis:document' 不允许版本控制。

查看所有可用 OBJECT_TYPE_ID 的代码(来源):

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

这导致了这样的列表:

TYPE:CMIS 文件夹(CMIS 文件夹类型的描述) Id:cmis:folder Fileable:true Queryable:true

TYPE:CMIS 文档(CMIS 文档类型的描述) Id:cmis:document Fileable:true Queryable:true [DOC Attrs->] Versionable:false Content:ALLOWED

TYPE:My Type 1 Level 1 (我的 Type 1 Level 1 类型的描述)
Id:MyDocType1 Fileable:true Queryable:true [DOC Attrs->] Versionable:false Content:ALLOWED

TYPE:VersionedType (VersionedType 类型的描述)
Id:VersionableType Fileable:true Queryable:true [DOC Attrs->] Versionable:true Content:ALLOWED

如您所见,最后一个 OBJECT_TYPE_ID 具有 versionable: true... 并且当我使用它时它确实有效。

于 2013-05-23T12:46:26.033 回答