Java Code Examples for org.alfresco.query.PagingResults#getTotalResultCount()
The following examples show how to use
org.alfresco.query.PagingResults#getTotalResultCount() .
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: MLTranslationInterceptor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private PagingResults<FileInfo> processPagingResults(final PagingResults<FileInfo> fileInfos) { final List<FileInfo> orderedResults = processList(fileInfos.getPage()); PagingResults<FileInfo> orderedPagingResults = new PagingResults<FileInfo>() { @Override public String getQueryExecutionId() { return fileInfos.getQueryExecutionId(); } @Override public List<FileInfo> getPage() { return orderedResults; } @Override public boolean hasMoreItems() { return fileInfos.hasMoreItems(); } @Override public Pair<Integer, Integer> getTotalResultCount() { return fileInfos.getTotalResultCount(); } }; return orderedPagingResults; }
Example 2
Source File: FavouritesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
private CollectionWithPagingInfo<Favourite> wrap(Paging paging, PagingResults<PersonFavourite> personFavourites, Parameters parameters) { final List<PersonFavourite> page = personFavourites.getPage(); final List<Favourite> list = new AbstractList<Favourite>() { @Override public Favourite get(int index) { PersonFavourite personFavourite = page.get(index); Favourite fav = getFavourite(personFavourite, parameters); return fav; } @Override public int size() { return page.size(); } }; Pair<Integer, Integer> pair = personFavourites.getTotalResultCount(); Integer total = null; if(pair.getFirst().equals(pair.getSecond())) { total = pair.getFirst(); } return CollectionWithPagingInfo.asPaged(paging, list, personFavourites.hasMoreItems(), total); }
Example 3
Source File: AuthorityDAOImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private PagingResults<String> getUserAuthoritiesImpl(String displayNameFilter, boolean sortByDisplayName, boolean sortAscending, PagingRequest pagingRequest) { List<Pair<QName,String>> filter = null; if (displayNameFilter != null) { filter = new ArrayList<Pair<QName,String>>(); filter.add(new Pair<QName, String>(ContentModel.PROP_USERNAME, displayNameFilter)); } List<Pair<QName,Boolean>> sort = null; if (sortByDisplayName) { sort = new ArrayList<Pair<QName,Boolean>>(); sort.add(new Pair<QName, Boolean>(ContentModel.PROP_USERNAME, sortAscending)); } final PagingResults<PersonInfo> ppr = personService.getPeople(filter, true, sort, pagingRequest); List<PersonInfo> result = ppr.getPage(); final List<String> auths = new ArrayList<String>(result.size()); for (PersonInfo person : result) { auths.add(getPooledName(person.getUserName())); } return new PagingResults<String>() { @Override public String getQueryExecutionId() { return ppr.getQueryExecutionId(); } @Override public List<String> getPage() { return auths; } @Override public boolean hasMoreItems() { return ppr.hasMoreItems(); } @Override public Pair<Integer, Integer> getTotalResultCount() { return ppr.getTotalResultCount(); } }; }
Example 4
Source File: CalendarServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Our class to wrap up paged results of NodeRefs as * CalendarEntry instances */ private PagingResults<CalendarEntry> wrap(final PagingResults<NodeRef> results, final NodeRef container) { // Pre-load the nodes before we create them nodeDAO.cacheNodes(results.getPage()); // Wrap return new PagingResults<CalendarEntry>() { @Override public String getQueryExecutionId() { return results.getQueryExecutionId(); } @Override public List<CalendarEntry> getPage() { List<CalendarEntry> entries = new ArrayList<CalendarEntry>(); for(NodeRef nodeRef : results.getPage()) { String entryName = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); CalendarEntryImpl entry = new CalendarEntryImpl(nodeRef, container, entryName); entry.populate(nodeService.getProperties(nodeRef)); entry.setTags(taggingService.getTags(nodeRef)); entries.add(entry); } return entries; } @Override public boolean hasMoreItems() { return results.hasMoreItems(); } @Override public Pair<Integer, Integer> getTotalResultCount() { return results.getTotalResultCount(); } }; }
Example 5
Source File: TaggingServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * @see org.alfresco.service.cmr.tagging.TaggingService#getTags(org.alfresco.service.cmr.repository.StoreRef, org.alfresco.query.PagingRequest) */ public PagingResults<Pair<NodeRef, String>> getTags(StoreRef storeRef, PagingRequest pagingRequest) { ParameterCheck.mandatory("storeRef", storeRef); PagingResults<ChildAssociationRef> rootCategories = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, pagingRequest, true); final List<Pair<NodeRef, String>> result = new ArrayList<Pair<NodeRef, String>>(rootCategories.getPage().size()); for (ChildAssociationRef rootCategory : rootCategories.getPage()) { String name = (String)this.nodeService.getProperty(rootCategory.getChildRef(), ContentModel.PROP_NAME); result.add(new Pair<NodeRef, String>(rootCategory.getChildRef(), name)); } final boolean hasMoreItems = rootCategories.hasMoreItems(); final Pair<Integer, Integer> totalResultCount = rootCategories.getTotalResultCount(); final String queryExecutionId = rootCategories.getQueryExecutionId(); rootCategories = null; return new PagingResults<Pair<NodeRef, String>>() { @Override public List<Pair<NodeRef, String>> getPage() { return result; } @Override public boolean hasMoreItems() { return hasMoreItems; } @Override public Pair<Integer, Integer> getTotalResultCount() { return totalResultCount; } @Override public String getQueryExecutionId() { return queryExecutionId; } }; }
Example 6
Source File: VirtualFileFolderServiceExtension.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public PagingResults<FileInfo> asFileInfoResults(ActualEnvironment environment, final PagingResults<Reference> results, VirtualStore store) throws ReferenceEncodingException, VirtualizationException { List<Reference> virtualPage = results.getPage(); final LinkedList<FileInfo> page = new LinkedList<FileInfo>(); for (Reference ref : virtualPage) { FileInfo fileInfo = asFileInfo(store, environment, ref); page.add(fileInfo); } final boolean hasMoreItems = results.hasMoreItems(); final Pair<Integer, Integer> totalResultCount = results.getTotalResultCount(); final String queryExecutionId = results.getQueryExecutionId(); return new PagingResults<FileInfo>() { @Override public List<FileInfo> getPage() { return page; } @Override public String getQueryExecutionId() { return queryExecutionId; } @Override public Pair<Integer, Integer> getTotalResultCount() { return totalResultCount; } @Override public boolean hasMoreItems() { return hasMoreItems; } }; }
Example 7
Source File: PageCollator.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private PagingResults<R> collate(List<R> objects, final PagingResults<R> objectPageSurce, int pageSkip, final PagingRequest pagingRequest, Comparator<R> comparator) { final int pageSize = pagingRequest.getMaxItems(); final List<R> inPageList = objectPageSurce.getPage(); final List<R> collatedPageList = new LinkedList<>(); final boolean endOfCollation = collate(objects, inPageList, pageSkip, pageSize, comparator, collatedPageList); final int resultsSize = objects.size(); final Pair<Integer, Integer> pageTotal = objectPageSurce.getTotalResultCount(); Integer pageTotalFirst = null; Integer pageTotalSecond = null; if (pageTotal != null) { pageTotalFirst = pageTotal.getFirst(); pageTotalSecond = pageTotal.getSecond(); } final Pair<Integer, Integer> total = new Pair<>(pageTotalFirst == null ? null : pageTotalFirst + resultsSize, pageTotalSecond == null ? null : pageTotalSecond + resultsSize); final boolean hasMoreItems = objectPageSurce.hasMoreItems() || !endOfCollation; return new PagingResults<R>() { @Override public List<R> getPage() { return collatedPageList; } @Override public boolean hasMoreItems() { return hasMoreItems; } @Override public Pair<Integer, Integer> getTotalResultCount() { return total; } @Override public String getQueryExecutionId() { return pagingRequest.getQueryExecutionId(); } }; }
Example 8
Source File: ScriptNode.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@SuppressWarnings("unchecked") /** * @param files Return files extending from cm:content * @param folders Return folders extending from cm:folder - ignoring sub-types of cm:systemfolder * @param ignoreTypes Also optionally removes additional type qnames. The additional type can be * specified in short or long qname string form as a single string or an Array e.g. "fm:forum". * @param skipOffset Items to skip (e.g. 0 or (num pages to skip * size of page) * @param maxItems Max number of items (eg. size of page) * @param requestTotalCountMax Request total count (upto a given max total count) * Note: if 0 then total count is not requested and the query may be able to optimise/cutoff for max items) * @param sortProp Optional sort property as a prefix qname string (e.g. "cm:name"). Also supports special * content case (i.e. "cm:content.size" and "cm:content.mimetype") * @param sortAsc Given a sort property, true => ascending, false => descending * @param queryExecutionId If paging then can pass back the previous query execution (as a hint for possible query optimisation) * * @return Returns ScriptPagingNodes which includes a JavaScript array of child file/folder nodes for this nodes. * Automatically retrieves all sub-types of cm:content and cm:folder, also removes * system folder types from the results. * This is equivalent to @see FileFolderService.listFiles() and @see FileFolderService.listFolders() * * <br/><br/>author janv * @since 4.0 */ public ScriptPagingNodes childFileFolders(boolean files, boolean folders, Object ignoreTypes, int skipOffset, int maxItems, int requestTotalCountMax, String sortProp, Boolean sortAsc, String queryExecutionId) { Object[] results; Set<QName> ignoreTypeQNames = new HashSet<QName>(5); // Add user defined types to ignore if (ignoreTypes instanceof ScriptableObject) { Serializable types = getValueConverter().convertValueForRepo((ScriptableObject)ignoreTypes); if (types instanceof List) { for (Serializable typeObj : (List<Serializable>)types) { ignoreTypeQNames.add(createQName(typeObj.toString())); } } else if (types instanceof String) { ignoreTypeQNames.add(createQName(types.toString())); } } else if (ignoreTypes instanceof String) { ignoreTypeQNames.add(createQName(ignoreTypes.toString())); } // ALF-13968 - sort folders before files (for Share) - TODO should be optional sort param List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(2); if ((sortProp == null) || (! sortProp.equals(GetChildrenCannedQuery.SORT_QNAME_NODE_TYPE.getLocalName()))) { sortProps.add(new Pair<QName, Boolean>(GetChildrenCannedQuery.SORT_QNAME_NODE_IS_FOLDER, false)); } if (sortProp != null) { sortProps.add(new Pair<QName, Boolean>(createQName(sortProp), sortAsc)); } PagingRequest pageRequest = new PagingRequest(skipOffset, maxItems, queryExecutionId); pageRequest.setRequestTotalCountMax(requestTotalCountMax); PagingResults<FileInfo> pageOfNodeInfos = null; FileFilterMode.setClient(Client.script); try { pageOfNodeInfos = this.fileFolderService.list(this.nodeRef, files, folders, null, ignoreTypeQNames, sortProps, pageRequest); } finally { FileFilterMode.clearClient(); } List<FileInfo> nodeInfos = pageOfNodeInfos.getPage(); int size = nodeInfos.size(); results = new Object[size]; for (int i=0; i<size; i++) { FileInfo nodeInfo = nodeInfos.get(i); results[i] = newInstance(nodeInfo, this.services, this.scope); } int totalResultCountLower = -1; int totalResultCountUpper = -1; Pair<Integer, Integer> totalResultCount = pageOfNodeInfos.getTotalResultCount(); if (totalResultCount != null) { totalResultCountLower = (totalResultCount.getFirst() != null ? totalResultCount.getFirst() : -1); totalResultCountUpper = (totalResultCount.getSecond() != null ? totalResultCount.getSecond() : -1); } return new ScriptPagingNodes(Context.getCurrentContext().newArray(this.scope, results), pageOfNodeInfos.hasMoreItems(), totalResultCountLower, totalResultCountUpper); }
Example 9
Source File: ScriptPagingDetails.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Records the total number of results found, and the confidence * in this, from the Paging Results * @param results The PagingResults to extract the information from */ public <R> void setTotalItems(PagingResults<R> results) { if(results.getTotalResultCount() == null) { // No count calculated this.totalItems = -1; this.confidence = ItemsSizeConfidence.UNKNOWN; } else { // Get the total count and confidence Integer min = results.getTotalResultCount().getFirst(); Integer max = results.getTotalResultCount().getSecond(); if(min == null) { this.totalItems = -1; this.confidence = ItemsSizeConfidence.UNKNOWN; } else if(max == null) { this.totalItems = min; this.confidence = ItemsSizeConfidence.AT_LEAST; } else if(min.equals(max)) { this.totalItems = min; this.confidence = ItemsSizeConfidence.EXACT; } else { this.totalItems = min; this.totalItemsRangeMax = max; this.confidence = ItemsSizeConfidence.RANGE; } } // Finally record the query execution ID setQueryExecutionId(results.getQueryExecutionId()); }
Example 10
Source File: FileFolderServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
public void testList_HiddenFiles() { // Test that hidden files are not returned for clients that should not be able to see them, // and that the total result count is correct. Client saveClient = FileFilterMode.setClient(Client.webdav); try { // create some hidden files NodeRef nodeRef = fileFolderService.create(workingRootNodeRef, "" + System.currentTimeMillis(), ContentModel.TYPE_CONTENT).getNodeRef(); NodeRef nodeRef1 = fileFolderService.create(nodeRef, "parent", ContentModel.TYPE_CONTENT).getNodeRef(); for(int i = 0; i < 10; i++) { fileFolderService.create(nodeRef1, ".child" + i, ContentModel.TYPE_CONTENT).getNodeRef(); } // and some visible files for(int i = 0; i < 10; i++) { fileFolderService.create(nodeRef1, "visiblechild" + i, ContentModel.TYPE_CONTENT).getNodeRef(); } // switch to a client that should not see the hidden files saveClient = FileFilterMode.setClient(Client.cmis); PagingRequest pagingRequest = new PagingRequest(0, Integer.MAX_VALUE); pagingRequest.setRequestTotalCountMax(10000); // need this so that total count is set PagingResults<FileInfo> results = fileFolderService.list(nodeRef1, true, true, null, null, pagingRequest); Pair<Integer, Integer> totalResultCount = results.getTotalResultCount(); assertNotNull(totalResultCount.getFirst()); assertEquals("Total result lower count should be 10", 10, totalResultCount.getFirst().intValue()); assertNotNull(totalResultCount.getSecond()); assertEquals("Total result upper count should be 10", 10, totalResultCount.getSecond().intValue()); for(FileInfo fileInfo : results.getPage()) { assertTrue(fileInfo.getName().startsWith("visiblechild")); } assertEquals("Expected only 10 results", 10, results.getPage().size()); } finally { FileFilterMode.setClient(saveClient); } }
Example 11
Source File: FileFolderServiceImplTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private void checkPages(NodeRef parentRef, int pageSize, int totalItems, boolean hideCheckedOut, int checkedOutChildIdx) { Set<QName> ignoreQNameTypes = null; if (hideCheckedOut) { ignoreQNameTypes = new HashSet<QName>(1); ignoreQNameTypes.add(ContentModel.ASPECT_CHECKED_OUT); } else { if (checkedOutChildIdx > -1) { totalItems++; } } List<Pair<QName, Boolean>> sortProps = new ArrayList<Pair<QName, Boolean>>(1); sortProps.add(new Pair<QName, Boolean>(ContentModel.PROP_NAME, true)); int pageCount = (totalItems / pageSize) + 1; for (int i = 1; i <= pageCount; i++) { int offset = (i-1)*pageSize; PagingRequest pagingRequest = new PagingRequest(offset, pageSize); pagingRequest.setRequestTotalCountMax(10000); // need this so that total count is set PagingResults<FileInfo> results = fileFolderService.list(parentRef, true, true, ignoreQNameTypes, sortProps, pagingRequest); Pair<Integer, Integer> totalResultCount = results.getTotalResultCount(); assertNotNull(totalResultCount.getFirst()); assertEquals(totalItems, totalResultCount.getFirst().intValue()); assertNotNull(totalResultCount.getSecond()); assertEquals(totalItems, totalResultCount.getSecond().intValue()); assertEquals((i != pageCount ? pageSize : (totalItems - ((pageCount-1)*pageSize))), results.getPage().size()); int j = offset; for (FileInfo fileInfo : results.getPage()) { String suffix = String.format("%05d", j); if (checkedOutChildIdx > -1) { if (! hideCheckedOut) { if (j == checkedOutChildIdx+1) { suffix = String.format("%05d", j-1) + " (Working Copy)"; } else if (j > checkedOutChildIdx+1) { suffix = String.format("%05d", j-1); } } else { if (j == checkedOutChildIdx) { suffix = String.format("%05d", j) + " (Working Copy)"; } } } String actual = fileInfo.getName(); String expected = "child-"+suffix; assertTrue("Expected: "+expected+", Actual: "+actual+" (j="+j+")", expected.equals(actual)); j++; } } }
Example 12
Source File: AbstractGetBlogWebScript.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
protected void createFtlModel(WebScriptRequest req, Map<String, Object> model, NodeRef node, PagingRequest pagingReq, PagingResults<BlogPostInfo> blogPostList) { Map<String, Object> blogPostsData = new HashMap<String, Object>(); final Pair<Integer, Integer> totalResultCount = blogPostList.getTotalResultCount(); int total = blogPostList.getPage().size(); if (totalResultCount != null && totalResultCount.getFirst() != null) { total = totalResultCount.getFirst(); } //FIXME What to do? null blogPostsData.put("total", total); blogPostsData.put("pageSize", pagingReq.getMaxItems()); blogPostsData.put("startIndex", pagingReq.getSkipCount()); blogPostsData.put("itemCount", blogPostList.getPage().size()); if (total == pagingReq.getRequestTotalCountMax()) { blogPostsData.put("totalRecordsUpper", true); } else { blogPostsData.put("totalRecordsUpper", false); } List<Map<String, Object>> blogPostDataSets = new ArrayList<Map<String, Object>>(blogPostList.getPage().size()); for (BlogPostInfo postInfo : blogPostList.getPage()) { Map<String, Object> data = BlogPostLibJs.getBlogPostData(postInfo.getNodeRef(), services); blogPostDataSets.add(data); } blogPostsData.put("items", blogPostDataSets); model.put("data", blogPostsData); // fetch the contentLength param String contentLengthStr = req.getParameter("contentLength"); int contentLength = contentLengthStr == null ? -1 : Integer.parseInt(contentLengthStr); model.put("contentLength", contentLength); // assign the blog node model.put("blog", node); model.put("externalBlogConfig", BlogPostLibJs.hasExternalBlogConfiguration(node, services)); }
Example 13
Source File: SitesImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
public PagingResults<SiteContainer> getSiteContainers(String siteId, Paging paging) { SiteInfo siteInfo = validateSite(siteId); if(siteInfo == null) { // site does not exist throw new EntityNotFoundException(siteId); } final PagingResults<FileInfo> pagingResults = siteService.listContainers(siteInfo.getShortName(), Util.getPagingRequest(paging)); List<FileInfo> containerFileInfos = pagingResults.getPage(); final List<SiteContainer> siteContainers = new ArrayList<SiteContainer>(containerFileInfos.size()); for(FileInfo containerFileInfo : containerFileInfos) { NodeRef nodeRef = containerFileInfo.getNodeRef(); String containerId = (String)nodeService.getProperty(nodeRef, SiteModel.PROP_COMPONENT_ID); SiteContainer siteContainer = new SiteContainer(containerId, nodeRef); siteContainers.add(siteContainer); } return new PagingResults<SiteContainer>() { @Override public List<SiteContainer> getPage() { return siteContainers; } @Override public boolean hasMoreItems() { return pagingResults.hasMoreItems(); } @Override public Pair<Integer, Integer> getTotalResultCount() { return pagingResults.getTotalResultCount(); } @Override public String getQueryExecutionId() { return null; } }; }