Alfresco REST Core API 按路径查找节点

Alfresco REST Core API find node by path

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

但我还没有找到允许检索节点及其路径的方法。

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

你能告诉我怎么做吗?

您可以尝试使用 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//*'"
  }
}

下面的代码将 return noderef 正如您从 folder/file 路径中期望的那样。

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