@Override public Annotation getExternalAnnotation(CoreSession session, String entityId) throws CommentNotFoundException, CommentSecurityException { DocumentModel annotationModel = getAnnotationModel(session, entityId); if (annotationModel == null) { throw new CommentNotFoundException("The external annotation " + entityId + " does not exist."); } String parentId = (String) annotationModel.getPropertyValue(COMMENT_PARENT_ID); if (!session.hasPermission(new IdRef(parentId), SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " does not have access to the annotations of document " + parentId); } return Comments.newAnnotation(annotationModel); }
@Override public Annotation getAnnotation(CoreSession session, String annotationId) throws CommentNotFoundException, CommentSecurityException { DocumentRef annotationRef = new IdRef(annotationId); if (!session.exists(annotationRef)) { throw new CommentNotFoundException("The document " + annotationId + " does not exist."); } NuxeoPrincipal principal = session.getPrincipal(); return CoreInstance.doPrivileged(session, s -> { DocumentModel annotationModel = s.getDocument(annotationRef); String parentId = (String) annotationModel.getPropertyValue(COMMENT_PARENT_ID); if (!s.hasPermission(principal, new IdRef(parentId), SecurityConstants.READ)) { throw new CommentSecurityException("The user " + principal.getName() + " does not have access to the annotations of document " + parentId); } return Comments.newAnnotation(annotationModel); }); }
@Override public Annotation createAnnotation(CoreSession session, Annotation annotation) throws CommentSecurityException { String parentId = annotation.getParentId(); if (!session.hasPermission(new IdRef(parentId), SecurityConstants.READ)) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not create annotations on document " + parentId); } return CoreInstance.doPrivileged(session, s -> { // Create base comment in the annotation DocumentModel docToAnnotate = s.getDocument(new IdRef(annotation.getParentId())); DocumentModel annotationModel = s.createDocumentModel(ANNOTATION_DOC_TYPE); Comments.annotationToDocumentModel(annotation, annotationModel); if (annotation instanceof ExternalEntity) { annotationModel.addFacet(EXTERNAL_ENTITY_FACET); Comments.externalEntityToDocumentModel((ExternalEntity) annotation, annotationModel); } annotationModel = Framework.getService(CommentManager.class).createComment(docToAnnotate, annotationModel); return Comments.newAnnotation(annotationModel); }); }