Canceling a Checkout

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:

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    
  2. 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 and ParamUtil, but you can get it any way you wish:

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");
    
  3. 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.

Checking Out Files

Checking In Files

Updating Files

« Checking In FilesCopying and Moving Entities »
Was this article helpful?
0 out of 0 found this helpful