Java Code Examples for org.alfresco.query.PagingRequest#getSkipCount()
The following examples show how to use
org.alfresco.query.PagingRequest#getSkipCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SiteServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
public PagingResults<SiteMembership> listMembersPaged(String shortName, boolean collapseGroups, List<Pair<SiteService.SortFields, Boolean>> sortProps, PagingRequest pagingRequest) { CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems()); // sort details CannedQuerySortDetails sortDetails = null; if(sortProps != null) { List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(sortProps.size()); for (Pair<SiteService.SortFields, Boolean> sortProp : sortProps) { sortPairs.add(new Pair<SiteService.SortFields, SortOrder>(sortProp.getFirst(), (sortProp.getSecond() ? SortOrder.ASCENDING : SortOrder.DESCENDING))); } sortDetails = new CannedQuerySortDetails(sortPairs); } SiteMembersCannedQueryParams parameterBean = new SiteMembersCannedQueryParams(shortName, collapseGroups); CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId()); CannedQuery<SiteMembership> query = new SiteMembersCannedQuery(this, personService, nodeService, params); CannedQueryResults<SiteMembership> results = query.execute(); return getPagingResults(pagingRequest, results); }
Example 2
Source File: SiteServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") public PagingResults<FileInfo> listContainers(String shortName, PagingRequest pagingRequest) { SiteContainersCannedQueryFactory sitesContainersCannedQueryFactory = (SiteContainersCannedQueryFactory)cannedQueryRegistry.getNamedObject("siteContainersCannedQueryFactory"); CannedQueryPageDetails pageDetails = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems()); CannedQuerySortDetails sortDetails = new CannedQuerySortDetails(new Pair<Object, SortOrder>(SiteContainersCannedQueryParams.SortFields.ContainerName, SortOrder.ASCENDING)); SiteContainersCannedQueryParams parameterBean = new SiteContainersCannedQueryParams(getSiteNodeRef(shortName)); CannedQueryParameters params = new CannedQueryParameters(parameterBean, pageDetails, sortDetails, pagingRequest.getRequestTotalCountMax(), pagingRequest.getQueryExecutionId()); CannedQuery<FileInfo> query = sitesContainersCannedQueryFactory.getCannedQuery(params); CannedQueryResults<FileInfo> results = query.execute(); return getPagingResults(pagingRequest, results); }
Example 3
Source File: PageCollatorTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
@Override public PagingResults<R> retrieve(PagingRequest pr) throws PageCollationException { final int skip = pr.getSkipCount(); final int pageSize = pr.getMaxItems(); if (skip < 0 || pageSize < 0) { throw new PageCollationException("Invalid page!"); } if (boundsError && (skip >= array.length)) { throw new InvalidPageBounds("Out of bounds " + skip + ">=" + array.length); } return new ListBackedPagingResults<R>(Arrays.asList(array), pr); }
Example 4
Source File: GetNodesWithAspectCannedQueryFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Retrieve an unsorted instance of a {@link CannedQuery} based on parameters including * request for a total count (up to a given max) * * @param storeRef the store to search in, if requested * @param aspectQNames qnames of aspects to search for * @param pagingRequest skipCount, maxItems - optionally queryExecutionId and requestTotalCountMax * * @return an implementation that will execute the query */ public CannedQuery<NodeRef> getCannedQuery(StoreRef storeRef, Set<QName> aspectQNames, PagingRequest pagingRequest) { ParameterCheck.mandatory("aspectQNames", aspectQNames); ParameterCheck.mandatory("pagingRequest", pagingRequest); int requestTotalCountMax = pagingRequest.getRequestTotalCountMax(); // specific query params - context (parent) and inclusive filters (child types, property values) GetNodesWithAspectCannedQueryParams paramBean = new GetNodesWithAspectCannedQueryParams(storeRef, aspectQNames); // page details CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); // no sort details - no sorting done // create query params holder CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, null, requestTotalCountMax, pagingRequest.getQueryExecutionId()); // return canned query instance return getCannedQuery(params); }
Example 5
Source File: AuthorityDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private <T> PagingResults<T> getAuthoritiesImpl(AuthorityType type, NodeRef containerRef, String displayNameFilter, String sortBy, boolean sortAscending, PagingRequest pagingRequest, AbstractPagingResults<T> finalResults) { Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null); if (type != null) { switch (type) { case GROUP: case ROLE: case USER: // drop through break; default: throw new UnsupportedOperationException("Unexpected authority type: "+type); } } // get canned query GetAuthoritiesCannedQueryFactory getAuthoritiesCannedQueryFactory = (GetAuthoritiesCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_AUTHS_LIST); CannedQuery<AuthorityInfo> cq = getAuthoritiesCannedQueryFactory.getCannedQuery(type, containerRef, displayNameFilter, sortBy, sortAscending, pagingRequest); // execute canned query final CannedQueryResults<AuthorityInfo> results = cq.execute(); finalResults.setResults(results); if (start != null) { int cnt = finalResults.getPage().size(); int skipCount = pagingRequest.getSkipCount(); int maxItems = pagingRequest.getMaxItems(); boolean hasMoreItems = finalResults.hasMoreItems(); int pageNum = (skipCount / maxItems) + 1; logger.debug("getAuthoritiesByType: "+cnt+" items in "+(System.currentTimeMillis()-start)+" msecs [type="+type+",pageNum="+pageNum+",skip="+skipCount+",max="+maxItems+",hasMorePages="+hasMoreItems+",filter="+displayNameFilter+"]"); } return finalResults; }
Example 6
Source File: GetPeopleCannedQueryFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Retrieve an optionally filtered/sorted instance of a {@link CannedQuery} based on parameters including request for a total count (up to a given max) * * Note: if both filtering and sorting is required then the combined total of unique QName properties should be the 0 to 3. * * @param parentRef parent node ref * @param pattern the pattern to use to filter children (wildcard character is '*') * @param filterProps filter props * @param inclusiveAspects If not null, only child nodes with any aspect in this collection will be included in the results. * @param exclusiveAspects If not null, any child nodes with any aspect in this collection will be excluded in the results. * @param includeAdministrators include administrators in the returned results * @param sortProps sort property pairs (QName and Boolean - true if ascending) * @param pagingRequest skipCount, maxItems - optionally queryExecutionId and requestTotalCountMax * * @return an implementation that will execute the query */ public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, String pattern, List<QName> filterProps, Set<QName> inclusiveAspects, Set<QName> exclusiveAspects, boolean includeAdministrators, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest) { ParameterCheck.mandatory("parentRef", parentRef); ParameterCheck.mandatory("pagingRequest", pagingRequest); int requestTotalCountMax = pagingRequest.getRequestTotalCountMax(); // specific query params - context (parent) and inclusive filters (property values) GetPeopleCannedQueryParams paramBean = new GetPeopleCannedQueryParams(tenantService.getName(parentRef), filterProps, pattern, inclusiveAspects, exclusiveAspects, includeAdministrators); // page details CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); // sort details CannedQuerySortDetails cqsd = null; if (sortProps != null) { List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(sortProps.size()); for (Pair<QName, Boolean> sortProp : sortProps) { boolean sortAsc = ((sortProp.getSecond() == null) || sortProp.getSecond()); sortPairs.add(new Pair<QName, SortOrder>(sortProp.getFirst(), (sortAsc ? SortOrder.ASCENDING : SortOrder.DESCENDING))); } cqsd = new CannedQuerySortDetails(sortPairs); } // create query params holder CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingRequest.getQueryExecutionId()); // return canned query instance return getCannedQuery(params); }
Example 7
Source File: FileFolderServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private CannedQueryResults<NodeRef> listImpl(NodeRef contextNodeRef, String pattern, Set<QName> assocTypeQNames, Set<QName> searchTypeQNames, Set<QName> ignoreAspectQNames, List<Pair<QName, Boolean>> sortProps, List<FilterProp> filterProps, PagingRequest pagingRequest) { Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null); // get canned query GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_FILEFOLDER_LIST); GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(contextNodeRef, pattern, assocTypeQNames, searchTypeQNames, ignoreAspectQNames, filterProps, sortProps, pagingRequest); // execute canned query CannedQueryResults<NodeRef> results = cq.execute(); if (start != null) { int cnt = results.getPagedResultCount(); int skipCount = pagingRequest.getSkipCount(); int maxItems = pagingRequest.getMaxItems(); boolean hasMoreItems = results.hasMoreItems(); Pair<Integer, Integer> totalCount = (pagingRequest.getRequestTotalCountMax() > 0 ? results.getTotalResultCount() : null); int pageNum = (skipCount / maxItems) + 1; logger.debug("List: "+cnt+" items in "+(System.currentTimeMillis()-start)+" msecs [pageNum="+pageNum+",skip="+skipCount+",max="+maxItems+",hasMorePages="+hasMoreItems+",totalCount="+totalCount+",parentNodeRef="+contextNodeRef+"]"); } return results; }
Example 8
Source File: GetChildrenCannedQueryFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Retrieve an optionally filtered/sorted instance of a {@link CannedQuery} based on parameters including request for a total count (up to a given max) * * Note: if both filtering and sorting is required then the combined total of unique QName properties should be the 0 to 3. * * @param parentRef parent node ref * @param pattern the pattern to use to filter children (wildcard character is '*') * @param assocTypeQNames qnames of assocs to include (may be null) * @param childTypeQNames type qnames of children nodes (pre-filter) * @param inclusiveAspects If not null, only child nodes with any aspect in this collection will be included in the results. * @param exclusiveAspects If not null, any child nodes with any aspect in this collection will be excluded in the results. * @param filterProps filter properties * @param sortProps sort property pairs (QName and Boolean - true if ascending) * @param pagingRequest skipCount, maxItems - optionally queryExecutionId and requestTotalCountMax * * @return an implementation that will execute the query */ public CannedQuery<NodeRef> getCannedQuery(NodeRef parentRef, String pattern, Set<QName> assocTypeQNames, Set<QName> childTypeQNames, Set<QName> inclusiveAspects, Set<QName> exclusiveAspects, List<FilterProp> filterProps, List<Pair<QName, Boolean>> sortProps, PagingRequest pagingRequest) { ParameterCheck.mandatory("parentRef", parentRef); ParameterCheck.mandatory("pagingRequest", pagingRequest); int requestTotalCountMax = pagingRequest.getRequestTotalCountMax(); // specific query params - context (parent) and inclusive filters (child types, property values) GetChildrenCannedQueryParams paramBean = new GetChildrenCannedQueryParams(tenantService.getName(parentRef), assocTypeQNames, childTypeQNames, inclusiveAspects, exclusiveAspects, filterProps, pattern); // page details CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); // sort details CannedQuerySortDetails cqsd = null; if (sortProps != null) { List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(sortProps.size()); for (Pair<QName, Boolean> sortProp : sortProps) { sortPairs.add(new Pair<QName, SortOrder>(sortProp.getFirst(), (sortProp.getSecond() ? SortOrder.ASCENDING : SortOrder.DESCENDING))); } cqsd = new CannedQuerySortDetails(sortPairs); } // create query params holder CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingRequest.getQueryExecutionId()); // return canned query instance return getCannedQuery(params); }
Example 9
Source File: GetArchivedNodesCannedQueryFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * @param archiveStoreRootNodeRef NodeRef * @param assocTypeQName QName * @param filter String * @param filterIgnoreCase boolean * @param pagingRequest PagingRequest * @param sortOrderAscending boolean * @return an implementation that will execute the query */ public CannedQuery<ArchivedNodeEntity> getCannedQuery(NodeRef archiveStoreRootNodeRef, QName assocTypeQName, String filter, boolean filterIgnoreCase, PagingRequest pagingRequest, boolean sortOrderAscending) { ParameterCheck.mandatory("pagingRequest", pagingRequest); Long nodeId = (archiveStoreRootNodeRef == null) ? -1 : getNodeId(archiveStoreRootNodeRef); Long qnameId = (assocTypeQName == null) ? -1 : getQNameId(assocTypeQName); int requestTotalCountMax = pagingRequest.getRequestTotalCountMax(); GetArchivedNodesCannedQueryParams paramBean = new GetArchivedNodesCannedQueryParams(nodeId, qnameId, filter, filterIgnoreCase, getQNameId(ContentModel.PROP_NAME), sortOrderAscending); // page details CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); // create query params holder CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, null, requestTotalCountMax, pagingRequest.getQueryExecutionId()); // return canned query instance return getCannedQuery(params); }
Example 10
Source File: ScriptPagingDetails.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public ScriptPagingDetails(PagingRequest paging) { super(paging.getSkipCount(), paging.getMaxItems(), paging.getQueryExecutionId()); setRequestTotalCountMax(paging.getRequestTotalCountMax()); }
Example 11
Source File: GetAuthoritiesCannedQueryFactory.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public CannedQuery<AuthorityInfo> getCannedQuery(AuthorityType type, NodeRef containerRef, String displayNameFilter, String sortBy, boolean sortAscending, PagingRequest pagingRequest) { ParameterCheck.mandatory("containerRef", containerRef); ParameterCheck.mandatory("pagingRequest", pagingRequest); int requestTotalCountMax = pagingRequest.getRequestTotalCountMax(); Pair<Long, NodeRef> nodePair = nodeDAO.getNodePair(tenantService.getName(containerRef)); if (nodePair == null) { throw new InvalidNodeRefException("Container ref does not exist: " + containerRef, containerRef); } Long containerNodeId = nodePair.getFirst(); Long qnameAuthDisplayNameId = Long.MIN_VALUE; // We query but using a value that won't return results Pair<Long, QName> qnameAuthDisplayNamePair = qnameDAO.getQName(ContentModel.PROP_AUTHORITY_DISPLAY_NAME); if (qnameAuthDisplayNamePair != null) { qnameAuthDisplayNameId = qnameAuthDisplayNamePair.getFirst(); } // this can be null, in which case, there is no filtering on type, done at the database level Long typeQNameId = getQNameIdForType(type); // specific query params GetAuthoritiesCannedQueryParams paramBean = new GetAuthoritiesCannedQueryParams(type, typeQNameId, containerNodeId, qnameAuthDisplayNameId, displayNameFilter); // page details CannedQueryPageDetails cqpd = new CannedQueryPageDetails(pagingRequest.getSkipCount(), pagingRequest.getMaxItems(), CannedQueryPageDetails.DEFAULT_PAGE_NUMBER, CannedQueryPageDetails.DEFAULT_PAGE_COUNT); // sort details CannedQuerySortDetails cqsd = null; if (sortBy != null) { List<Pair<? extends Object, SortOrder>> sortPairs = new ArrayList<Pair<? extends Object, SortOrder>>(1); sortPairs.add(new Pair<String, SortOrder>(sortBy, (sortAscending ? SortOrder.ASCENDING : SortOrder.DESCENDING))); cqsd = new CannedQuerySortDetails(sortPairs); } // create query params holder CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingRequest.getQueryExecutionId()); // return canned query instance return getCannedQuery(params); }
Example 12
Source File: DiscussionServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public PagingResults<TopicInfo> findTopics(NodeRef nodeRef, String username, String tag, boolean sortAscending, PagingRequest paging) { // Build the query StringBuilder luceneQuery = new StringBuilder(); luceneQuery.append(" +TYPE:\"" + ForumModel.TYPE_TOPIC + "\""); luceneQuery.append(" +PATH:\"" + nodeService.getPath(nodeRef).toPrefixString(namespaceService) + "/*\""); if (username != null) { luceneQuery.append(" +@cm\\:creator:\"" + username + "\""); } if (tag != null) { luceneQuery.append(" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\"" ); } String sortOn = "@{http://www.alfresco.org/model/content/1.0}created"; // Query SearchParameters sp = new SearchParameters(); sp.addStore(nodeRef.getStoreRef()); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery(luceneQuery.toString()); sp.addSort(sortOn, sortAscending); if (paging.getSkipCount() > 0) { sp.setSkipCount(paging.getSkipCount()); } // Build the results PagingResults<TopicInfo> pagedResults = new EmptyPagingResults<TopicInfo>(); ResultSet results = null; try { results = searchService.query(sp); pagedResults = wrap(results, nodeRef, paging); } finally { if (results != null) { results.close(); } } return pagedResults; }
Example 13
Source File: ActivityFeedDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") private List<ActivityFeedEntity> filterByNetwork(String networkId, String siteId, String sql, ActivityFeedQueryEntity params, PagingRequest pagingRequest) { int expectedSkipCount = pagingRequest.getSkipCount(); // +1 to calculate hasMoreItems int expectedMaxItems = (pagingRequest.getMaxItems() == CannedQueryPageDetails.DEFAULT_PAGE_SIZE ? pagingRequest.getMaxItems() : pagingRequest.getMaxItems() + 1); int skipCount = 0; int maxItems = fetchBatchSize; List<ActivityFeedEntity> ret = new LinkedList<ActivityFeedEntity>(); int numMatchingItems = 0; int numAddedItems = 0; boolean skipping = true; List<ActivityFeedEntity> feedEntries = null; // fetch activities in batches of size "maxItems" // iterate through them, filtering out any that don't match the networkId do { RowBounds rowBounds = new RowBounds(skipCount, maxItems); feedEntries = template.selectList(sql, params, rowBounds); Iterator<ActivityFeedEntity> feedEntriesIt = feedEntries.iterator(); while(feedEntriesIt.hasNext() && numAddedItems < expectedMaxItems) { ActivityFeedEntity activityFeedEntry = feedEntriesIt.next(); if(siteId == null) { // note: pending requirements for THOR-224, for now assume all activities are within context of site and filter by current tenant if(!networkId.equals(tenantService.getDomain(activityFeedEntry.getSiteNetwork()))) { continue; } } numMatchingItems++; if(skipping) { if(numMatchingItems > expectedSkipCount) { skipping = false; } else { continue; } } ret.add(activityFeedEntry); numAddedItems++; } skipCount += feedEntries.size(); } while(feedEntries != null && feedEntries.size() > 0 && numAddedItems < expectedMaxItems); return ret; }
Example 14
Source File: NodeArchiveServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * {@inheritDoc} */ public PagingResults<NodeRef> listArchivedNodes(ArchivedNodesCannedQueryBuilder cannedQueryBuilder) { ParameterCheck.mandatory("cannedQueryBuilder", cannedQueryBuilder); Long start = (logger.isDebugEnabled() ? System.currentTimeMillis() : null); // get canned query GetArchivedNodesCannedQueryFactory getArchivedNodesCannedQueryFactory = (GetArchivedNodesCannedQueryFactory) cannedQueryRegistry .getNamedObject(CANNED_QUERY_ARCHIVED_NODES_LIST); Pair<NodeRef, QName> archiveNodeRefAssocTypePair = getArchiveNodeRefAssocTypePair(cannedQueryBuilder.getArchiveRootNodeRef()); GetArchivedNodesCannedQuery cq = (GetArchivedNodesCannedQuery) getArchivedNodesCannedQueryFactory .getCannedQuery(archiveNodeRefAssocTypePair.getFirst(), archiveNodeRefAssocTypePair.getSecond(), cannedQueryBuilder.getFilter(), cannedQueryBuilder.isFilterIgnoreCase(), cannedQueryBuilder.getPagingRequest(), cannedQueryBuilder.getSortOrderAscending()); // execute canned query final CannedQueryResults<ArchivedNodeEntity> results = ((CannedQuery<ArchivedNodeEntity>) cq).execute(); final List<ArchivedNodeEntity> page; if (results.getPageCount() > 0) { page = results.getPages().get(0); } else { page = Collections.emptyList(); } // set total count final Pair<Integer, Integer> totalCount; PagingRequest pagingRequest = cannedQueryBuilder.getPagingRequest(); if (pagingRequest.getRequestTotalCountMax() > 0) { totalCount = results.getTotalResultCount(); } else { totalCount = null; } if (start != null) { int skipCount = pagingRequest.getSkipCount(); int maxItems = pagingRequest.getMaxItems(); int pageNum = (skipCount / maxItems) + 1; if (logger.isDebugEnabled()) { StringBuilder sb = new StringBuilder(300); sb.append("listArchivedNodes: ").append(page.size()).append(" items in ") .append((System.currentTimeMillis() - start)).append("ms ") .append("[pageNum=").append(pageNum).append(", skip=").append(skipCount) .append(", max=").append(maxItems).append(", hasMorePages=") .append(results.hasMoreItems()).append(", totalCount=") .append(totalCount).append(", filter=") .append(cannedQueryBuilder.getFilter()).append(", sortOrderAscending=") .append(cannedQueryBuilder.getSortOrderAscending()).append("]"); logger.debug(sb.toString()); } } return new PagingResults<NodeRef>() { @Override public String getQueryExecutionId() { return results.getQueryExecutionId(); } @Override public List<NodeRef> getPage() { List<NodeRef> nodeRefs = new ArrayList<NodeRef>(page.size()); for (ArchivedNodeEntity entity : page) { nodeRefs.add(entity.getNodeRef()); } return nodeRefs; } @Override public boolean hasMoreItems() { return results.hasMoreItems(); } @Override public Pair<Integer, Integer> getTotalResultCount() { return totalCount; } }; }
Example 15
Source File: ForumTopicsFilteredGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * 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; }
Example 16
Source File: LinksServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public PagingResults<LinkInfo> findLinks(String siteShortName, String user, Date from, Date to, String tag, PagingRequest paging) { NodeRef container = getSiteLinksContainer(siteShortName, false); if (container == null) { // No links return new EmptyPagingResults<LinkInfo>(); } // Build the query StringBuilder luceneQuery = new StringBuilder(); luceneQuery.append(" +TYPE:\"" + LinksModel.TYPE_LINK + "\""); luceneQuery.append(" +PATH:\"" + nodeService.getPath(container).toPrefixString(namespaceService) + "/*\""); if (user != null) { luceneQuery.append(" +@cm\\:creator:\"" + user + "\""); } if (from != null && to != null) { luceneQuery.append(LuceneUtils.createDateRangeQuery( from, to, ContentModel.PROP_CREATED, dictionaryService, namespaceService)); } if (tag != null) { luceneQuery.append(" +PATH:\"/cm:taggable/cm:" + ISO9075.encode(tag) + "/member\""); } String sortOn = "@{http://www.alfresco.org/model/content/1.0}created"; // Query SearchParameters sp = new SearchParameters(); sp.addStore(container.getStoreRef()); sp.setLanguage(SearchService.LANGUAGE_LUCENE); sp.setQuery(luceneQuery.toString()); sp.addSort(sortOn, false); if (paging.getSkipCount() > 0) { sp.setSkipCount(paging.getSkipCount()); } // Build the results PagingResults<LinkInfo> pagedResults = new EmptyPagingResults<LinkInfo>(); ResultSet results = null; try { results = searchService.query(sp); pagedResults = wrap(results, container, paging); } finally { if (results != null) { results.close(); } } return pagedResults; }
Example 17
Source File: PageCollator.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @param objects * @param objectPageSurce * @param pagingRequest * @param comparator * @return a {@link PagingResults} R objects obtained from merging a * collection of R objects with a paged result obtained from a * {@link PagingResultsSource} considering the a merged result * {@link PagingRequest} * @throws PageCollationException */ public PagingResults<R> collate(List<R> objects, PagingResultsSource<R> objectPageSurce, PagingRequest pagingRequest, Comparator<R> comparator) throws PageCollationException { final int skip = pagingRequest.getSkipCount(); final int pageSize = pagingRequest.getMaxItems(); if (skip < 0 || pageSize < 0) { throw new InvalidPageBounds("Negative page skip index and/or bounds."); } int preemptiveSkip = Math.max(0, skip - objects.size()); int pageSkip = skip - preemptiveSkip; int preemptiveSize = pageSize + pageSkip; PagingResults<R> pageResults = null; try { PagingRequest preemptiveRequest = new PagingRequest(preemptiveSkip, preemptiveSize, pagingRequest.getQueryExecutionId()); preemptiveRequest.setRequestTotalCountMax(pagingRequest.getRequestTotalCountMax()); pageResults = objectPageSurce.retrieve(preemptiveRequest); } catch (InvalidPageBounds e) { if (logger.isDebugEnabled()) { logger.debug(e); } pageResults = new PagingResults<R>() { @Override public List<R> getPage() { return Collections.emptyList(); } @Override public boolean hasMoreItems() { return false; } @Override public Pair<Integer, Integer> getTotalResultCount() { return new Pair<Integer, Integer>(null, null); } @Override public String getQueryExecutionId() { return null; } }; } return collate(objects, pageResults, pageSkip, pagingRequest, comparator); }
Example 18
Source File: VirtualQueryImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private PagingResults<Reference> asPagingResults(ActualEnvironment environment, PagingRequest pagingRequest, ResultSet result, Reference parentReference) throws ActualEnvironmentException { final List<Reference> page = new LinkedList<Reference>(); for (ResultSetRow row : result) { page.add(NodeProtocol.newReference(row.getNodeRef(), parentReference)); } final boolean hasMore = result.hasMore(); final int totalFirst = (int) result.getNumberFound(); int start; try { start = result.getStart(); } catch (UnsupportedOperationException e) { if (logger.isDebugEnabled()) { logger.debug("Unsupported ResultSet.getStart() when trying to create query paging result"); } if (pagingRequest != null) { start = pagingRequest.getSkipCount(); } else { start = 0; } } final int totlaSecond = !hasMore ? (int) result.getNumberFound() : (int) (start + result.getNumberFound() + 1); final Pair<Integer, Integer> total = new Pair<Integer, Integer>(totalFirst, totlaSecond); return new PagingResults<Reference>() { @Override public List<Reference> getPage() { return page; } @Override public boolean hasMoreItems() { return hasMore; } @Override public Pair<Integer, Integer> getTotalResultCount() { return total; } @Override public String getQueryExecutionId() { return null; } }; }
Example 19
Source File: LuceneCategoryServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public PagingResults<ChildAssociationRef> getRootCategories(StoreRef storeRef, QName aspectName, PagingRequest pagingRequest, boolean sortByName, String filter) { final List<ChildAssociationRef> assocs = new LinkedList<ChildAssociationRef>(); Set<NodeRef> nodeRefs = getClassificationNodes(storeRef, aspectName); final int skipCount = pagingRequest.getSkipCount(); final int maxItems = pagingRequest.getMaxItems(); final int size = (maxItems == CannedQueryPageDetails.DEFAULT_PAGE_SIZE ? CannedQueryPageDetails.DEFAULT_PAGE_SIZE : skipCount + maxItems); int count = 0; boolean moreItems = false; OUTER: for(NodeRef nodeRef : nodeRefs) { Collection<ChildAssociationRef> children = getChildren(nodeRef, Mode.SUB_CATEGORIES, Depth.IMMEDIATE, sortByName, filter, skipCount + maxItems + 1); for(ChildAssociationRef child : children) { count++; if(count <= skipCount) { continue; } if(count > size) { moreItems = true; break OUTER; } assocs.add(child); } } final boolean hasMoreItems = moreItems; return new PagingResults<ChildAssociationRef>() { @Override public List<ChildAssociationRef> getPage() { return assocs; } @Override public boolean hasMoreItems() { return hasMoreItems; } @Override public Pair<Integer, Integer> getTotalResultCount() { return new Pair<Integer, Integer>(null, null); } @Override public String getQueryExecutionId() { return null; } }; }
Example 20
Source File: RemoteCredentialsServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * TODO This would probably be better done as a dedicated Canned Query * We want to filter by Assoc Type and Child Node Type, and the node service * currently only allows you to do one or the other */ private PagingResults<? extends BaseCredentialsInfo> listCredentials(NodeRef[] containers, String remoteSystem, QName credentialsType, PagingRequest paging) { // NodeService wants an exhaustive list of the types // Expand our single Credentials Type to cover all subtypes of it too Set<QName> types = null; if (credentialsType != null) { types = new HashSet<QName>( dictionaryService.getSubTypes(credentialsType, true) ); if (logger.isDebugEnabled()) logger.debug("Searching for credentials of " + credentialsType + " as types " + types); } // Find all the credentials List<ChildAssociationRef> credentials = new ArrayList<ChildAssociationRef>(); for (NodeRef nodeRef : containers) { if (nodeRef != null) { // Find the credentials in the node List<ChildAssociationRef> allCreds = nodeService.getChildAssocs( nodeRef, RemoteCredentialsModel.ASSOC_CREDENTIALS, RegexQNamePattern.MATCH_ALL); // Filter them by type, if needed if (types == null || types.isEmpty()) { // No type filtering needed credentials.addAll(allCreds); } else { // Check the type of each one, and add if it matches for (ChildAssociationRef ref : allCreds) { NodeRef credNodeRef = ref.getChildRef(); QName credType = nodeService.getType(credNodeRef); if (types.contains(credType)) { // Matching type, accept credentials.add(ref); } } } } } // Did we find any? if (credentials.isEmpty()) { return new EmptyPagingResults<BaseCredentialsInfo>(); } // Excerpt int start = paging.getSkipCount(); int end = Math.min(credentials.size(), start + paging.getMaxItems()); if (paging.getMaxItems() == 0) { end = credentials.size(); } boolean hasMore = (end < credentials.size()); List<ChildAssociationRef> wanted = credentials.subList(start, end); // Wrap and return return new CredentialsPagingResults(wanted, credentials.size(), hasMore, remoteSystem); }