use of org.alfresco.rest.framework.resource.parameters.SortColumn 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);
}
use of org.alfresco.rest.framework.resource.parameters.SortColumn in project alfresco-remote-api by Alfresco.
the class NodesImpl method getListChildrenSortProps.
/**
* <p>Returns a List of sort properties specified by the "sorting" request parameter.</p>
*
* @param parameters The {@link Parameters} object to get the parameters passed into the request
* including:
* - filter, sort & paging params (where, orderBy, skipCount, maxItems)
* - incFiles, incFolders (both true by default)
* @return The list of <code>Pair<QName, Boolean></code> sort properties. If no sort parameters are
* found defaults to {@link #getListChildrenSortPropsDefault() getListChildrenSortPropsDefault}.
*/
protected List<Pair<QName, Boolean>> getListChildrenSortProps(final Parameters parameters) {
List<SortColumn> sortCols = parameters.getSorting();
List<Pair<QName, Boolean>> sortProps;
if ((sortCols != null) && (sortCols.size() > 0)) {
// TODO should we allow isFile in sort (and map to reverse of isFolder) ?
sortProps = new ArrayList<>(sortCols.size());
for (SortColumn sortCol : sortCols) {
QName propQname = PARAM_SYNONYMS_QNAME.get(sortCol.column);
if (propQname == null) {
propQname = createQName(sortCol.column);
}
if (propQname != null) {
sortProps.add(new Pair<>(propQname, sortCol.asc));
}
}
} else {
sortProps = getListChildrenSortPropsDefault();
}
return sortProps;
}
use of org.alfresco.rest.framework.resource.parameters.SortColumn in project alfresco-remote-api by Alfresco.
the class PeopleImpl method getSortProps.
private List<Pair<QName, Boolean>> getSortProps(Parameters parameters) {
List<Pair<QName, Boolean>> sortProps = new ArrayList<>();
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
for (SortColumn sortCol : sortCols) {
QName sortPropQName = sort_params_to_qnames.get(sortCol.column);
if (sortPropQName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
}
} else {
// default sort order
sortProps.add(new Pair<>(ContentModel.PROP_USERNAME, Boolean.TRUE));
}
return sortProps;
}
use of org.alfresco.rest.framework.resource.parameters.SortColumn in project alfresco-remote-api by Alfresco.
the class SitesImpl method getSites.
public CollectionWithPagingInfo<Site> getSites(final Parameters parameters) {
final BeanPropertiesFilter filter = parameters.getFilter();
Paging paging = parameters.getPaging();
PagingRequest pagingRequest = Util.getPagingRequest(paging);
// pagingRequest.setRequestTotalCountMax(requestTotalCountMax)
List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>();
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
for (SortColumn sortCol : sortCols) {
QName sortPropQName = SORT_PARAMS_TO_QNAMES.get(sortCol.column);
if (sortPropQName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProps.add(new Pair<>(sortPropQName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE)));
}
} else {
// default sort order
sortProps.add(new Pair<>(ContentModel.PROP_TITLE, Boolean.TRUE));
}
List<FilterProp> filterProps = getFilterPropListOfSites(parameters);
final PagingResults<SiteInfo> pagingResult = siteService.listSites(filterProps, sortProps, pagingRequest);
final List<SiteInfo> sites = pagingResult.getPage();
int totalItems = pagingResult.getTotalResultCount().getFirst();
final String personId = AuthenticationUtil.getFullyAuthenticatedUser();
List<Site> page = new AbstractList<Site>() {
@Override
public Site get(int index) {
SiteInfo siteInfo = sites.get(index);
String role = null;
if (filter.isAllowed(Site.ROLE)) {
role = siteService.getMembersRole(siteInfo.getShortName(), personId);
}
return new Site(siteInfo, role);
}
@Override
public int size() {
return sites.size();
}
};
return CollectionWithPagingInfo.asPaged(paging, page, pagingResult.hasMoreItems(), totalItems);
}
use of org.alfresco.rest.framework.resource.parameters.SortColumn in project alfresco-remote-api by Alfresco.
the class AuditImpl method getAuditEntrySortProp.
/**
* @param parameters
* @return
* @throws InvalidArgumentException
*/
private Pair<String, Boolean> getAuditEntrySortProp(Parameters parameters) {
Pair<String, Boolean> sortProp = null;
List<SortColumn> sortCols = parameters.getSorting();
if ((sortCols != null) && (sortCols.size() > 0)) {
if (sortCols.size() > 1) {
throw new InvalidArgumentException("Multiple sort fields not allowed.");
}
SortColumn sortCol = sortCols.get(0);
String sortPropName = SORT_PARAMS_TO_NAMES.get(sortCol.column);
if (sortPropName == null) {
throw new InvalidArgumentException("Invalid sort field: " + sortCol.column);
}
sortProp = new Pair<>(sortPropName, (sortCol.asc ? Boolean.TRUE : Boolean.FALSE));
}
return sortProp;
}
Aggregations