@Override public PartialList<E> subList(int fromIndex, int toIndex) { return new PartialList<>(list.subList(fromIndex, toIndex), totalSize); }
@Override public PartialList<Comment> getComments(CoreSession session, String documentId, Long pageSize, Long currentPageIndex, boolean sortAscending) throws CommentSecurityException { List<Comment> firstComments = first.getComments(session, documentId, pageSize, currentPageIndex, sortAscending); List<Comment> secondComments = second.getComments(session, documentId, pageSize, currentPageIndex, sortAscending); List<Comment> allComments = Stream.concat(firstComments.stream(), secondComments.stream()) .distinct() .collect(Collectors.toList()); return new PartialList<>(allComments, allComments.size()); }
@Override @SuppressWarnings("unchecked") public PartialList<Comment> getComments(CoreSession session, String documentId, Long pageSize, Long currentPageIndex, boolean sortAscending) throws CommentSecurityException { DocumentRef docRef = new IdRef(documentId); if (!session.exists(docRef)) { return new PartialList<>(Collections.emptyList(), 0); } DocumentModel commentedDoc = session.getDocument(docRef); // do a dummy implementation of pagination for former comment manager implementation List<DocumentModel> comments = getComments(commentedDoc); long maxSize = pageSize == null || pageSize <= 0 ? comments.size() : pageSize; long offset = currentPageIndex == null || currentPageIndex <= 0 ? 0 : currentPageIndex * pageSize; return comments.stream() .sorted(Comparator.comparing(doc -> (Calendar) doc.getPropertyValue("dc:created"))) .skip(offset) .limit(maxSize) .map(Comments::newComment) .collect(collectingAndThen(toList(), list -> new PartialList<>(list, comments.size()))); }
log.trace("Mem: -> " + projections.size()); return new PartialList<>(projections, totalSize);
return new PartialList<>(list, pl.totalSize());
@Override @SuppressWarnings("unchecked") public PartialList<Comment> getComments(CoreSession session, String documentId, Long pageSize, Long currentPageIndex, boolean sortAscending) throws CommentSecurityException { DocumentRef docRef = new IdRef(documentId); PageProviderService ppService = Framework.getService(PageProviderService.class); NuxeoPrincipal principal = session.getPrincipal(); return CoreInstance.doPrivileged(session, s -> { if (s.exists(docRef)) { DocumentRef ancestorRef = getAncestorRef(s, s.getDocument(docRef)); if (s.exists(ancestorRef) && !s.hasPermission(principal, ancestorRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + principal.getName() + " does not have access to the comments of document " + documentId); } } Map<String, Serializable> props = Collections.singletonMap(CORE_SESSION_PROPERTY, (Serializable) s); PageProvider<DocumentModel> pageProvider = (PageProvider<DocumentModel>) ppService.getPageProvider( GET_COMMENTS_FOR_DOC_PAGEPROVIDER_NAME, singletonList(new SortInfo(COMMENT_CREATION_DATE, sortAscending)), pageSize, currentPageIndex, props, documentId); List<DocumentModel> commentList = pageProvider.getCurrentPage(); return commentList.stream() .map(Comments::newComment) .collect(collectingAndThen(toList(), list -> new PartialList<>(list, pageProvider.getResultsCount()))); }); }
return new PartialList<>(Collections.emptyList(), 0); return new PartialList<>(projections, totalSize);
log.trace("MongoDB: -> " + projections.size()); return new PartialList<>(projections, totalSize);