使用CMIS创建两个文件(Alfresco CE 4.2.c)之间的关系



我的模型看起来像这样:

我有两个文件夹(HTMLs)和(图像)。大量的文件入到图像文件夹中,我试图实现的业务用例的一小部分是,当客户端要求说第1章时.html那么该第1章.html的所有相关图像都应该从Alfresco存储库中获取并发送。

我正在使用CMIS,并且能够完成它提供的大部分内容。我已经浏览了大多数教程和代码片段,可以通过这种方式创建关系:

https://anonsvn.springframework.org/svn/se-surf/branches/DEV_CMIS_2/sandbox/spring-cmis/spring-cmis-test/src/main/java/org/springframework/extensions/cmis/test/CmisCreateTest.java

  1. testCreateRelations():工作正常,但当getRelations()调用时再次返回空,并在上下文中设置setIncludeRelations。

  2. testBelarus():它不起作用并抛出以下异常(org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException:Bad Request)。

我使用了"关系"部分中给出的代码片段http://chemistry.apache.org/java/developing/guide.html并成功创建它,但再次发现很难获取该特定 HTML 的引用图像

请提出一些解决方案,因为这是阻止我去露天生产的唯一原因。

如果我以错误的方式(创建关系)这样做,并且是否有更好的解决方案来满足我的需求(使用自定义模型/alfcmis:nodeRef/cmiscustom:docprop_string等),请提出建议。

任何帮助,不胜感激。

谢谢

粘贴 testCreateRelations() 中的代码,并在末尾添加一些代码,演示如何获取关系并将它们打印到控制台(听起来你尝试过这种方式没有运气?无论如何,下面的代码适用于我的存储库):

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

最新更新