@Override public void updateExternalAnnotation(CoreSession session, String entityId, Annotation annotation) throws CommentNotFoundException, CommentSecurityException { NuxeoPrincipal principal = session.getPrincipal(); if (!principal.isAdministrator() && !annotation.getAuthor().equals(principal.getName())) { throw new CommentSecurityException("The user " + session.getPrincipal().getName() + " can not edit annotations of document " + annotation.getParentId()); } DocumentModel annotationModel = getAnnotationModel(session, entityId); if (annotationModel == null) { throw new CommentNotFoundException("The external annotation " + entityId + " does not exist."); } Comments.annotationToDocumentModel(annotation, annotationModel); if (annotation instanceof ExternalEntity) { Comments.externalEntityToDocumentModel((ExternalEntity) annotation, annotationModel); } session.saveDocument(annotationModel); }
@Override public void updateAnnotation(CoreSession session, String annotationId, Annotation annotation) throws CommentNotFoundException, CommentSecurityException { IdRef annotationRef = new IdRef(annotationId); if (!session.exists(annotationRef)) { throw new CommentNotFoundException("The annotation " + annotationId + " does not exist."); } NuxeoPrincipal principal = session.getPrincipal(); if (!principal.isAdministrator() && !annotation.getAuthor().equals(principal.getName())) { throw new CommentSecurityException("The user " + principal.getName() + " can not edit annotations of document " + annotation.getParentId()); } CoreInstance.doPrivileged(session, s -> { DocumentModel annotationModel = s.getDocument(annotationRef); Comments.annotationToDocumentModel(annotation, annotationModel); if (annotation instanceof ExternalEntity) { Comments.externalEntityToDocumentModel((ExternalEntity) annotation, annotationModel); } s.saveDocument(annotationModel); }); }