There are also methods in the Documents and Media API that retrieve lists
containing several entity types. These methods use many of the same parameters
as those already described for retrieving files and folders. For example,
this method
gets files and shortcuts from a given repository and folder. The status
parameter specifies a
workflow
status. As before, the start
and end
parameters control pagination of the
entities:
getFileEntriesAndFileShortcuts(long repositoryId, long folderId, int status, int start, int end)
To see all such methods, see the
DLAppService
Javadoc.
Follow these steps to use the above getFileEntriesAndFileShortcuts
method.
Note that the example in these steps gets all the files and shortcuts in the
default Site repository’s root folder:
-
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’s arguments any way you wish. To specify the default Site repository, you can use the group ID as the repository ID. This example gets the group ID from the request (
javax.portlet.ActionRequest
) viaParamUtil
:long groupId = ParamUtil.getLong(actionRequest, "groupId");
Getting the parent folder ID, workflow status, and start and end parameters isn’t necessary because Liferay DXP provides constants for them. The next step shows this in detail.
-
Call the service reference method with the data from the previous step and any other values you want to provide. This example calls
getFileEntriesAndFileShortcuts
with the group ID from the previous step and constants for the remaining arguments:_dlAppService.getFileEntriesAndFileShortcuts( groupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, WorkflowConstants.STATUS_APPROVED, QueryUtil.ALL_POS, QueryUtil.ALL_POS )
Here’s a description of the arguments used in this example:
groupId
: Using the group ID as the repository ID specifies that the operation takes place in the default site repository.DLFolderConstants.DEFAULT_PARENT_FOLDER_ID
: Uses theDLFolderConstants
constantDEFAULT_PARENT_FOLDER_ID
to specify the repository’s root folder.WorkflowConstants.STATUS_APPROVED
: Uses theWorkflowConstants
constantSTATUS_APPROVED
to specify only files/folders that have been approved via workflow.QueryUtil.ALL_POS
: Uses theQueryUtil
constantALL_POS
for the start and end positions in the results. This specifies all results, bypassing pagination.