我使用OpenCmis in-memory进行测试。但是当我创建一个文档时,我不允许将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.
我错过了什么?
答案 0 :(得分:1)
我找到了原因......
通过执行以下代码,我发现OBJECT_TYPE_ID'cmis:document'不允许版本控制。
查看所有可用OBJECT_TYPE_ID(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 + " ");
}
}
这导致了这样的列表:
TYPE:CMIS文件夹(CMIS文件夹类型说明)Id:cmis:文件夹 Fileable:true Queryable:true
TYPE:CMIS文件(CMIS文件类型说明) Id:cmis:document Fileable:true可查询:true [DOC Attrs-&gt;] 可版本化:false内容:允许
TYPE:我的类型1级别1(我的类型1级别1类型的描述)
Id:MyDocType1 Fileable:true可查询:true [DOC Attrs-&gt;] 可版本化:false内容:允许TYPE:VersionedType(VersionedType类型的描述)
Id:VersionableType Fileable:true Queryable:true [DOC Attrs-&gt;] 版本:true内容:允许
正如您所看到的,最后一个OBJECT_TYPE_ID具有可版本化:true ...当我使用它时它确实有效。