Java Code Examples for org.alfresco.query.PagingRequest#getRequestTotalCountMax()

The following examples show how to use org.alfresco.query.PagingRequest#getRequestTotalCountMax() . 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: GetNodesWithAspectCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 2
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 3
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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 4
Source File: DocumentLinkServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<Long> getNodeLinksIds(NodeRef nodeRef)
{
    /* Validate input */
    PropertyCheck.mandatory(this, "nodeRef", nodeRef);

    /* Get all links of the given nodeRef */
    PagingRequest pagingRequest = new PagingRequest(0, 100000);
    List<Long> nodeLinks = new ArrayList<Long>();

    Pair<Long, QName> nameQName = qnameDAO.getQName(ContentModel.PROP_LINK_DESTINATION);
    if (nameQName != null)
    {
        // Execute the canned query if there are links in the database
        GetDoclinkNodesCannedQueryParams parameterBean = new GetDoclinkNodesCannedQueryParams(nodeRef.toString(), 
                                                                                              nameQName.getFirst(), 
                                                                                              pagingRequest.getMaxItems());
        CannedQueryParameters params = new CannedQueryParameters(parameterBean, 
                                                                 null, 
                                                                 null, 
                                                                 pagingRequest.getRequestTotalCountMax(), 
                                                                 pagingRequest.getQueryExecutionId());
        CannedQuery<Long> query = new GetDoclinkNodesCannedQuery(cannedQueryDAO, 
                                                                 params);
        CannedQueryResults<Long> results = query.execute();

        for (Long nodeId : results.getPage())
        {
            nodeLinks.add(nodeId);
        }
    }

    return nodeLinks;
}
 
Example 5
Source File: GetDiscussionTopcisWithPostsCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CannedQuery<NodeWithChildrenEntity> getCannedQuery(NodeRef parentNodeRef, 
      Date topicCreatedFrom, Date postCreatedFrom, boolean excludePrimaryPosts,
      CannedQuerySortDetails sortDetails, PagingRequest pagingReq)
{
    ParameterCheck.mandatory("parentNodeRef", parentNodeRef);
    ParameterCheck.mandatory("pagingReq", pagingReq);
    
    int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
    
    //FIXME Need tenant service like for GetChildren?
    GetDiscussionTopcisWithPostsCannedQueryParams paramBean = new GetDiscussionTopcisWithPostsCannedQueryParams(
          getNodeId(parentNodeRef), 
          getQNameId(ContentModel.PROP_NAME),
          getQNameId(ForumModel.TYPE_TOPIC),
          getQNameId(ForumModel.TYPE_POST),
          topicCreatedFrom, postCreatedFrom,
          excludePrimaryPosts);
    
    CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
    
    // create query params holder
    CannedQueryParameters params = new CannedQueryParameters(
          paramBean, cqpd, sortDetails, requestTotalCountMax, pagingReq.getQueryExecutionId());
    
    // return canned query instance
    return getCannedQuery(params);
}
 
Example 6
Source File: GetChildrenWithTargetAssocsAuditableCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CannedQuery<NodeWithTargetsEntity> getCannedQuery(NodeRef parentNodeRef, 
      QName contentType, QName assocType,
      CannedQuerySortDetails sortDetails, PagingRequest pagingReq)
{
    ParameterCheck.mandatory("parentNodeRef", parentNodeRef);
    ParameterCheck.mandatory("contentType", contentType);
    ParameterCheck.mandatory("pagingReq", pagingReq);
    
    int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
    
    //FIXME Need tenant service like for GetChildren?
    GetChildrenWithTargetAssocsAuditableCannedQueryParams paramBean = new GetChildrenWithTargetAssocsAuditableCannedQueryParams(
          getNodeId(parentNodeRef), 
          getQNameId(ContentModel.PROP_NAME),
          getQNameId(contentType),
          getQNameId(assocType)
    );
    
    CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
    
    // create query params holder
    CannedQueryParameters params = new CannedQueryParameters(
          paramBean, cqpd, sortDetails, requestTotalCountMax, pagingReq.getQueryExecutionId());
    
    // return canned query instance
    return getCannedQuery(params);
}
 
Example 7
Source File: GetArchivedNodesCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @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 8
Source File: GetBlogPostsCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CannedQuery<BlogEntity> getGetDraftsCannedQuery(NodeRef blogContainerNode, String username, PagingRequest pagingReq)
{
    ParameterCheck.mandatory("blogContainerNode", blogContainerNode);
    ParameterCheck.mandatory("pagingReq", pagingReq);
    
    int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
    
    //FIXME Need tenant service like for GetChildren?
    boolean isPublished = false;
    GetBlogPostsCannedQueryParams paramBean = new GetBlogPostsCannedQueryParams(getNodeId(blogContainerNode),
                                                                                getQNameId(ContentModel.PROP_NAME),
                                                                                getQNameId(ContentModel.PROP_PUBLISHED),
                                                                                getQNameId(ContentModel.TYPE_CONTENT),
                                                                                username,
                                                                                isPublished,
                                                                                null, null,
                                                                                null, null);
    
    CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
    CannedQuerySortDetails cqsd = createCQSortDetails(ContentModel.PROP_CREATED, SortOrder.DESCENDING);
    
    // create query params holder
    CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());
    
    // return canned query instance
    return getCannedQuery(params);
}
 
Example 9
Source File: DraftsAndPublishedBlogPostsCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CannedQuery<BlogEntity> getCannedQuery(NodeRef blogContainerNode, Date fromDate, Date toDate, String byUser, PagingRequest pagingReq)
{
    ParameterCheck.mandatory("blogContainerNode", blogContainerNode);
    ParameterCheck.mandatory("pagingReq", pagingReq);
    
    int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
    
    //FIXME Need tenant service like for GetChildren?
    DraftsAndPublishedBlogPostsCannedQueryParams paramBean = new DraftsAndPublishedBlogPostsCannedQueryParams(
                                                                                getNodeId(blogContainerNode),
                                                                                getQNameId(ContentModel.PROP_NAME),
                                                                                getQNameId(ContentModel.PROP_PUBLISHED),
                                                                                getQNameId(ContentModel.TYPE_CONTENT),
                                                                                byUser,
                                                                                fromDate, toDate);
    
    CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
    
    List<Pair<QName, Boolean>> sortPairs = new ArrayList<Pair<QName, Boolean>>(2);
    
    // Sort by created then published. We want a list of all published (most recently published first),
    //                                 followed by all unpublished (most recently created first)
    sortPairs.add(new Pair<QName, Boolean>(ContentModel.PROP_CREATED, Boolean.FALSE));
    sortPairs.add(new Pair<QName, Boolean>(ContentModel.PROP_PUBLISHED, Boolean.FALSE));
    
    CannedQuerySortDetails cqsd = createCQSortDetails(sortPairs);
    
    // create query params holder
    CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());
    
    // return canned query instance
    return getCannedQuery(params);
}
 
Example 10
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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 11
Source File: GetCalendarEntriesCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public CannedQuery<CalendarEntry> getCannedQuery(NodeRef[] containerNodes, Date fromDate, Date toDate, PagingRequest pagingReq)
{
    ParameterCheck.mandatory("containerNodes", containerNodes);
    ParameterCheck.mandatory("pagingReq", pagingReq);
    
    int requestTotalCountMax = pagingReq.getRequestTotalCountMax();
    
    Long[] containerIds = new Long[containerNodes.length];
    for(int i=0; i<containerIds.length; i++)
    {
       containerIds[i] = getNodeId(containerNodes[i]);
    }
    
    //FIXME Need tenant service like for GetChildren?
    GetCalendarEntriesCannedQueryParams paramBean = new GetCalendarEntriesCannedQueryParams(
          containerIds, 
          getQNameId(ContentModel.PROP_NAME),
          getQNameId(CalendarModel.TYPE_EVENT),
          getQNameId(CalendarModel.PROP_FROM_DATE),
          getQNameId(CalendarModel.PROP_TO_DATE),
          getQNameId(CalendarModel.PROP_RECURRENCE_RULE),
          getQNameId(CalendarModel.PROP_RECURRENCE_LAST_MEETING),
          fromDate, 
          toDate
    );
    
    CannedQueryPageDetails cqpd = createCQPageDetails(pagingReq);
    CannedQuerySortDetails cqsd = createCQSortDetails();
    
    // create query params holder
    CannedQueryParameters params = new CannedQueryParameters(paramBean, cqpd, cqsd, requestTotalCountMax, pagingReq.getQueryExecutionId());
    
    // return canned query instance
    return getCannedQuery(params);
}
 
Example 12
Source File: GetPeopleCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 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 13
Source File: GetAuthoritiesCannedQueryFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
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 14
Source File: FileFolderServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private PagingResults<FileInfo> getPagingResults(PagingRequest pagingRequest, final CannedQueryResults<NodeRef> results)
{
    List<NodeRef> nodeRefs = null;
    if (results.getPageCount() > 0)
    {
        nodeRefs = results.getPages().get(0);
    }
    else
    {
        nodeRefs = Collections.emptyList();
    }
    
    // set total count
    final Pair<Integer, Integer> totalCount;
    if (pagingRequest.getRequestTotalCountMax() > 0)
    {
        totalCount = results.getTotalResultCount();
    }
    else
    {
        totalCount = null;
    }
    
    final List<FileInfo> nodeInfos = new ArrayList<FileInfo>(nodeRefs.size());
    for (NodeRef nodeRef : nodeRefs)
    {
        nodeInfos.add(toFileInfo(nodeRef, true));
    }
    PermissionCheckedCollectionMixin.create(nodeInfos, nodeRefs);
    
    return new PagingResults<FileInfo>()
    {
        @Override
        public String getQueryExecutionId()
        {
            return results.getQueryExecutionId();
        }
        @Override
        public List<FileInfo> getPage()
        {
            return nodeInfos;
        }
        @Override
        public boolean hasMoreItems()
        {
            return results.hasMoreItems();
        }
        @Override
        public Pair<Integer, Integer> getTotalResultCount()
        {
            return totalCount;
        }
    };        
}
 
Example 15
Source File: SubscriptionsDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PagingFollowingResults selectFollowing(String userId, PagingRequest pagingRequest)
{
    if (userId == null)
    {
        throw new IllegalArgumentException("User Id may not be null!");
    }

    NodeRef userNodeRef = getUserNodeRef(userId);
    if (userNodeRef == null)
    {
        throw new IllegalArgumentException("User does not exist!");
    }

    Long dbid = (Long) nodeService.getProperty(userNodeRef, PROP_SYS_NODE_DBID);

    Map<String, Object> map = new HashMap<String, Object>();

    Pair<Long, QName> qNamePair = qnameDAO.getQName(ContentModel.PROP_USERNAME);
    if (null != qNamePair)
    {
        map.put("userIdQname", qNamePair.getFirst());
    }

    map.put("userNodeId", dbid);

    int maxItems = (pagingRequest.getMaxItems() < 0 || pagingRequest.getMaxItems() > Integer.MAX_VALUE - 1 ? Integer.MAX_VALUE - 1
            : pagingRequest.getMaxItems() + 1);

    @SuppressWarnings("unchecked")
    List<String> userList = template.selectList("alfresco.subscriptions.select_Following", map,
            new RowBounds(pagingRequest.getSkipCount(), maxItems + 1));

    boolean hasMore = userList.size() > maxItems;
    if (hasMore && userList.size() > 0)
    {
        userList.remove(userList.size() - 1);
    }

    Integer totalCount = null;
    if (pagingRequest.getRequestTotalCountMax() > 0)
    {
        totalCount = countSubscriptions(userId, SubscriptionItemTypeEnum.USER);
    }

    return new PagingFollowingResultsImpl(userList, hasMore, totalCount);
}
 
Example 16
Source File: CommentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PagingResults<NodeRef> listComments(NodeRef discussableNode, PagingRequest paging)
{
	NodeRef commentsFolder = getShareCommentsTopic(discussableNode);
	if(commentsFolder != null)
	{
		List<Pair<QName,Boolean>> sort = new ArrayList<Pair<QName,Boolean>>();
		sort.add(new Pair<QName, Boolean>(ContentModel.PROP_CREATED, false));

     // Run the canned query
     GetChildrenCannedQueryFactory getChildrenCannedQueryFactory = (GetChildrenCannedQueryFactory)cannedQueryRegistry.getNamedObject(CANNED_QUERY_GET_CHILDREN);
     GetChildrenCannedQuery cq = (GetChildrenCannedQuery)getChildrenCannedQueryFactory.getCannedQuery(commentsFolder, null, null, null, null, sort, paging);
        
        // Execute the canned query
        final CannedQueryResults<NodeRef> results = cq.execute();

        // Now convert the CannedQueryResults<NodeRef> into a more useful PagingResults<NodeRef>
        List<NodeRef> comments = Collections.emptyList();

        if (results.getPageCount() > 0)
        {
            comments = results.getPages().get(0);
        }

        // set total count
        final Pair<Integer, Integer> totalCount;
        if (paging.getRequestTotalCountMax() > 0)
        {
            totalCount = results.getTotalResultCount();
        }
        else
        {
            totalCount = null;
        }

        final List<NodeRef> page = new ArrayList<NodeRef>(comments.size());
        for (NodeRef comment : comments)
        {
            page.add(comment);
        }

        return new PagingResults<NodeRef>()
        {
            @Override
            public String getQueryExecutionId()
            {
                return results.getQueryExecutionId();
            }

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

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

            @Override
            public Pair<Integer, Integer> getTotalResultCount()
            {
                return totalCount;
            }
        };
    }
    else
    {
        return new EmptyPagingResults<NodeRef>();
    }
}
 
Example 17
Source File: NodeArchiveServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@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 18
Source File: SiteServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private <T extends Object> PagingResults<T> getPagingResults(PagingRequest pagingRequest, final CannedQueryResults<T> results)
{
    List<T> entities = null;
    if (results.getPageCount() > 0)
    {
        entities = results.getPages().get(0);
    }
    else
    {
        entities = Collections.emptyList();
    }
    
    // set total count
    final Pair<Integer, Integer> totalCount;
    if (pagingRequest.getRequestTotalCountMax() > 0)
    {
        totalCount = results.getTotalResultCount();
    }
    else
    {
        totalCount = null;
    }
    
    final List<T> members = new ArrayList<T>(entities.size());
    for (T entity : entities)
    {
        members.add(entity);
    }
    
    return new PagingResults<T>()
    {
        @Override
        public String getQueryExecutionId()
        {
            return results.getQueryExecutionId();
        }

        @Override
        public List<T> getPage()
        {
            return members;
        }
        
        @Override
        public boolean hasMoreItems()
        {
            return results.hasMoreItems();
        }

        @Override
        public Pair<Integer, Integer> getTotalResultCount()
        {
            return totalCount;
        }
    };
}
 
Example 19
Source File: SubscriptionsDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PagingSubscriptionResults selectSubscriptions(String userId, SubscriptionItemTypeEnum type,
        PagingRequest pagingRequest)
{
    if (userId == null)
    {
        throw new IllegalArgumentException("User Id may not be null!");
    }

    if (type == null)
    {
        throw new IllegalArgumentException("Type may not be null!");
    }

    NodeRef userNodeRef = getUserNodeRef(userId);
    if (userNodeRef == null)
    {
        throw new IllegalArgumentException("User does not exist!");
    }

    Long dbid = (Long) nodeService.getProperty(userNodeRef, PROP_SYS_NODE_DBID);

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("userNodeId", dbid);

    int maxItems = (pagingRequest.getMaxItems() < 0 || pagingRequest.getMaxItems() > Integer.MAX_VALUE - 1 ? Integer.MAX_VALUE - 1
            : pagingRequest.getMaxItems() + 1);

    @SuppressWarnings("unchecked")
    List<SubscriptionNodeEntity> nodeList = template.selectList(
            "alfresco.subscriptions.select_Subscriptions", map, new RowBounds(pagingRequest.getSkipCount(),
                    maxItems + 1));

    boolean hasMore = nodeList.size() > maxItems;

    List<NodeRef> result = new ArrayList<NodeRef>(nodeList.size());
    for (SubscriptionNodeEntity sne : nodeList)
    {
        result.add(sne.getNodeRef());
        if (result.size() == pagingRequest.getMaxItems())
        {
            break;
        }
    }

    Integer totalCount = null;
    if (pagingRequest.getRequestTotalCountMax() > 0)
    {
        totalCount = countSubscriptions(userId, type);
    }

    return new PagingSubscriptionResultsImpl(result, hasMore, totalCount);
}
 
Example 20
Source File: SubscriptionsDAOImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PagingFollowingResults selectFollowers(String userId, PagingRequest pagingRequest)
{
    if (userId == null)
    {
        throw new IllegalArgumentException("User Id may not be null!");
    }

    NodeRef userNodeRef = getUserNodeRef(userId);
    if (userNodeRef == null)
    {
        throw new IllegalArgumentException("User does not exist!");
    }

    Long dbid = (Long) nodeService.getProperty(userNodeRef, PROP_SYS_NODE_DBID);

    Map<String, Object> map = new HashMap<String, Object>();

    Pair<Long, QName> qNamePair = qnameDAO.getQName(ContentModel.PROP_USERNAME);
    if (null != qNamePair)
    {
        map.put("userIdQname", qNamePair.getFirst());
    }

    map.put("userNodeId", dbid);

    int maxItems = (pagingRequest.getMaxItems() < 0 || pagingRequest.getMaxItems() > Integer.MAX_VALUE - 1 ? Integer.MAX_VALUE - 1
            : pagingRequest.getMaxItems() + 1);

    @SuppressWarnings("unchecked")
    List<String> userList = template.selectList("alfresco.subscriptions.select_Followers", map,
            new RowBounds(pagingRequest.getSkipCount(), maxItems + 1));

    boolean hasMore = userList.size() > maxItems;
    if (hasMore && userList.size() > 0)
    {
        userList.remove(userList.size() - 1);
    }

    Integer totalCount = null;
    if (pagingRequest.getRequestTotalCountMax() > 0)
    {
        totalCount = countFollowers(userId);
    }

    return new PagingFollowingResultsImpl(userList, hasMore, totalCount);
}