public static void annotationToDocumentModel(Annotation annotation, DocumentModel documentModel) { commentToDocumentModel(annotation, documentModel); documentModel.setPropertyValue(ANNOTATION_XPATH_PROPERTY, annotation.getXpath()); }
@Override public Comment createComment(CoreSession session, Comment comment) throws CommentNotFoundException, CommentSecurityException { DocumentRef commentRef = new IdRef(comment.getParentId()); if (!session.exists(commentRef)) { throw new CommentNotFoundException("The document " + comment.getParentId() + " does not exist."); } DocumentModel docToComment = session.getDocument(commentRef); DocumentModel commentModel = session.createDocumentModel(COMMENT_DOC_TYPE); commentModel.setPropertyValue("dc:created", Calendar.getInstance()); Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { commentModel.addFacet(EXTERNAL_ENTITY_FACET); Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel); } DocumentModel createdCommentModel = createComment(docToComment, commentModel); return Comments.newComment(createdCommentModel); }
@Override public Comment updateExternalComment(CoreSession session, String entityId, Comment comment) throws CommentNotFoundException { DocumentModel commentModel = getExternalCommentModel(session, entityId); if (commentModel == null) { throw new CommentNotFoundException("The external comment " + entityId + " does not exist."); } NuxeoPrincipal principal = session.getPrincipal(); if (!principal.isAdministrator() && !comment.getAuthor().equals(principal.getName())) { throw new CommentSecurityException( "The user " + principal.getName() + " can not edit comments of document " + comment.getParentId()); } return CoreInstance.doPrivileged(session, s -> { Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel); } s.saveDocument(commentModel); return Comments.newComment(commentModel); }); }
@Override public Comment updateComment(CoreSession session, String commentId, Comment comment) throws CommentNotFoundException { IdRef commentRef = new IdRef(commentId); if (!CoreInstance.doPrivileged(session, s -> {return s.exists(commentRef);})) { throw new CommentNotFoundException("The comment " + commentId + " does not exist."); } NuxeoPrincipal principal = session.getPrincipal(); if (!principal.isAdministrator() && !comment.getAuthor().equals(principal.getName())) { throw new CommentSecurityException( "The user " + principal.getName() + " can not edit comments of document " + comment.getParentId()); } return CoreInstance.doPrivileged(session, s -> { // Initiate Modification Date if it is not done yet if (comment.getModificationDate() == null) { comment.setModificationDate(Instant.now()); } DocumentModel commentModel = s.getDocument(commentRef); Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { Comments.externalEntityToDocumentModel((ExternalEntity) comment, commentModel); } s.saveDocument(commentModel); return Comments.newComment(commentModel); }); }
String path = getCommentContainerPath(s, parentId); DocumentModel commentModel = s.createDocumentModel(path, COMMENT_NAME, COMMENT_DOC_TYPE); Comments.commentToDocumentModel(comment, commentModel); if (comment instanceof ExternalEntity) { commentModel.addFacet(EXTERNAL_ENTITY_FACET);