Search in sources :

Example 31 with PagingRequest

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

the class QuickShareLinksImpl method findLinks.

public CollectionWithPagingInfo<QuickShareLink> findLinks(Parameters parameters) {
    checkEnabled();
    String queryString = "ASPECT:\"" + QuickShareModel.ASPECT_QSHARE.toString() + "\"";
    SearchParameters sp = new SearchParameters();
    // note: REST API query parameter (ie. where clause filter) - not to be confused with search query ;-)
    Query q = parameters.getQuery();
    if (q != null) {
        // filtering via "where" clause
        MapBasedQueryWalker propertyWalker = new MapBasedQueryWalker(FIND_SHARED_LINKS_QUERY_PROPERTIES, null);
        QueryHelper.walk(q, propertyWalker);
        String sharedByUserId = propertyWalker.getProperty(PARAM_SHAREDBY, WhereClauseParser.EQUALS, String.class);
        if (sharedByUserId != null) {
            if (People.DEFAULT_USER.equalsIgnoreCase(sharedByUserId)) {
                sharedByUserId = AuthenticationUtil.getFullyAuthenticatedUser();
            }
            QueryParameterDefinition qpd = new QueryParameterDefImpl(QuickShareModel.PROP_QSHARE_SHAREDBY, dictionaryService.getDataType(DataTypeDefinition.TEXT), true, sharedByUserId);
            sp.addQueryParameterDefinition(qpd);
            String qsharedBy = QuickShareModel.PROP_QSHARE_SHAREDBY.toPrefixString(namespaceService);
            queryString += " +@" + SearchLanguageConversion.escapeLuceneQuery(qsharedBy) + ":\"${" + qsharedBy + "}\"";
        }
    }
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery(queryString);
    sp.addStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    Paging paging = parameters.getPaging();
    PagingRequest pagingRequest = Util.getPagingRequest(paging);
    sp.setSkipCount(pagingRequest.getSkipCount());
    sp.setMaxItems(pagingRequest.getMaxItems());
    sp.addSort("@" + ContentModel.PROP_MODIFIED, false);
    ResultSet results = searchService.query(sp);
    List<QuickShareLink> qsLinks = new ArrayList<>(results.length());
    List<String> includeParam = parameters.getInclude();
    for (ResultSetRow row : results) {
        NodeRef nodeRef = row.getNodeRef();
        qsLinks.add(getQuickShareInfo(nodeRef, false, includeParam));
    }
    results.close();
    return CollectionWithPagingInfo.asPaged(paging, qsLinks, results.hasMore(), Long.valueOf(results.getNumberFound()).intValue());
}
Also used : QueryParameterDefImpl(org.alfresco.repo.search.QueryParameterDefImpl) Query(org.alfresco.rest.framework.resource.parameters.where.Query) Paging(org.alfresco.rest.framework.resource.parameters.Paging) ArrayList(java.util.ArrayList) ResultSetRow(org.alfresco.service.cmr.search.ResultSetRow) PagingRequest(org.alfresco.query.PagingRequest) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) NodeRef(org.alfresco.service.cmr.repository.NodeRef) MapBasedQueryWalker(org.alfresco.rest.workflow.api.impl.MapBasedQueryWalker) ResultSet(org.alfresco.service.cmr.search.ResultSet) QuickShareLink(org.alfresco.rest.api.model.QuickShareLink) QueryParameterDefinition(org.alfresco.service.cmr.search.QueryParameterDefinition)

Example 32 with PagingRequest

use of org.alfresco.query.PagingRequest 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 33 with PagingRequest

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

the class Util method wrapPagingResults.

public static <T> PagingResults<T> wrapPagingResults(Paging paging, Collection<T> result) {
    if (paging == null) {
        throw new InvalidArgumentException("paging object can't be null.");
    }
    if (result == null) {
        result = Collections.emptyList();
    }
    PagingRequest pagingRequest = getPagingRequest(paging);
    final int totalSize = result.size();
    final PageDetails pageDetails = PageDetails.getPageDetails(pagingRequest, totalSize);
    final List<T> page = new ArrayList<>(pageDetails.getPageSize());
    Iterator<T> it = result.iterator();
    for (int counter = 0, end = pageDetails.getEnd(); counter < end && it.hasNext(); counter++) {
        T element = it.next();
        if (counter < pageDetails.getSkipCount()) {
            continue;
        }
        if (counter > end - 1) {
            break;
        }
        page.add(element);
    }
    return new PagingResults<T>() {

        @Override
        public List<T> getPage() {
            return page;
        }

        @Override
        public boolean hasMoreItems() {
            return pageDetails.hasMoreItems();
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount() {
            Integer total = totalSize;
            return new Pair<>(total, total);
        }

        @Override
        public String getQueryExecutionId() {
            return null;
        }
    };
}
Also used : InvalidArgumentException(org.alfresco.rest.framework.core.exceptions.InvalidArgumentException) PagingResults(org.alfresco.query.PagingResults) ArrayList(java.util.ArrayList) PagingRequest(org.alfresco.query.PagingRequest) CannedQueryPageDetails(org.alfresco.query.CannedQueryPageDetails) PageDetails(org.alfresco.query.PageDetails) Pair(org.alfresco.util.Pair)

Example 34 with PagingRequest

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

the class ForumTopicsHotGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // They shouldn't be trying to list of an existing Post or Topic
    if (topic != null || post != null) {
        String error = "Can't list Topics inside an existing Topic or Post";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    // Grab the date range to search over
    String numDaysS = req.getParameter("numdays");
    int numDays = RECENT_POSTS_PERIOD_DAYS;
    if (numDaysS != null) {
        numDays = Integer.parseInt(numDaysS);
    }
    Date now = new Date();
    Date since = new Date(now.getTime() - numDays * ONE_DAY_MS);
    // Get the topics with recent replies
    PagingResults<Pair<TopicInfo, Integer>> topicsAndCounts = null;
    PagingRequest paging = buildPagingRequest(req);
    if (site != null) {
        topicsAndCounts = discussionService.listHotTopics(site.getShortName(), since, paging);
    } else {
        topicsAndCounts = discussionService.listHotTopics(nodeRef, since, paging);
    }
    // For this, we actually only need the topics, not their counts too
    List<TopicInfo> topics = new ArrayList<TopicInfo>();
    for (Pair<TopicInfo, Integer> tc : topicsAndCounts.getPage()) {
        topics.add(tc.getFirst());
    }
    // been created yet, use the site for the permissions checking
    if (site != null && nodeRef == null) {
        nodeRef = site.getNodeRef();
    }
    // Build the common model parts
    Map<String, Object> model = buildCommonModel(site, topic, post, req);
    model.put("forum", nodeRef);
    // Have the topics rendered
    model.put("data", renderTopics(topics, topicsAndCounts.getTotalResultCount(), paging, site));
    // All done
    return model;
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) PagingRequest(org.alfresco.query.PagingRequest) TopicInfo(org.alfresco.service.cmr.discussion.TopicInfo) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.simple.JSONObject) Pair(org.alfresco.util.Pair)

Example 35 with PagingRequest

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

the class ForumTopicsMineGet method executeImpl.

@Override
protected Map<String, Object> executeImpl(SiteInfo site, NodeRef nodeRef, TopicInfo topic, PostInfo post, WebScriptRequest req, JSONObject json, Status status, Cache cache) {
    // They shouldn't be trying to list of an existing Post or Topic
    if (topic != null || post != null) {
        String error = "Can't list Topics inside an existing Topic or Post";
        throw new WebScriptException(Status.STATUS_BAD_REQUEST, error);
    }
    // Grab the current user to list for
    String username = AuthenticationUtil.getFullyAuthenticatedUser();
    // Get the topics for the user, oldest first
    PagingResults<TopicInfo> topics = null;
    PagingRequest paging = buildPagingRequest(req);
    if (site != null) {
        topics = discussionService.listTopics(site.getShortName(), username, true, paging);
    } else {
        topics = discussionService.listTopics(nodeRef, username, true, paging);
    }
    // been created yet, use the site for the permissions checking
    if (site != null && nodeRef == null) {
        nodeRef = site.getNodeRef();
    }
    // Build the common model parts
    Map<String, Object> model = buildCommonModel(site, topic, post, req);
    model.put("forum", nodeRef);
    // Have the topics rendered
    model.put("data", renderTopics(topics, paging, site));
    // All done
    return model;
}
Also used : WebScriptException(org.springframework.extensions.webscripts.WebScriptException) JSONObject(org.json.simple.JSONObject) TopicInfo(org.alfresco.service.cmr.discussion.TopicInfo) PagingRequest(org.alfresco.query.PagingRequest)

Aggregations

PagingRequest (org.alfresco.query.PagingRequest)36 ArrayList (java.util.ArrayList)18 Pair (org.alfresco.util.Pair)12 NodeRef (org.alfresco.service.cmr.repository.NodeRef)11 HashMap (java.util.HashMap)10 JSONObject (org.json.simple.JSONObject)10 Paging (org.alfresco.rest.framework.resource.parameters.Paging)8 Map (java.util.Map)7 Date (java.util.Date)6 UserTransaction (javax.transaction.UserTransaction)6 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)6 AbstractList (java.util.AbstractList)5 FacesContext (javax.faces.context.FacesContext)5 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)5 TopicInfo (org.alfresco.service.cmr.discussion.TopicInfo)5 PersonInfo (org.alfresco.service.cmr.security.PersonService.PersonInfo)5 AccessDeniedException (org.alfresco.repo.security.permissions.AccessDeniedException)4 SiteInfo (org.alfresco.service.cmr.site.SiteInfo)4 HashSet (java.util.HashSet)3 List (java.util.List)3