【问题标题】:Alfresco REST Core API find node by pathAlfresco REST Core API 按路径查找节点
【发布时间】:2021-02-24 15:59:51
【问题描述】:

我正在开发一个基于 REST API 的 Alfresco 客户端。

但我还没有找到一种方法可以通过它的路径检索节点。

[ base url: /alfresco/api/-default-/public/alfresco/versions/1 , api version: 1 ] 

你能告诉我怎么做吗?

【问题讨论】:

  • 为什么需要这个?您能否向我们展示您想在请求中使用的路径示例?
  • @Lista a 这里是一个例子:pp:company_home/cm:xlsx/cm:template.xlsx 我想通过它的路径检索template.xlsx文件

标签: rest lucene alfresco cmis


【解决方案1】:

以下代码将按照您对文件夹/文件路径的期望返回 noderef。

public static void main(String[] args) throws IOException {
        client = new AlfrescoClient.Builder().connect("http://localhost:8080/alfresco", "admin", "admin").build();
        NodeRepresentation node = findNodeByPath("Sites/testsite/documentLibrary/TestFolder/UploadTest.txt");
        System.out.println(node == null ? "null" : node.getName());
    }

private static NodeRepresentation findNodeByPath(String path) throws IOException {
    if (path.startsWith("/"))
        path = path.substring(1);
    if (path.endsWith("/"))
        path = path.substring(0, path.length() - 1);
    return findNodeByPath("-root-", path);
}

private static NodeRepresentation findNodeByPath(String parentNodeId, String path) throws IOException {
    String[] pathParts = path.split("/");
    String name = pathParts[0];
    String remaining = pathParts.length == 1 ? "" : path.substring(name.length() + 1, path.length());
    List<NodeRepresentation> children = client.getNodesAPI().listNodeChildrenCall(parentNodeId).execute().body()
            .getList();
    for (NodeRepresentation child : children) {
        if (child.getName().equals(name)) {
            return pathParts.length == 1 ? child : findNodeByPath(child.getId(), remaining);
        }
    }
    return null;
}

【讨论】:

    【解决方案2】:

    您可以尝试使用 AFTS 和 PATH 运算符,它应该可以工作。您基本上是在编写查询,而不是使用特定的 API 方法来“按路径查找”。例如:

    {
      "query": {
        "language": "afts",
        "query": "PATH:'/app:company_home/st:sites/cm:swsdp/cm:documentLibrary/cm:Agency_x0020_Files//*' OR PATH:'/app:company_home/st:sites/cm:swsdp/cm:documentLibrary/cm:Budget_x0020_Files//*'"
      }
    }
    

    【讨论】:

    • 有了它我得到了父母,有了它的ID,我得到了孩子们,我按名字过滤了他们。
    • 您可以简单地调整查询直接找到文档,没有理由不这样做。我刚刚意识到的一件事,PATH 查询不会是事务性的,我不确定这对您来说是否是个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多