use of org.alfresco.repo.site.SiteMembershipComparator 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