protected List<Comment> getAllComments(String annotationId, CommentManager commentManager, CoreSession session) { List<Comment> allComments = new ArrayList<>(); List<Comment> comments = commentManager.getComments(session, annotationId); for (Comment comment : comments) { allComments.addAll(getAllComments(comment.getId(), commentManager, session)); allComments.add(comment); } return allComments; }
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()); } } }
public List<DocumentModel> getComments(DocumentModel parent) { CoreSession session = docModel.getCoreSession(); List<Comment> comments = commentManager.getComments(session, parent.getId()); return CoreInstance.doPrivileged(session, s -> { return comments.stream().map(comment -> { DocumentModel commentModel = s.getDocument(new IdRef(comment.getId())); commentModel.detach(true); return commentModel; }).collect(Collectors.toList()); }); }
protected void deleteCommentChildren(CoreSession coreSession, CommentManager commentManager, DocumentModel documentModel) { commentManager.getComments(coreSession, documentModel.getId()) .forEach(comment -> coreSession.removeDocument(new IdRef(comment.getId()))); }
protected static void writeCommentEntity(Comment entity, JsonGenerator jg) throws IOException { jg.writeStringField(COMMENT_ID_FIELD, entity.getId()); jg.writeStringField(COMMENT_PARENT_ID_FIELD, entity.getParentId()); jg.writeArrayFieldStart(COMMENT_ANCESTOR_IDS_FIELD); for (String ancestorId : entity.getAncestorIds()) { jg.writeString(ancestorId); } jg.writeEndArray(); jg.writeStringField(COMMENT_AUTHOR_FIELD, entity.getAuthor()); jg.writeStringField(COMMENT_TEXT_FIELD, entity.getText()); String creationDate = entity.getCreationDate() != null ? entity.getCreationDate().toString() : null; jg.writeStringField(COMMENT_CREATION_DATE_FIELD, creationDate); String modificationDate = entity.getModificationDate() != null ? entity.getModificationDate().toString() : null; jg.writeStringField(COMMENT_MODIFICATION_DATE_FIELD, modificationDate); if (entity instanceof ExternalEntity) { jg.writeStringField(EXTERNAL_ENTITY_ID, ((ExternalEntity) entity).getEntityId()); jg.writeStringField(EXTERNAL_ENTITY_ORIGIN, ((ExternalEntity) entity).getOrigin()); jg.writeStringField(EXTERNAL_ENTITY, ((ExternalEntity) entity).getEntity()); } }
@Override protected void writeEntityBody(Comment entity, JsonGenerator jg) throws IOException { writeCommentEntity(entity, jg); CoreSession session = ctx.getSession(null).getSession(); NuxeoPrincipal principal = session.getPrincipal(); PermissionProvider permissionProvider = Framework.getService(PermissionProvider.class); // Write permissions of current user on the annotation, // which are the ones granted on the commented document Collection<String> permissions = CoreInstance.doPrivileged(session, s -> { if (entity.getId() == null) { return Collections.emptyList(); } DocumentRef ancestorRef = new IdRef( (String) commentManager.getThreadForComment(s.getDocument(new IdRef(entity.getId()))) .getPropertyValue(COMMENT_PARENT_ID)); return s.filterGrantedPermissions(principal, ancestorRef, Arrays.asList(permissionProvider.getPermissions())); }); jg.writeArrayFieldStart(COMMENT_PERMISSIONS); for (String permission : permissions) { jg.writeString(permission); } jg.writeEndArray(); boolean includeRepliesSummary = ctx.getFetched(COMMENT_ENTITY_TYPE).contains(FETCH_REPLIES_SUMMARY); if (includeRepliesSummary) { writeRepliesSummary(session, entity, jg); } }