Updating File Shortcuts

To update a file shortcut with the Documents and Media API, you must use the updateFileShortcut method discussed in Updating Entities. The steps here show you how. For general information on using the API, see Documents and Media API.

Follow these steps to update a file shortcut:

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    
  2. Get the data needed to populate the updateFileShortcut method’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 javax.portlet.ActionRequest and 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);
    
  1. Call the service reference’s updateFileShortcut method with the data from the previous step:

    _dlAppService.updateFileShortcut(
            fileShortcutId, folderId, toFileEntryId, serviceContext);
    

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

Creating File Shortcuts

Deleting File Shortcuts

« Updating FoldersFile Checkout and Checkin »
Was this article helpful?
0 out of 0 found this helpful