Search in sources :

Example 1 with EmptyPagingResults

use of org.alfresco.query.EmptyPagingResults in project alfresco-remote-api by Alfresco.

the class GroupsImpl method getGroups.

public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
    final List<String> includeParam = parameters.getInclude();
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    // Parse where clause properties.
    Query q = parameters.getQuery();
    Boolean isRootParam = null;
    String zoneFilter = null;
    if (q != null) {
        GroupsQueryWalker propertyWalker = new GroupsQueryWalker();
        QueryHelper.walk(q, propertyWalker);
        isRootParam = propertyWalker.getIsRoot();
        List<String> zonesParam = propertyWalker.getZones();
        if (zonesParam != null) {
            validateZonesParam(zonesParam);
            zoneFilter = zonesParam.get(0);
        }
    }
    final AuthorityType authorityType = AuthorityType.GROUP;
    final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
    PagingResults<AuthorityInfo> pagingResult;
    try {
        pagingResult = getAuthoritiesInfo(authorityType, isRootParam, zoneFilter, rootAuthorities, sortProp, paging);
    } catch (UnknownAuthorityException e) {
        // Non-existent zone
        pagingResult = new EmptyPagingResults<>();
    }
    // Create response.
    final List<AuthorityInfo> page = pagingResult.getPage();
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    List<Group> groups = new AbstractList<Group>() {

        @Override
        public Group get(int index) {
            AuthorityInfo authorityInfo = page.get(index);
            return getGroup(authorityInfo, includeParam, rootAuthorities);
        }

        @Override
        public int size() {
            return page.size();
        }
    };
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : AbstractList(java.util.AbstractList) Group(org.alfresco.rest.api.model.Group) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) EmptyPagingResults(org.alfresco.query.EmptyPagingResults)

Example 2 with EmptyPagingResults

use of org.alfresco.query.EmptyPagingResults in project alfresco-remote-api by Alfresco.

the class ForumTopicsFilteredGet method doSearch.

/**
 * Do the actual search
 *
 * @param searchQuery Pair with query string in first and query language in second
 * @param sortAscending boolean
 * @param paging PagingRequest
 */
protected PagingResults<TopicInfo> doSearch(Pair<String, String> searchQuery, boolean sortAscending, PagingRequest paging) {
    ResultSet resultSet = null;
    PagingResults<TopicInfo> pagedResults = new EmptyPagingResults<TopicInfo>();
    String sortOn = "@{http://www.alfresco.org/model/content/1.0}created";
    // Setup the search parameters
    SearchParameters sp = new SearchParameters();
    sp.addStore(SPACES_STORE);
    sp.setQuery(searchQuery.getFirst());
    sp.setLanguage(searchQuery.getSecond());
    sp.addSort(sortOn, sortAscending);
    if (paging.getMaxItems() > 0) {
        // Multiply maxItems by 10.  This is to catch topics that have multiple replies and ensure that the maximum number of topics is shown.
        sp.setLimit(paging.getMaxItems() * 10);
        sp.setLimitBy(LimitBy.FINAL_SIZE);
    }
    if (paging.getSkipCount() > 0) {
        sp.setSkipCount(paging.getSkipCount());
    }
    try {
        resultSet = searchService.query(sp);
        pagedResults = wrap(resultSet, paging);
    } finally {
        try {
            resultSet.close();
        } catch (Exception e) {
        // do nothing
        }
    }
    return pagedResults;
}
Also used : SearchParameters(org.alfresco.service.cmr.search.SearchParameters) ResultSet(org.alfresco.service.cmr.search.ResultSet) EmptyPagingResults(org.alfresco.query.EmptyPagingResults) TopicInfo(org.alfresco.service.cmr.discussion.TopicInfo) WebScriptException(org.springframework.extensions.webscripts.WebScriptException)

Example 3 with EmptyPagingResults

use of org.alfresco.query.EmptyPagingResults in project alfresco-remote-api by Alfresco.

the class GroupsFilter method getGroups.

public CollectionWithPagingInfo<Group> getGroups(final Parameters parameters) {
    Paging paging = parameters.getPaging();
    // Retrieve sort column. This is limited for now to sort column due to
    // v0 api implementation. Should be improved in the future.
    Pair<String, Boolean> sortProp = getGroupsSortProp(parameters);
    // Parse where clause properties.
    GroupsFilter groupsFilters = getGroupsFilterFromQueryParameters(parameters.getQuery());
    final AuthorityType authorityType = AuthorityType.GROUP;
    final Set<String> rootAuthorities = getAllRootAuthorities(authorityType);
    PagingResults<AuthorityInfo> pagingResult;
    try {
        pagingResult = getAuthoritiesInfo(authorityType, groupsFilters, rootAuthorities, sortProp, paging);
    } catch (UnknownAuthorityException e) {
        // Non-existent zone
        pagingResult = new EmptyPagingResults<>();
    }
    List<Group> groups = createGroupsResponse(pagingResult.getPage(), parameters.getInclude(), rootAuthorities);
    int totalItems = pagingResult.getTotalResultCount().getFirst();
    return CollectionWithPagingInfo.asPaged(paging, groups, pagingResult.hasMoreItems(), totalItems);
}
Also used : Group(org.alfresco.rest.api.model.Group) Paging(org.alfresco.rest.framework.resource.parameters.Paging) AuthorityType(org.alfresco.service.cmr.security.AuthorityType) AuthorityInfo(org.alfresco.repo.security.authority.AuthorityInfo) UnknownAuthorityException(org.alfresco.repo.security.authority.UnknownAuthorityException) EmptyPagingResults(org.alfresco.query.EmptyPagingResults)

Aggregations

EmptyPagingResults (org.alfresco.query.EmptyPagingResults)3 AuthorityInfo (org.alfresco.repo.security.authority.AuthorityInfo)2 UnknownAuthorityException (org.alfresco.repo.security.authority.UnknownAuthorityException)2 Group (org.alfresco.rest.api.model.Group)2 Paging (org.alfresco.rest.framework.resource.parameters.Paging)2 AuthorityType (org.alfresco.service.cmr.security.AuthorityType)2 AbstractList (java.util.AbstractList)1 Query (org.alfresco.rest.framework.resource.parameters.where.Query)1 TopicInfo (org.alfresco.service.cmr.discussion.TopicInfo)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)1 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)1