gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 05:13:41 26 4
gpt4 key购买 nike

我的模型看起来像这样:

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

我正在使用 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

  • testCreateRelationship(): 工作正常,但当 getRelationships() 在 Context 上设置 setIncludeRelationships 时再次返回空。
  • 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 等),请提出建议。

    任何帮助表示赞赏。

    谢谢

    最佳答案

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

    关于java - 使用 CMIS 创建两个文件 (Alfresco CE 4.2.c) 之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14563492/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com