To cancel a checkout with the Documents and Media API, use the
cancelCheckOut
method discussed in
File Checkout and Checkin.
The steps here show you how. For general information on using the API, see
Documents and Media API.
Follow these steps to cancel a checkout:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
Get the ID of the file whose checkout you want to cancel. Since it’s common to cancel a checkout in response to a user action, you can extract the file ID from the request. This example does so via
javax.portlet.ActionRequest
andParamUtil
, but you can get it any way you wish:long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");
-
Call the service reference’s
cancelCheckOut
method with the file’s ID:_dlAppService.cancelCheckOut(fileEntryId);
You can find the full code for this example in the cancelFileEntriesCheckOut
method of Liferay DXP’s
EditFileEntryMVCActionCommand
class. This class uses the Documents and Media API to implement almost all the
FileEntry
actions that the Documents and Media app supports. Also note that
this cancelFileEntriesCheckOut
method, as well as the rest of
EditFileEntryMVCActionCommand
, contains additional logic to suit the specific
needs of the Documents and Media app.