我正在尝试在cmis-alfresco中更新文档(具有版本支持)。正常文档更新成功。但是当我尝试更新具有relation
的文档时,它得到了错误。
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");
}
错误:
Constraint violation: 00190010 Found 1 integrity violations:
The association source multiplicity has been violated:
我遇到了同样的问题,并且相当绝望,因为它在Alfresco 5.x之前曾经工作过。此外,更新化学和导入org.alfresco.cmis.client.AlfrescoDocument软件包也无济于事。
但我找到了以下解决方法。我们的Alfresco安装一直配置为自动版本,所以我通过简单地为文档设置一个新内容来绕过签出/更新/签入过程:
theDoc.setContentStream(contentStream, true);
请注意,这将在我们的配置中添加一个新版本,因此"theDoc"从现在开始指向文档的旧版本。因此,您可能需要再次获取文档以使其指向最新版本,以避免"文档不是最新版本"错误。