Deleting a Folder or File - Alfresco Content Services - 23.4 - 23.4 - Ready - Alfresco - external

Alfresco Content Services

Platform
Alfresco
Product
Alfresco Content Services
Release
23.4
License

To delete a folder or a file node, use the deleteNode method of the NodesApi.

For more information about this ReST API endpoint, see Delete a Folder or File.

import org.alfresco.core.handler.NodesApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

import java.io.IOException;

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

    @Autowired
    NodesApi nodesApi;

    public void execute(String nodeId) throws IOException {
        // If true, then the node is deleted permanently, without moving to the trashcan.
        // Only the owner of the node or an admin can permanently delete the node.
        // default value = false
        Boolean permanent = false;

        ResponseEntity<Void> deletedNodeResponse = nodesApi.deleteNode(nodeId, permanent);
        LOGGER.info("Deleted node response: {}", deletedNodeResponse);
    }
}

Executing this code would give the following result, passing in the node to delete:

% java -jar target/rest-api-0.0.1-SNAPSHOT.jar delete-node fe955da0-c4e5-42d3-972f-697424b546b1                                   

2021-05-04 13:47:10.376  INFO 29542 --- [           main] o.a.tutorial.restapi.RestApiApplication  : Started RestApiApplication in 3.639 seconds (JVM running for 4.406)
2021-05-04 13:47:10.377  INFO 29542 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[0]: delete-node
2021-05-04 13:47:10.379  INFO 29542 --- [           main] o.a.tutorial.restapi.RestApiApplication  : args[1]: fe955da0-c4e5-42d3-972f-697424b546b1
2021-05-04 13:47:10.787  INFO 29542 --- [           main] o.a.tutorial.restapi.DeleteNodeCmd       : Deleted node response: 
  <204 NO_CONTENT No Content,[cache-control:"no-cache", connection:"keep-alive", content-type:"application/json;charset=UTF-8", date:"Tue,