Updating File Shortcuts

The Documents and Media API lets you update file shortcuts (FileShortcut 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 DLAppService method updateFileShortcut:

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:

  1. Get a reference to DLAppService:

    @Reference
    private DLAppService _dlAppService;
    

    For more information on this, see the section on getting a service reference in the getting started tutorial.

  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);
    

    For more information on getting folder IDs, see the getting started tutorial’s section on specifying folders. For more information on ServiceContext, see the tutorial Understanding ServiceContext.

  3. 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 Check-out and Check-in »
Este artigo foi útil?
Utilizadores que acharam útil: 0 de 0