To list deleted nodes, use the restoreDeletedNode method of the TrashcanApi.
For more information about this ReST API endpoint, see Restore Deleted Folders and Files (Trashcan).
For a description of the common parameters, such as fields, see Common Parameters.
import org.alfresco.core.handler.TrashcanApi;
import org.alfresco.core.model.DeletedNodeBodyRestore;
import org.alfresco.core.model.NodeEntry;
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 RestoreDeletedNodeCmd {
static final Logger LOGGER = LoggerFactory.getLogger(RestoreDeletedNodeCmd.class);
@Autowired
TrashcanApi trashcanApi;
public void execute(String nodeId, String restoreFolderId) throws IOException {
List<String> fields = null;
// POST body need to ne supplied with target folder ID
DeletedNodeBodyRestore deletedNodeBodyRestore = new DeletedNodeBodyRestore();
deletedNodeBodyRestore.setTargetParentId(restoreFolderId);
deletedNodeBodyRestore.setAssocType("cm:contains");
NodeEntry restoredNode = trashcanApi.restoreDeletedNode(nodeId, fields, deletedNodeBodyRestore).getBody();
LOGGER.info("Restored node: {}", restoredNode.getEntry());
}
}
Executing this code would restore a node with passed in ID. The location folder ID is also passed in:
% java -jar target/rest-api-0.0.1-SNAPSHOT.jar restore-deleted-node b717304b-1c07-400b-b8a8-3268ea79c49f 7f041db0-fdb6-4185-b921-2fb9ed381480
2021-05-05 09:46:19.805 INFO 15098 --- [ main] o.a.tutorial.restapi.RestApiApplication : Started RestApiApplication in 3.033 seconds (JVM running for 3.498)
2021-05-05 09:46:19.807 INFO 15098 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[0]: restore-deleted-node
2021-05-05 09:46:19.808 INFO 15098 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[1]: b717304b-1c07-400b-b8a8-3268ea79c49f
2021-05-05 09:46:19.808 INFO 15098 --- [ main] o.a.tutorial.restapi.RestApiApplication : args[2]: 7f041db0-fdb6-4185-b921-2fb9ed381480
2021-05-05 09:46:20.436 INFO 15098 --- [ main] o.a.t.restapi.RestoreDeletedNodeCmd : Restored node: class Node {
id: b717304b-1c07-400b-b8a8-3268ea79c49f
name: newname.txt
nodeType: acme:document
isFolder: false
isFile: true
isLocked: false
modifiedAt: 2021-05-04T09:19:49.903Z
modifiedByUser: class UserInfo {
displayName: Administrator
id: admin
}
createdAt: 2021-05-04T09:19:49.903Z
createdByUser: class UserInfo {
displayName: Administrator
id: admin
}
parentId: 7f041db0-fdb6-4185-b921-2fb9ed381480
isLink: null
isFavorite: null
content: class ContentInfo {
mimeType: text/plain
mimeTypeName: Plain Text
sizeInBytes: 30
encoding: ISO-8859-1
}
aspectNames: [rn:renditioned, cm:versionable, cm:titled, cm:auditable, acme:securityClassified, cm:taggable, cm:author, cm:thumbnailModification]
properties: {cm:title=UPDATED title, cm:versionType=MAJOR, acme:documentId=DOC-001, cm:versionLabel=1.0, acme:securityClassification=Company Confidential, cm:lastThumbnailModification=[doclib:1620120715749], cm:description=UPDATED description, cm:taggable=[a6da6c4d-cb6b-41b5-a010-7188459dd3cb, 9a9044c9-3787-44ca-bd92-c6797c9a82ae]}
allowableOperations: null
path: null
permissions: null
definition: null
}