Java Code Examples for org.alfresco.query.PagingResults#hasMoreItems()

The following examples show how to use org.alfresco.query.PagingResults#hasMoreItems() . 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: CopyServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<NodeRef> getCopies(NodeRef nodeRef)
{
    PagingRequest pagingRequest = new PagingRequest(1000);
    PagingResults<CopyInfo> page = getCopies(nodeRef, pagingRequest);
    if (page.hasMoreItems())
    {
        logger.warn("Trimmed page size for deprecated getCopies() call.");
    }
    List<CopyInfo> pageResults = page.getPage();
    List<NodeRef> results = new ArrayList<NodeRef>(pageResults.size());
    for (CopyInfo copyInfo : pageResults)
    {
        results.add(copyInfo.getNodeRef());
    }
    return results;
}
 
Example 2
Source File: GetChildrenCannedQueryTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testMaxItems() throws Exception
{
    NodeRef parentNodeRef = getOrCreateParentTestFolder("GetChildrenCannedQueryTest-"+TEST_RUN_ID);
    
    PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0);
    assertFalse(results.hasMoreItems());
    
    int totalCnt = results.getPage().size();
    assertTrue(totalCnt > 3);
    
    for (int i = 1; i <= totalCnt; i++)
    {
        results = list(parentNodeRef, 0, i, 0);
        assertEquals(results.getPage().size(), i);
        
        boolean hasMore = results.hasMoreItems();
        assertTrue(hasMore == (i != totalCnt));
        
        if (logger.isInfoEnabled())
        {
            logger.info("testSimpleMaxItems: [itemCnt="+i+",hasMore="+hasMore+"]");
        }
    }
}
 
Example 3
Source File: MLTranslationInterceptor.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 4
Source File: AuthorityDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 5
Source File: CalendarAllDayEventDatesCorrectingPatch.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected String applyInternal() throws Exception
{
    int updatedEventsAmount = 0;

    NodeRef siteRoot = siteService.getSiteRoot();

    if (LOGGER.isDebugEnabled())
    {
        LOGGER.debug("Site root: " + siteRoot);
    }

    List<ChildAssociationRef> allSites = (null != siteRoot) ? (nodeService.getChildAssocs(siteRoot)) : (null);

    if ((null != allSites) && !allSites.isEmpty())
    {
        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Starting processing of " + allSites.size() + " sites...");
        }

        PagingResults<CalendarEntry> entries = null;
        String queryId = null;

        int maxItems = (batchEnabled) ? (batchSize) : (Integer.MAX_VALUE);

        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Batching info:\n\t- batching enabled: " + batchEnabled + ";\n\t-batch size: " + batchSize);
        }

        for (ChildAssociationRef siteAssoc : allSites)
        {
            SiteInfo site = siteService.getSite(siteAssoc.getChildRef());

            if (null != site)
            {
                int skipCount = 0;

                if (LOGGER.isDebugEnabled())
                {
                    LOGGER.debug("Processing a site: [short name: " + site.getShortName() + ", title: " + site.getTitle() + ", visibility: " + site.getVisibility() + "]");
                }

                do
                {
                    PagingRequest paging = new PagingRequest(skipCount, maxItems, queryId);
                    entries = calendarService.listCalendarEntries(site.getShortName(), paging);

                    List<CalendarEntry> page = (null != entries) ? (entries.getPage()) : (null);

                    if (null != page)
                    {
                        if (LOGGER.isDebugEnabled())
                        {
                            LOGGER.debug("Processing " + page.size() + " Calendar Events...");
                        }

                        queryId = entries.getQueryExecutionId();

                        for (CalendarEntry entry : page)
                        {
                            if (isAllDay(entry))
                            {
                                updatedEventsAmount++;

                                if (LOGGER.isDebugEnabled())
                                {
                                    LOGGER.debug("'All Day' Calendar event has been detected: [title: " + entry.getTitle() + ", start: " + entry.getStart() + ", end: "
                                            + entry.getEnd() + ", isOutlook: " + entry.isOutlook() + "]");
                                }

                                nodeService.setProperty(entry.getNodeRef(), CalendarModel.PROP_TO_DATE, adjustOldDate(entry.getEnd()));
                                nodeService.setProperty(entry.getNodeRef(), CalendarModel.PROP_FROM_DATE, adjustOldDate(entry.getStart()));
                            }
                        }

                        skipCount += maxItems;
                    }
                } while (batchEnabled && entries.hasMoreItems());
            }
            else
            {
                if (LOGGER.isDebugEnabled())
                {
                    LOGGER.debug("Not site object has been detected. Skipping...");
                }
            }
        }
    }
    else
    {
        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("No one site has been found! Skipping patch execution...");
        }
    }

    return I18NUtil.getMessage(MSG_SUCCESS, updatedEventsAmount);
}
 
Example 6
Source File: CalendarServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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 7
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @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 8
Source File: VirtualFileFolderServiceExtension.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 9
Source File: PageCollator.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 10
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 11
Source File: GetChildrenCannedQueryTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testPaging() throws Exception
{
    NodeRef parentNodeRef = getOrCreateParentTestFolder("GetChildrenCannedQueryTest-"+TEST_RUN_ID);
    
    PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0);
    assertFalse(results.hasMoreItems());
    
    int totalCnt = results.getPage().size();
    int pageSize = 3;
    assertTrue(totalCnt > pageSize);
    
    int pageCnt = totalCnt / pageSize;
    if ((totalCnt % pageSize) != 0)
    {
        // round-up
        pageCnt++;
    }
    assertTrue(pageCnt > 1);
    
    if (logger.isInfoEnabled())
    {
        logger.info("testSimplePaging: [totalCount="+totalCnt+",pageSize="+pageSize+",pageCount="+pageCnt+"]");
    }
    
    for (int i = 1; i <= pageCnt; i++)
    {
        int skipCount = ((i - 1)* pageSize);
        int maxItems = pageSize;
        
        results = list(parentNodeRef, skipCount, maxItems, 0);
        
        boolean hasMore = results.hasMoreItems();
        int itemsCnt = results.getPage().size();
        
        if (logger.isInfoEnabled())
        {
            logger.info("testSimplePaging:     [pageNum="+i+",itemCnt="+itemsCnt+",hasMore="+hasMore+"]");
        }
        
        if (i != pageCnt)
        {
            // not last page
            assertEquals(itemsCnt, maxItems);
            assertTrue(hasMore);
        }
        else
        {
            // last page
            assertTrue(itemsCnt <= maxItems);
            assertFalse(hasMore);
        }
    }
}
 
Example 12
Source File: GetChildrenCannedQueryTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testPagingGetChildrenCannedQueryWithoutProps() throws Exception
{
    try
    {
        long startTime = System.currentTimeMillis();

        int itemCount = 1500;
        int repeatListCount = 5;

        Set<QName> assocTypeQNames = new HashSet<>(1);
        assocTypeQNames.add(ContentModel.ASSOC_CONTAINS);

        Set<QName> childTypeQNames = new HashSet<>(1);
        childTypeQNames.add(ContentModel.TYPE_FOLDER);

        AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

        NodeRef testFolder = repositoryHelper.getCompanyHome();

        NodeRef parentFolder = createFolder(testFolder, "testCreateList-"+ GUID.generate(), ContentModel.TYPE_FOLDER);

        for (int i = 1; i <= itemCount; i++)
        {
            String folderName = "folder_" + GUID.generate();
            createFolder(parentFolder, folderName, ContentModel.TYPE_FOLDER);
        }

        for (int j = 1; j <= repeatListCount; j++)
        {
            // page/iterate through the children
            boolean hasMore = true;
            int skipCount = 0;
            int maxItems = 100;

            int count = 0;
            Set<String> docIds = new HashSet<>(itemCount);

            while (hasMore)
            {
                // note: mimic similar to AlfrescoServiceCmisServiceImpl
                PagingResults<NodeRef> results = list(parentFolder, skipCount, maxItems, skipCount + 10000, assocTypeQNames, childTypeQNames, null, null, null, null);
                hasMore = results.hasMoreItems();
                skipCount = skipCount + maxItems;

                for (NodeRef nodeRef : results.getPage())
                {
                    docIds.add(nodeRef.getId());
                    count++;
                }
            }

            assertEquals(itemCount, count);
            assertEquals(itemCount, docIds.size());
        }

        System.out.println("Test time: " + (System.currentTimeMillis() - startTime) + " ms");
    } 
    finally
    {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 13
Source File: SitesImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
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;
        }
    };
}