Listing Deleted Folders and Files (Trashcan) - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

To list deleted nodes, use the listDeletedNodes method of the TrashcanApi.

For more information about this ReST API endpoint, see List Deleted Folders and Files (Trashcan).

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

import org.alfresco.core.handler.TrashcanApi;
import org.alfresco.core.model.DeletedNodeEntry;
import org.alfresco.core.model.DeletedNodesPaging;
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.ArrayList;
import java.util.List;

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

    @Autowired
    TrashcanApi trashcanApi;

    public void execute() throws IOException {
        Integer skipCount = 0;
        Integer maxItems = 100;
        List<String> include = new ArrayList<>();
        include.add("path");

        LOGGER.info("Listing soft deleted nodes in the trashcan:");
        DeletedNodesPaging deletedNodes = trashcanApi.listDeletedNodes(skipCount, maxItems, include).getBody();
        for (DeletedNodeEntry deletedNodeEntry: deletedNodes.getList().getEntries()) {
            LOGGER.info("    Deleted node: {}", deletedNodeEntry.getEntry());
        }
    }
}

Executing this code would list the soft deleted nodes that exist in the so called “Trashcan”:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar list-deleted-nodes                                       

2021-05-05 09:38:54.983  INFO 14986 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 4.404 seconds (JVM running for 4.861)
2021-05-05 09:38:54.985  INFO 14986 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: list-deleted-nodes
2021-05-05 09:38:54.986  INFO 14986 --- [           main] o.a.t.restapi.ListDeletedNodesCmd        : Listing soft deleted nodes in the trashcan:
2021-05-05 09:38:55.333  INFO 14986 --- [           main] o.a.t.restapi.ListDeletedNodesCmd        :     Deleted node: class DeletedNode {
    id: d32e1b4b-2ae0-48c2-9ee7-6323f8f4e96b
    name: My Gadgets
    nodeType: cm:folder
    isFolder: true
    isFile: false
    isLocked: false
    modifiedAt: 2021-04-30T15:46:17.334Z
    modifiedByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    createdAt: 2021-04-30T15:46:16.332Z
    createdByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    parentId: null
    isLink: null
    isFavorite: null
    content: null
    aspectNames: null
    properties: null
    allowableOperations: null
    path: class PathInfo {
        elements: [class PathElement {
            id: e439190c-3fe0-48a1-8a9a-374fbc54b570
            name: Company Home
            nodeType: cm:folder
            aspectNames: [cm:titled, cm:auditable, app:uifacets]
        }]
        name: /Company Home
        isComplete: true
    }
    permissions: null
    definition: null
    archivedByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    archivedAt: 2021-05-05T08:36:11.141Z
}
2021-05-05 09:38:55.333  INFO 14986 --- [           main] o.a.t.restapi.ListDeletedNodesCmd        :     Deleted node: class DeletedNode {
    id: fe955da0-c4e5-42d3-972f-697424b546b1
    name: newname.txt
    nodeType: acme:document
    isFolder: false
    isFile: true
    isLocked: false
    modifiedAt: 2021-05-04T09:52:17.053Z
    modifiedByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    createdAt: 2021-05-04T09:52:17.053Z
    createdByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    parentId: null
    isLink: null
    isFavorite: null
    content: class ContentInfo {
        mimeType: text/plain
        mimeTypeName: Plain Text
        sizeInBytes: 30
        encoding: ISO-8859-1
    }
    aspectNames: null
    properties: null
    allowableOperations: null
    path: class PathInfo {
        elements: [class PathElement {
            id: e439190c-3fe0-48a1-8a9a-374fbc54b570
            name: Company Home
            nodeType: cm:folder
            aspectNames: [cm:titled, cm:auditable, app:uifacets]
        }, class PathElement {
            id: 7f041db0-fdb6-4185-b921-2fb9ed381480
            name: Imap Attachments
            nodeType: cm:folder
            aspectNames: [cm:titled, cm:auditable, app:uifacets]
        }]
        name: /Company Home/Imap Attachments
        isComplete: true
    }
    permissions: null
    definition: null
    archivedByUser: class UserInfo {
        displayName: Administrator
        id: admin
    }
    archivedAt: 2021-05-04T12:47:10.524Z
}

Note the extra properties at the end that tells you when the node was soft deleted and by who (i.e. archivedAt and archivedByUser). Also, by setting the include parameter to path we get information about where the node was located before it was deleted (i.e. path.name)