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.
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.
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.
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();
client.getNodesAPI().deleteNodeCall(nodeToDelete.getId()).execute();
Assert.assertFalse(client.getNodesAPI().getNodeCall(nodeToDelete.getId()).execute().isSuccessful());
TrashcanAPI trashcanAPI = client.getTrashcanAPI();
ResultPaging<DeletedNodeRepresentation> deletedNodes = trashcanAPI.listDeletedNodesCall().execute().body();
Assert.assertTrue(deletedNodes.getCount() > 10);
DeletedNodeRepresentation deletedNodeInfo = trashcanAPI.getDeletedNodeCall(nodeToDelete.getId()).execute().body();
Assert.assertEquals(deletedNodeInfo.getId() , nodeToDelete.getId());
NodeRepresentation restoredNode = trashcanAPI.restoreDeletedNodeCall(nodeToDelete.getId(), null).execute().body();
Assert.assertEquals(restoredNode.getId() , nodeToDelete.getId());
Assert.assertTrue(client.getNodesAPI().getNodeCall(nodeToDelete.getId()).execute().isSuccessful());
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());