我的模特看起来像这样:
我有两个文件夹(HTML)& (图片)。大量的文件被插入到图像文件夹中,而我试图实现的业务用例的一小部分是,当客户端请求chapter1.html时,那个chapter1.html的所有相关图像应该从Alfresco存储库中获取并发送。
我正在使用CMIS并能够完成它提供的大部分内容。我已经阅读了大部分教程和代码片段,并且可以通过这种方式创建关系:
testCreateRelationship():工作正常,但在使用上下文设置的setIncludeRelationships调用getRelationships()时再次返回空。
testBelarus():它不起作用并抛出异常(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException:Bad Request)。
我使用了“关系”中提供的代码段。部分 http://chemistry.apache.org/java/developing/guide.html 并成功创建它,但再次发现难以获取特定HTML的引用图像
请提出一些解决方案,因为这是阻止我在生产中去Alfresco的唯一办法。
如果我以错误的方式(创建关系)并且如果有更好的解决方案满足我的要求(使用自定义模型/ alfcmis:nodeRef / cmiscustom:docprop_string等),请建议。
感谢任何帮助。
由于
答案 0 :(得分:3)
将testCreateRelationship()中的代码粘贴到最后添加一些代码,演示如何获取关系并将它们打印到控制台(听起来就像你试过这样没有运气?下面的代码无论如何都适用于我的repo):< / p>
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());
}
}