After checking out and editing a file, you must check it back in for other users to see the new version. Once you do so, you can’t access the private working copy. The next time the file is checked out, the private working copy’s contents are overwritten.
method for checking in a file is
checkInFileEntry(long fileEntryId, boolean majorVersion, String changeLog, ServiceContext serviceContext)
For a full description of the method and its parameters, see its
This method uses the private working copy to create a new version of the file.
Updating Files tutorial
majorVersion parameter’s setting determines how the file’s
version number is incremented.
Follow these steps to use
checkInFileEntry to check in a file:
Get a reference to
@Reference private DLAppService _dlAppService;
For more information on this, see the section on getting a service reference in the getting started tutorial.
Get the data needed to populate the
checkInFileEntrymethod’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 via
ParamUtil, 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);
For more information on
ServiceContext, see the tutorial Understanding ServiceContext.
Call the service reference’s
checkInFileEntrymethod with the data from the previous step:
_dlAppService.checkInFileEntry( fileEntryId, majorVersion, changeLog, serviceContext);
You can find the full code for this example in the
of Liferay DXP’s
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
checkInFileEntries method, as well as the rest of
EditFileEntryMVCActionCommand, contains additional logic to suit the specific
needs of the Documents and Media app.