To check in a file with the Documents and Media API, use the
checkInFileEntry
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 use checkInFileEntry
to check in a file:
-
Get a reference to
DLAppService
:@Reference private DLAppService _dlAppService;
-
Get the data needed to populate the
checkInFileEntry
method’s arguments. Since it’s common to check in 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"); boolean majorVersion = ParamUtil.getBoolean(actionRequest, "majorVersion"); String changeLog = ParamUtil.getString(actionRequest, "changeLog"); ServiceContext serviceContext = ServiceContextFactory.getInstance(actionRequest);
-
Call the service reference’s
checkInFileEntry
method with the data from the previous step:_dlAppService.checkInFileEntry( fileEntryId, majorVersion, changeLog, serviceContext);
You can find the full code for this example in the checkInFileEntries
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 checkInFileEntries
method, as well as the rest of
EditFileEntryMVCActionCommand
, contains additional logic to suit the specific
needs of the Documents and Media app.