java - Alfresco CMIS 查询返回包含分号和版本的 objectId

标签 java alfresco cmis opencmis

我将 alfresco 4.2 与 OpenCMIS java 客户端库 CMIS 1.1 结合使用。

    String serviceUrl = "http://URL/alfresco/api/-default-/public/cmis/versions/1.1/atom"; // Uncomment for Web Services binding

    // default factory implementation
    SessionFactory factory = SessionFactoryImpl.newInstance();
    Map<String, String> parameter = new HashMap<String, String>();
    // user credentials
    parameter.put(SessionParameter.USER, "admin");
    parameter.put(SessionParameter.PASSWORD, "admin");
    // connection settings
    parameter.put(SessionParameter.ATOMPUB_URL, serviceUrl); // Uncomment for Atom Pub binding
    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value()); // Uncomment for Atom Pub binding

    // Set the alfresco object factory
    // Used when using the CMIS extension for Alfresco for working with aspects
    List<Repository> repositories = factory.getRepositories(parameter);
    Session session = repositories.get(0).createSession();

    // Get some repository info
    System.out.println("Repository Name: "+session.getRepositoryInfo().getName());
    System.out.println("Repository ID: "+session.getRepositoryInfo().getId());
    System.out.println("CMIS Version: "+session.getRepositoryInfo().getCmisVersion());

    List<String> cmisObjectId = new ArrayList<String>();

    StringBuilder sb = new StringBuilder();
    sb.append("select * from ged:document m");

    // execute query
    ItemIterable<QueryResult> results = session.query(sb.toString(), false);

    for (QueryResult qResult : results) {

        PropertyData<?> propData = qResult.getPropertyById("cmis:objectId");
        String objectId = (String) propData.getFirstValue();
        cmisObjectId.add(objectId);
        System.out.println(objectId);
    }

结果是:

e8137d5d-cf50-41c4-844a-ec98a44ee73a;1.0
f86557af-89c3-4287-85c4-381e47896c1a;1.0
d56b4e1e-e1dc-4514-9bd2-24080b7879a8;1.0
59a0a9a8-8309-43b6-8040-bb3e9e448171;1.0

但我想要不带版本号的节点 ID,以将其用于 REST API 调用。

谢谢。

最佳答案

CMIS 对象 ID 被定义为不透明字符串。格式在存储库实现之间会有所不同,并且存储库版本之间可能会有所不同。

如果您想要 Alfresco NodeRef,并且确定您正在与 Alfresco 服务器通信,那么您需要的属性是 alfcmis:nodeRef

如果您使用 Apache Chemistry CMIS Workbench 连接到存储库,您可以看到它报告的属性,并从那里看到类似这样的内容

Workbench showing it

关于java - Alfresco CMIS 查询返回包含分号和版本的 objectId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25782847/

相关文章:

java - 为什么我的数组会出现 NullPointer 异常?

java - 如何在 Windows 的露天共享中部署自定义主题?

java - 设置 OpenCMIS InMemory 存储库

cmis - 什么是 OpenCMIS 桥接器?

java - 如何将按钮背景更改为图像,然后在按下时返回默认按钮

java - 建议使用以下哪种方法来使用 Java 连接 MongoDB?

java - Scala 的并发范式与 Go 相比如何?

tomcat - alfresco/share 重定向到一个长站点 url?

authorization - Alfresco 和 google Drive 类似授权

java - Cmis 方法 getAllVersions 出现异常 : CmisNotSupportedException: Operation not supported by the repository for this object