粘贴来自 testCreateRelationship() 的代码,最后添加一些代码,演示如何获取关系并将它们打印到控制台(听起来你尝试这种方式没有运气?下面的代码无论如何都适用于我的 repo):
public void testCreateRelationship()
{
Session session = createSession();
Folder root = session.getRootFolder();
Map<String,String> newFolderProps = new HashMap<String, String>();
newFolderProps.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
String name = "testCreateRelationship " + System.currentTimeMillis();
newFolderProps.put(PropertyIds.NAME, name);
Folder folder = root.createFolder(newFolderProps, null, null, null, session.getDefaultContext());
System.out.println(folder.getName());
Map<String,String> newDocProps1 = new HashMap<String, String>();
newDocProps1.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
newDocProps1.put(PropertyIds.NAME, "Test Doc 1");
ContentStream contentStream1 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes()));
Document doc1 = folder.createDocument(newDocProps1, contentStream1, VersioningState.MAJOR, null, null, null, session.getDefaultContext());
Map<String,String> newDocProps2 = new HashMap<String, String>();
newDocProps2.put(PropertyIds.OBJECT_TYPE_ID, "D:cmiscustom:document");
newDocProps2.put(PropertyIds.NAME, "Test Doc 2");
ContentStream contentStream2 = new ContentStreamImpl("xyz.txt", null, "plain/text", new ByteArrayInputStream("some content".getBytes()));
Document doc2 = folder.createDocument(newDocProps2, contentStream2, VersioningState.MAJOR, null, null, null, session.getDefaultContext());
Map<String, Serializable> relProps = new HashMap<String, Serializable>();
relProps.put("cmis:sourceId", doc1.getId());
relProps.put("cmis:targetId", doc2.getId());
relProps.put("cmis:objectTypeId", "R:cmiscustom:assoc");
session.createRelationship(relProps, null, null, null);
// create a OperationContext that fetches relationships on both ends...
OperationContext operationContext = new OperationContextImpl();
operationContext.setIncludeRelationships(IncludeRelationships.BOTH);
CmisObject object = session.getObject(doc1,operationContext);
List<Relationship> relationships = object.getRelationships();
for (Relationship rel : relationships){
System.out.println("relation: "+ rel.getName());
}
}