Follow these steps to use the Capabilities API to move an entity to the Recycle Bin. For an explanation of why you should use the Capabilities API for this, see Deleting Entities.
-
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.