Instead of deleting entities, you can move them to the Recycle Bin. Note that the Recycle Bin isn’t part of the Documents and Media API. Although you can use the Recycle Bin API directly, in the case of Documents and Media it’s better to use the Capabilities API. This is because some third-party repositories (e.g., SharePoint) don’t support Recycle Bin functionality. The Capabilities API lets you verify that the repository you’re working in supports the Recycle Bin. It’s therefore a best practice to always use the Capabilities API when moving entities to the Recycle Bin.
Follow these steps to use the Capabilities API to move an entity to the Recycle Bin:
-
Verify that the repository supports the Recycle Bin. Do this by calling the repository object’s
isCapabilityProvided
method withTrashCapability.class
as its argument. This example does so inif
statement’s condition:if (repository.isCapabilityProvided(TrashCapability.class)) { // The code to move the entity to the Recycle Bin // You'll write this in the next step }
-
Move the entity to the Recycle Bin if the repository supports it. To do this, first get a
TrashCapability
reference by calling the repository object’sgetCapability
method withTrashCapability.class
as its argument. Then call theTrashCapability
method that moves the entity to the Recycle Bin. For example, this code callsmoveFileEntryToTrash
to move a file to the Recycle Bin:if (repository.isCapabilityProvided(TrashCapability.class)) { TrashCapability trashCapability = repository.getCapability(TrashCapability.class); trashCapability.moveFileEntryToTrash(user.getUserId(), fileEntry); }
See the
TrashCapability
Javadoc for information on the methods you can use to move other types of entities to the Recycle Bin.