The Documents and Media API lets you update file shortcuts (
entities). You can update a shortcut to change the file it points to or the
folder it resides in. You can do this via the
updateFileShortcut(long fileShortcutId, long folderId, long toFileEntryId, ServiceContext serviceContext)
All of this method’s parameters are mandatory. To retain any of the shortcut’s original values, you must provide them to this method. For a full description of the parameters, see the method’s Javadoc.
Follow these steps to use this method to update a file shortcut:
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
updateFileShortcutmethod’s arguments. Since it’s common to update a file shortcut with data submitted 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 fileShortcutId = ParamUtil.getLong(actionRequest, "fileShortcutId"); long folderId = ParamUtil.getLong(actionRequest, "folderId"); long toFileEntryId = ParamUtil.getLong(actionRequest, "toFileEntryId"); ServiceContext serviceContext = ServiceContextFactory.getInstance( DLFileShortcutConstants.getClassName(), actionRequest);
Call the service reference’s
updateFileShortcutmethod with the data from the previous step:
_dlAppService.updateFileShortcut( fileShortcutId, folderId, toFileEntryId, 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
FileShortcut actions that the Documents and Media app supports. Also note that
updateFileShortcut method, as well as the rest of
EditFileShortcutMVCActionCommand, contains additional logic to suit the
specific needs of the Documents and Media app.