Alfresco Java Client SDK - Usage Part 11 - Trashcan

cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Java Client SDK - Usage Part 11 - Trashcan

jm_pascal
Active Member
1 0 2,102

We will now follow Gavin Cornwell  https://community.alfresco.com/community/ecm/blog/2017/04/24/v1-rest-api-part-11-trashcan   examples and see how we can achieve the same experience using the SDK

To make the exercise more concise we will execute each request in a synchronous way.

Important Notice

Alfresco Java Client is currently in Early Access mode. It evolves as you use them, as you give feedback, and as the developers update and add file. We like to think app & lib development as services that grow and evolve with the involvement of the community.

 

Prerequisites

In order to follow along you'll need an environment to do so, firstly download and install the 5.2.c Early Access Community Release. In our case we will consider Alfresco is available at http://localhost:8080/alfresco and the "admin" user is available and has "admin" as password.

Create File 

File file = new File("W:\\test.txt");
RequestBody requestBody = RequestBody.create(MediaType.parse("text/plain"), file);
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.addFormDataPart("filedata", "content-to-be-deleted.txt", requestBody);
RequestBody fileRequestBody = multipartBuilder.build();
NodeRepresentation nodeToDelete = client.getNodesAPI().createNodeCall(NodesAPI.FOLDER_MY, fileRequestBody).execute().body();‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Delete File 

client.getNodesAPI().deleteNodeCall(nodeToDelete.getId()).execute();
        Assert.assertFalse(client.getNodesAPI().getNodeCall(nodeToDelete.getId()).execute().isSuccessful());‍‍‍‍‍‍‍‍‍‍

List deleted nodes  

TrashcanAPI trashcanAPI = client.getTrashcanAPI();
ResultPaging<DeletedNodeRepresentation> deletedNodes = trashcanAPI.listDeletedNodesCall().execute().body();
Assert.assertTrue(deletedNodes.getCount() > 10);‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Deleted node details 

DeletedNodeRepresentation deletedNodeInfo = trashcanAPI.getDeletedNodeCall(nodeToDelete.getId()).execute().body();
Assert.assertEquals(deletedNodeInfo.getId() , nodeToDelete.getId());‍‍‍‍‍‍‍‍‍‍

Restore node 

NodeRepresentation restoredNode = trashcanAPI.restoreDeletedNodeCall(nodeToDelete.getId(), null).execute().body();
Assert.assertEquals(restoredNode.getId() , nodeToDelete.getId());
Assert.assertTrue(client.getNodesAPI().getNodeCall(nodeToDelete.getId()).execute().isSuccessful());‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Permanently delete node  

client.getNodesAPI().deleteNodeCall(nodeToDelete.getId()).execute();
Response<Void> purgedNodeResponse = trashcanAPI.purgeDeletedNodeCall(restoredNode.getId()).execute();
Assert.assertTrue(purgedNodeResponse.isSuccessful());
Assert.assertFalse(client.getNodesAPI().getNodeCall(nodeToDelete.getId()).execute().isSuccessful());‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Alfresco Java Client SDK Series