Getting Folder/File Metadata - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

To get metadata for a node, such as a file or folder, in the repository use the getNode method of the NodesApi , which is one of the main APIs used when you want to manipulate folders and files.

For more information about this ReST API endpoint, see Get Folder/File Metadata.

For a description of the common parameters, such as include, see Common Parameters.

import org.alfresco.core.handler.NodesApi;
import org.alfresco.core.model.NodeEntry;
import org.alfresco.core.model.Node;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.List;

@Component
public class GetNodeMetadataCmd {
    static final Logger LOGGER = LoggerFactory.getLogger(GetNodeMetadataCmd.class);

    @Autowired
    NodesApi nodesApi;

    public void execute() throws IOException {
        Node node = getNode("-root-", null);
        Node node2 = getNode("-root-", "/Data Dictionary");
    }

    /**
     * Get a node (file/folder).
     *
     * @param nodeId             the id of the node that we want to fetch metadata for. If relativeFolderPath is specified, then metadata for this node will be returned. Besides node ID the aliases -my-, -root- and -shared- are also supported.
     * @param relativeFolderPath A path relative to the nodeId, if this is not null, then metadata is returned on the node resolved by this path
     * @return Node object if exist, or null if does not exist
     */
    private Node getNode(String nodeId,
                         String relativeFolderPath) {
        List<String> include = null;
        List<String> fields = null;

        NodeEntry result = nodesApi.getNode(nodeId, include, relativeFolderPath, fields).getBody();
        LOGGER.info("Got node {}", result.getEntry());
        return result.getEntry();
    }
}

Executing this code would give the following result:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar get-node        
                                       
2021-04-29 08:09:22.215  INFO 18370 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.536 seconds (JVM running for 4.449)
2021-04-29 08:09:22.217  INFO 18370 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: get-node
2021-04-29 08:09:22.485  INFO 18370 --- [           main] o.a.tutorial.restapi.GetNodeMetadataCmd  : Got node class Node {
    id: e439190c-3fe0-48a1-8a9a-374fbc54b570
    name: Company Home
    nodeType: cm:folder
    isFolder: true
    isFile: false
    isLocked: false
    modifiedAt: 2021-04-28T11:48:08.325Z
    modifiedByUser: class UserInfo {
        displayName: System
        id: System
    }
    createdAt: 2021-04-28T11:47:59.098Z
    createdByUser: class UserInfo {
        displayName: System
        id: System
    }
    parentId: null
    isLink: null
    isFavorite: null
    content: null
    aspectNames: [cm:titled, cm:auditable, app:uifacets]
    properties: {cm:title=Company Home, cm:description=The company root space, app:icon=space-icon-default}
    allowableOperations: null
    path: null
    permissions: null
    definition: null
}
2021-04-29 08:09:22.538  INFO 18370 --- [           main] o.a.tutorial.restapi.GetNodeMetadataCmd  : Got node class Node {
    id: 1219e0ff-941f-49df-9151-997b84a8359b
    name: Data Dictionary
    nodeType: cm:folder
    isFolder: true
    isFile: false
    isLocked: false
    modifiedAt: 2021-04-28T11:48:17.700Z
    modifiedByUser: class UserInfo {
        displayName: System
        id: System
    }
    createdAt: 2021-04-28T11:47:59.199Z
    createdByUser: class UserInfo {
        displayName: System
        id: System
    }
    parentId: e439190c-3fe0-48a1-8a9a-374fbc54b570
    isLink: null
    isFavorite: null
    content: null
    aspectNames: [cm:titled, cm:auditable, app:uifacets]
    properties: {cm:title=Data Dictionary, cm:description=User managed definitions, app:icon=space-icon-default}
    allowableOperations: null
    path: null
    permissions: null
    definition: null
}

See also Working with Relationships between Folders or Files for information on how to list associations for a node.