Checking Out Files

To check out a file with the Documents and Media API, use the checkOutFileEntry 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 check out a file:

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    
  2. Get the data needed to populate the checkOutFileEntry method’s arguments. Since it’s common to check out a file in response to an action by the end user, you can extract the data from the request. This example does so via javax.portlet.ActionRequest and ParamUtil, but you can get the data any way you wish:

    long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId");
    
    ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
    
  1. Call the service reference’s checkOutFileEntry method with the data from the previous step:

    _dlAppService.checkOutFileEntry(fileEntryId, serviceContext);
    

You can find the full code for this example in the checkOutFileEntries 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 checkOutFileEntries method, as well as the rest of EditFileEntryMVCActionCommand, contains additional logic to suit the specific needs of the Documents and Media app.

Checking In Files

Canceling a Checkout

Updating Files

« File Checkout and CheckinChecking In Files »
Was this article helpful?
0 out of 0 found this helpful