use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class DeletedNodesImpl method listDeleted.
@Override
public CollectionWithPagingInfo<Node> listDeleted(Parameters parameters) {
PagingRequest pagingRequest = Util.getPagingRequest(parameters.getPaging());
NodeRef archiveStoreRootNodeRef = nodeService.getStoreArchiveNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// Create canned query
ArchivedNodesCannedQueryBuilder queryBuilder = new ArchivedNodesCannedQueryBuilder.Builder(archiveStoreRootNodeRef, pagingRequest).sortOrderAscending(false).build();
// Query the DB
PagingResults<NodeRef> result = nodeArchiveService.listArchivedNodes(queryBuilder);
Integer totalItems = result.getTotalResultCount().getFirst();
List<Node> nodesFound = new ArrayList<Node>(result.getPage().size());
Map mapUserInfo = new HashMap<>();
for (NodeRef nRef : result.getPage()) {
Node foundNode = nodes.getFolderOrDocument(nRef, null, null, parameters.getInclude(), mapUserInfo);
mapArchiveInfo(foundNode, mapUserInfo);
nodesFound.add(foundNode);
}
return CollectionWithPagingInfo.asPaged(parameters.getPaging(), nodesFound, result.hasMoreItems(), (totalItems == null ? null : totalItems.intValue()));
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class NodesImpl method listChildren.
@Override
public CollectionWithPagingInfo<Node> listChildren(String parentFolderNodeId, Parameters parameters) {
String path = parameters.getParameter(PARAM_RELATIVE_PATH);
final NodeRef parentNodeRef = validateOrLookupNode(parentFolderNodeId, path);
final List<String> includeParam = parameters.getInclude();
QName assocTypeQNameParam = null;
Query q = parameters.getQuery();
if (q != null) {
// filtering via "where" clause
MapBasedQueryWalker propertyWalker = createListChildrenQueryWalker();
QueryHelper.walk(q, propertyWalker);
String assocTypeQNameStr = propertyWalker.getProperty(PARAM_ASSOC_TYPE, WhereClauseParser.EQUALS, String.class);
if (assocTypeQNameStr != null) {
assocTypeQNameParam = getAssocType(assocTypeQNameStr);
}
}
List<Pair<QName, Boolean>> sortProps = getListChildrenSortProps(parameters);
List<FilterProp> filterProps = getListChildrenFilterProps(parameters);
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final PagingResults<FileInfo> pagingResults;
Pair<Set<QName>, Set<QName>> pair = buildSearchTypesAndIgnoreAspects(parameters);
Set<QName> searchTypeQNames = pair.getFirst();
Set<QName> ignoreAspectQNames = pair.getSecond();
Set<QName> assocTypeQNames = buildAssocTypes(assocTypeQNameParam);
// call GetChildrenCannedQuery (via FileFolderService)
if (((filterProps == null) || (filterProps.size() == 0)) && ((assocTypeQNames == null) || (assocTypeQNames.size() == 0)) && (smartStore.isVirtual(parentNodeRef) || (smartStore.canVirtualize(parentNodeRef)))) {
pagingResults = fileFolderService.list(parentNodeRef, searchTypeQNames, ignoreAspectQNames, sortProps, pagingRequest);
} else {
// TODO smart folders (see REPO-1173)
pagingResults = fileFolderService.list(parentNodeRef, assocTypeQNames, searchTypeQNames, ignoreAspectQNames, sortProps, filterProps, pagingRequest);
}
final Map<String, UserInfo> mapUserInfo = new HashMap<>(10);
final List<FileInfo> page = pagingResults.getPage();
List<Node> nodes = new AbstractList<Node>() {
@Override
public Node get(int index) {
FileInfo fInfo = page.get(index);
// minimal info by default (unless "include"d otherwise)
// (pass in null as parentNodeRef to force loading of primary
// parent node as parentId)
Node node = getFolderOrDocument(fInfo.getNodeRef(), null, fInfo.getType(), includeParam, mapUserInfo);
if (node.getPath() != null) {
calculateRelativePath(parentFolderNodeId, node);
}
return node;
}
private void calculateRelativePath(String parentFolderNodeId, Node node) {
NodeRef rootNodeRef = validateOrLookupNode(parentFolderNodeId, null);
try {
// get the path elements
List<String> pathInfos = fileFolderService.getNameOnlyPath(rootNodeRef, node.getNodeRef());
int sizePathInfos = pathInfos.size();
if (sizePathInfos > 1) {
// remove the current child
pathInfos.remove(sizePathInfos - 1);
// build the path string
StringBuilder sb = new StringBuilder(pathInfos.size() * 20);
for (String fileInfo : pathInfos) {
sb.append("/");
sb.append(fileInfo);
}
node.getPath().setRelativePath(sb.toString());
}
} catch (FileNotFoundException e) {
// NOTE: return null as relativePath
}
}
@Override
public int size() {
return page.size();
}
};
Node sourceEntity = null;
if (parameters.includeSource()) {
sourceEntity = getFolderOrDocumentFullInfo(parentNodeRef, null, null, null, mapUserInfo);
}
return CollectionWithPagingInfo.asPaged(paging, nodes, pagingResults.hasMoreItems(), pagingResults.getTotalResultCount().getFirst(), sourceEntity);
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class AbstractSubscriptionServiceWebScript method createPagingRequest.
protected PagingRequest createPagingRequest(WebScriptRequest req) {
int skipCount = parseNumber("skipCount", req.getParameter("skipCount"), 0);
int maxItems = parseNumber("maxItems", req.getParameter("maxItems"), -1);
PagingRequest result = new PagingRequest(skipCount, maxItems, null);
result.setRequestTotalCountMax(Integer.MAX_VALUE);
return result;
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSiteMembers.
public CollectionWithPagingInfo<SiteMember> getSiteMembers(String siteId, Parameters parameters) {
SiteInfo siteInfo = validateSite(siteId);
if (siteInfo == null) {
// site does not exist
throw new EntityNotFoundException(siteId);
}
// set the site id to the short name (to deal with case sensitivity issues with using the siteId from the url)
siteId = siteInfo.getShortName();
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
final List<Pair<SiteService.SortFields, Boolean>> sort = new ArrayList<Pair<SiteService.SortFields, Boolean>>();
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.LastName, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.FirstName, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Role, Boolean.TRUE));
sort.add(new Pair<SiteService.SortFields, Boolean>(SiteService.SortFields.Username, Boolean.TRUE));
PagingResults<SiteMembership> pagedResults = siteService.listMembersPaged(siteId, true, sort, pagingRequest);
List<SiteMembership> siteMembers = pagedResults.getPage();
List<SiteMember> ret = new ArrayList<SiteMember>(siteMembers.size());
for (SiteMembership siteMembership : siteMembers) {
SiteMember siteMember = new SiteMember(siteMembership.getPersonId(), siteMembership.getRole());
ret.add(siteMember);
}
return CollectionWithPagingInfo.asPaged(paging, ret, pagedResults.hasMoreItems(), null);
}
use of org.alfresco.query.PagingRequest in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSites.
public CollectionWithPagingInfo<MemberOfSite> getSites(String personId, Parameters parameters) {
Paging paging = parameters.getPaging();
personId = people.validatePerson(personId);
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// get the sorting options
List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<>(parameters.getSorting().size());
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
for (SortColumn sortCol : sortCols) {
SiteService.SortFields sortProp = SORT_SITE_MEMBERSHIP.get(sortCol.column);
if (sortProp == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortPairs.add(new Pair<>(sortProp, (sortCol.asc ? SortOrder.ASCENDING : SortOrder.DESCENDING)));
}
} else {
// default sort order
sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(SiteService.SortFields.SiteTitle, SortOrder.ASCENDING));
}
// get the unsorted list of site memberships
List<SiteMembership> siteMembers = siteService.listSiteMemberships(personId, 0);
// sort the list of site memberships
int totalSize = siteMembers.size();
final List<SiteMembership> sortedSiteMembers = new ArrayList<>(siteMembers);
Collections.sort(sortedSiteMembers, new SiteMembershipComparator(sortPairs, SiteMembershipComparator.Type.SITES));
PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);
List<MemberOfSite> ret = new ArrayList<>(totalSize);
List<FilterProp> filterProps = getFilterPropListOfSites(parameters);
int counter;
int totalItems = 0;
Iterator<SiteMembership> it = sortedSiteMembers.iterator();
for (counter = 0; it.hasNext(); ) {
SiteMembership siteMember = it.next();
if (filterProps != null && !includeFilter(siteMember, filterProps)) {
continue;
}
if (counter < pageDetails.getSkipCount()) {
totalItems++;
counter++;
continue;
}
if (counter <= pageDetails.getEnd() - 1) {
SiteInfo siteInfo = siteMember.getSiteInfo();
MemberOfSite memberOfSite = new MemberOfSite(siteInfo.getShortName(), siteInfo.getNodeRef(), siteMember.getRole());
ret.add(memberOfSite);
counter++;
}
totalItems++;
}
return CollectionWithPagingInfo.asPaged(paging, ret, counter < totalItems, totalItems);
}
Aggregations