@Test public void shouldCreateLocatedComment() { DocumentModel container = session.createDocumentModel("/domain", "CommentContainer", "Folder"); session.createDocument(container); session.save(); Comment comment = newComment(commentedDocModel.getId(), "some text"); comment.setCreationDate(Instant.now()); DocumentModel commentModel = session.createDocumentModel(null, "Comment", COMMENT_DOC_TYPE); applyDirtyPropertyValues(comment.getDocument(), commentModel); commentManager.createLocatedComment(commentedDocModel, commentModel, "/domain/CommentContainer"); DocumentModelList children = session.getChildren(new PathRef("/domain/CommentContainer"), COMMENT_DOC_TYPE); assertNotNull(children); assertEquals(1, children.totalSize()); assertEquals(comment.getAuthor(), children.get(0).getPropertyValue("comment:author")); assertEquals(comment.getCreationDate(), ((Calendar) children.get(0).getPropertyValue("comment:creationDate")).toInstant()); assertEquals(comment.getText(), children.get(0).getPropertyValue("comment:text")); }
@Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getTopLevelDocumentRef(session, docModel.getRef()); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_PARENT_ID_PROPERTY, docModel.getId()); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS_PROPERTY, computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }
PropertyCommentManager extends AbstractCommentManager { @Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getTopLevelDocumentRef(session, docModel.getRef()); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_PARENT_ID_PROPERTY, docModel.getId()); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS_PROPERTY, computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); } }
PropertyCommentManager extends AbstractCommentManager { @Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getTopLevelDocumentRef(session, docModel.getRef()); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_PARENT_ID_PROPERTY, docModel.getId()); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS_PROPERTY, computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }  }
PropertyCommentManager extends AbstractCommentManager { @Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getTopLevelDocumentRef(session, docModel.getRef()); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_PARENT_ID_PROPERTY, docModel.getId()); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS_PROPERTY, computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }  @Override @SuppressWarnings("unchecked") List<DocumentModel> getComments(CoreSession session, DocumentModel docModel); @Override List<DocumentModel> getComments(DocumentModel docModel, DocumentModel parent); @Override DocumentModel createComment(DocumentModel docModel, String comment); @Override @SuppressWarnings("removal") DocumentModel createComment(DocumentModel docModel, String text, String author); @Override DocumentModel createComment(DocumentModel docModel, DocumentModel commentModel); @Override @SuppressWarnings("removal") DocumentModel createComment(DocumentModel docModel, DocumentModel parent, DocumentModel child); @Override @SuppressWarnings("removal") void deleteComment(DocumentModel docModel, DocumentModel comment); @Override @SuppressWarnings("removal") List<DocumentModel> getDocumentsForComment(DocumentModel comment); @Override DocumentModel getThreadForComment(DocumentModel comment); @Override DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path); @Override Comment createComment(CoreSession session, Comment comment); @Override Comment getComment(CoreSession session, String commentId); @Override @SuppressWarnings("unchecked") PartialList<Comment> getComments(CoreSession session, String documentId, Long pageSize,
            Long currentPageIndex, boolean sortAscending); @Override List<Comment> getComments(CoreSession session, Collection<String> documentIds); @Override Comment updateComment(CoreSession session, String commentId, Comment comment); @Override void deleteComment(CoreSession session, String commentId); @Override Comment getExternalComment(CoreSession session, String documentId, String entityId); @Override Comment updateExternalComment(CoreSession session, String documentId, String entityId, Comment comment); @Override void deleteExternalComment(CoreSession session, String documentId, String entityId); @Override boolean hasFeature(Feature feature); }
PropertyCommentManager extends AbstractCommentManager { @Override public DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path) { CoreSession session = docModel.getCoreSession(); DocumentRef docRef = getTopLevelDocumentRef(session, docModel.getRef()); if (!session.hasPermission(docRef, SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create comments on document " + docModel.getId()); } return CoreInstance.doPrivileged(session, s -> { DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, comment.getType()); commentModel.copyContent(comment); commentModel.setPropertyValue(COMMENT_PARENT_ID_PROPERTY, docModel.getId()); commentModel.setPropertyValue(COMMENT_ANCESTOR_IDS_PROPERTY, computeAncestorIds(s, docModel.getId())); commentModel = s.createDocument(commentModel); notifyEvent(session, CommentEvents.COMMENT_ADDED, docModel, commentModel); return commentModel; }); }  @Override @SuppressWarnings("unchecked") List<DocumentModel> getComments(CoreSession session, DocumentModel docModel); @Override List<DocumentModel> getComments(DocumentModel docModel, DocumentModel parent); @Override DocumentModel createComment(DocumentModel docModel, String comment); @Override @SuppressWarnings("removal") DocumentModel createComment(DocumentModel docModel, String text, String author); @Override DocumentModel createComment(DocumentModel docModel, DocumentModel commentModel); @Override @SuppressWarnings("removal") DocumentModel createComment(DocumentModel docModel, DocumentModel parent, DocumentModel child); @Override @SuppressWarnings("removal") void deleteComment(DocumentModel docModel, DocumentModel comment); @Override @SuppressWarnings("removal") List<DocumentModel> getDocumentsForComment(DocumentModel comment); @Override DocumentModel getThreadForComment(DocumentModel comment); @Override DocumentModel createLocatedComment(DocumentModel docModel, DocumentModel comment, String path); @Override Comment createComment(CoreSession session, Comment comment); @Override Comment getComment(CoreSession session, String commentId); @Override @SuppressWarnings("unchecked") PartialList<Comment> getComments(CoreSession session, String documentId, Long pageSize,
            Long currentPageIndex, boolean sortAscending); @Override List<Comment> getComments(CoreSession session, Collection<String> documentIds); @Override Comment updateComment(CoreSession session, String commentId, Comment comment); @Override void deleteComment(CoreSession session, String commentId); @Override Comment getExternalComment(CoreSession session, String documentId, String entityId); @Override Comment updateExternalComment(CoreSession session, String documentId, String entityId, Comment comment); @Override void deleteExternalComment(CoreSession session, String documentId, String entityId); @Override boolean hasFeature(Feature feature);  }