Search in sources :

Example 1 with SiteMembership

use of org.alfresco.repo.site.SiteMembership 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);
}
Also used : SiteInfo(org.alfresco.service.cmr.site.SiteInfo) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) EntityNotFoundException(org.alfresco.rest.framework.core.exceptions.EntityNotFoundException) PagingRequest(org.alfresco.query.PagingRequest) SiteMembership(org.alfresco.repo.site.SiteMembership) SiteService(org.alfresco.service.cmr.site.SiteService) FilterPropBoolean(org.alfresco.repo.node.getchildren.FilterPropBoolean) Pair(org.alfresco.util.Pair)

Example 2 with SiteMembership

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

Aggregations

ArrayList (java.util.ArrayList)2 PagingRequest (org.alfresco.query.PagingRequest)2 SiteMembership (org.alfresco.repo.site.SiteMembership)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)2 SiteService (org.alfresco.service.cmr.site.SiteService)2 Pair (org.alfresco.util.Pair)2 SortOrder (org.alfresco.query.CannedQuerySortDetails.SortOrder)1 PageDetails (org.alfresco.query.PageDetails)1 FilterProp (org.alfresco.repo.node.getchildren.FilterProp)1 FilterPropBoolean (org.alfresco.repo.node.getchildren.FilterPropBoolean)1 SiteMembershipComparator (org.alfresco.repo.site.SiteMembershipComparator)1 EntityNotFoundException (org.alfresco.rest.framework.core.exceptions.EntityNotFoundException)1 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)1 SortColumn (org.alfresco.rest.framework.resource.parameters.SortColumn)1