@Override public PartialList<E> subList(int fromIndex, int toIndex) { return new PartialList<>(list.subList(fromIndex, toIndex), totalSize); }
protected void writeRepliesSummary(CoreSession session, Comment entity, JsonGenerator jg) throws IOException { PartialList<Comment> comments = commentManager.getComments(session, entity.getId(), 1L, 0L, false); jg.writeNumberField(COMMENT_NUMBER_OF_REPLIES, comments.totalSize()); if (comments.size() > 0) { jg.writeStringField(COMMENT_LAST_REPLY_DATE, comments.get(0).getCreationDate().toString()); } } }
return new PartialList<>(list, pl.totalSize());
@Override public PartialList<Serializable> query(String query, String queryType, QueryFilter queryFilter, long countUpTo) { PartialList<Serializable> result = queryProjection(query, queryType, queryFilter, countUpTo, (info, rs) -> info.whatColumns.get(0).getFromResultSet(rs, 1)); if (logger.isLogEnabled()) { logger.logIds(result, countUpTo != 0, result.totalSize()); } return result; }
@Override public void run() { PartialList<Map<String, Serializable>> workflows = session.queryProjection(WORKFLOWS_QUERY, limit, 0); numberOfCleanedUpWorkflows = workflows.size(); for (Map<String, Serializable> workflow : workflows) { String routeDocId = workflow.get(ECM_UUID).toString(); final String associatedTaskQuery = String.format(TASKS_QUERY, routeDocId); session.queryProjection(associatedTaskQuery, 0, 0) .stream() .map(task -> new IdRef(task.get(ECM_UUID).toString())) .forEach(session::removeDocument); session.removeDocument(new IdRef(routeDocId)); } }
protected boolean hasContent(DocumentModel document, String query) throws IOException { try (SessionWrapper wrapper = ctx.getSession(document)) { // Limit result set to 1 as we just want to know if there's at least one child return wrapper.getSession() .queryProjection(String.format(query, NXQL.escapeString(document.getId())), 1, 0) .size() > 0; } }
@Override public void write(JsonGenerator jg, DocumentModel document) throws IOException { if (!document.isFolder()) { jg.writeBooleanField(NAME, false); return; } try (SessionWrapper wrapper = ctx.getSession(document)) { String fetchFolderishChildQuery = "SELECT * FROM Document WHERE ecm:mixinType = 'Folderish'" + " AND ecm:mixinType != 'HiddenInNavigation' AND ecm:isTrashed = 0" + " AND ecm:parentId = " + NXQL.escapeString(document.getId()); // Limit result set to 1 as we just want to know if there's at least one Folderish child boolean hasChildren = !wrapper.getSession().queryProjection(fetchFolderishChildQuery, 1, 0).isEmpty(); jg.writeBooleanField(NAME, hasChildren); } }
@Override public PartialList<Map<String, Serializable>> queryProjection(String query, String queryType, QueryFilter queryFilter, boolean distinctDocuments, long countUpTo, Object... params) { query = computeDistinctDocuments(query, distinctDocuments); PartialList<Map<String, Serializable>> result = queryProjection(query, queryType, queryFilter, countUpTo, (info, rs) -> info.mapMaker.makeMap(rs), params); if (logger.isLogEnabled()) { logger.logMaps(result, countUpTo != 0, result.totalSize()); } return result; }
@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()); }
jg.writeNumberField("totalSize", partial.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); 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);
@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);