The move operation is more flexible than the copy operation. Copying only works with folders, and you can’t copy between repositories. The move operation, however, works with files and folders within or between repositories.
To move a folder, use the
DLAppService
method moveFolder
:
moveFolder(long folderId, long parentFolderId, ServiceContext serviceContext)
For a full description of this method and its parameters, see its
Javadoc.
This method is similar to copyFolder
, but it doesn’t let you change the
folder’s name or description, and it can move folders between repositories.
Folder contents are moved with the folder.
The operation for moving a file is almost identical to moving a folder. To move
a file, use the DLAppService
method moveFileEntry
:
moveFileEntry(long fileEntryId, long newFolderId, ServiceContext serviceContext)
For a full description of this method and its parameters, see its Javadoc.
Follow these steps to use moveFolder
and moveFileEntry
to move a folder and
a file, respectively. Although this example does both just to demonstrate the
procedure:
-
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.
-
Get the data needed to populate the method arguments. Since moving folders and files is typically done in response to a user action, you can get the data from the request. This example does so via
javax.portlet.ActionRequest
andParamUtil
, but you can get the data any way you wish:// Get the folder IDs long folderId = ParamUtil.getLong(actionRequest, "folderId"); long newFolderId = ParamUtil.getLong(actionRequest, "newFolderId"); // Get the file ID long fileEntryId = ParamUtil.getLong(actionRequest, "fileEntryId"); ServiceContext serviceContext = ServiceContextFactory.getInstance( DLFileEntry.class.getName(), 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. -
Call the service reference’s method(s). This example calls
moveFolder
to move a folder (folderId
) to a different folder (newFolderId
). It then callsmoveFileEntry
to move a file (fileEntryId
) to the same destination folder:_dlAppService.moveFolder(folderId, newFolderId, serviceContext); _dlAppService.moveFileEntry(fileEntryId, newFolderId, serviceContext);