Search in sources :

Example 6 with SortColumn

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);
}
Also used : SiteMembershipComparator(org.alfresco.repo.site.SiteMembershipComparator) ArrayList(java.util.ArrayList) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SiteMembership(org.alfresco.repo.site.SiteMembership) SiteService(org.alfresco.service.cmr.site.SiteService) Pair(org.alfresco.util.Pair) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) Paging(org.alfresco.rest.framework.resource.parameters.Paging) SortOrder(org.alfresco.query.CannedQuerySortDetails.SortOrder) PagingRequest(org.alfresco.query.PagingRequest) PageDetails(org.alfresco.query.PageDetails)

Example 7 with SortColumn

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&lt;QName, Boolean&gt;</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;
}
Also used : QName(org.alfresco.service.namespace.QName) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Pair(org.alfresco.util.Pair)

Example 8 with SortColumn

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;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) Pair(org.alfresco.util.Pair)

Example 9 with SortColumn

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);
}
Also used : AbstractList(java.util.AbstractList) SiteInfo(org.alfresco.service.cmr.site.SiteInfo) FilterProp(org.alfresco.repo.node.getchildren.FilterProp) QName(org.alfresco.service.namespace.QName) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) FilterPropString(org.alfresco.repo.node.getchildren.FilterPropString) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn) BeanPropertiesFilter(org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter) PagingRequest(org.alfresco.query.PagingRequest) InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 10 with SortColumn

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;
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) SortColumn(org.alfresco.rest.framework.resource.parameters.SortColumn)

Aggregations

SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)13 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)10 ArrayList (java.util.ArrayList)8 Paging (org.alfresco.rest.framework.resource.parameters.Paging)6 QName (org.alfresco.service.namespace.QName)3 Pair (org.alfresco.util.Pair)3 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)2 HistoricTaskInstanceQuery (org.activiti.engine.history.HistoricTaskInstanceQuery)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 PagingRequest (org.alfresco.query.PagingRequest)2 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)2 BeanPropertiesFilter (org.alfresco.rest.framework.jacksonextensions.BeanPropertiesFilter)2 QueryVariableHolder (org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker.QueryVariableHolder)2 Task (org.alfresco.rest.workflow.api.model.Task)2 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2 java.util (java.util)1