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:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
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 viajavax.portlet.ActionRequest
andParamUtil
, but you can get the data any way you wish:long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
-
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.