From 612d67301bbf186f5144c0243f9a37fe21d3646c Mon Sep 17 00:00:00 2001 From: deiflaender Date: Tue, 27 Oct 2020 12:00:03 +0100 Subject: [PATCH] RED-427: Added possibility to add comments to all annotation --- .../service/redaction/v1/model/IdRemoval.java | 6 ------ .../v1/model/ManualRedactionEntry.java | 3 --- .../redaction/v1/model/ManualRedactions.java | 7 +++++++ .../service/AnnotationHighlightService.java | 18 +++++++++++------- .../v1/server/RedactionIntegrationTest.java | 11 +++++++++-- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/IdRemoval.java b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/IdRemoval.java index a3cb402f..bc11c440 100644 --- a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/IdRemoval.java +++ b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/IdRemoval.java @@ -1,8 +1,5 @@ package com.iqser.red.service.redaction.v1.model; -import java.util.ArrayList; -import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; @@ -19,7 +16,4 @@ public class IdRemoval { private Status status; private boolean removeFromDictionary; - @Builder.Default - private List comments = new ArrayList<>(); - } diff --git a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactionEntry.java b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactionEntry.java index e68ef1f9..e3303495 100644 --- a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactionEntry.java +++ b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactionEntry.java @@ -24,9 +24,6 @@ public class ManualRedactionEntry { private Status status; private boolean addToDictionary; - @Builder.Default - private List comments = new ArrayList<>(); - private String section; private int sectionNumber; diff --git a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactions.java b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactions.java index b68f5428..9e602a79 100644 --- a/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactions.java +++ b/redaction-service-v1/redaction-service-api-v1/src/main/java/com/iqser/red/service/redaction/v1/model/ManualRedactions.java @@ -1,6 +1,9 @@ package com.iqser.red.service.redaction.v1.model; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Set; import lombok.AllArgsConstructor; @@ -19,4 +22,8 @@ public class ManualRedactions { @Builder.Default private Set entriesToAdd = new HashSet<>(); + + @Builder.Default + private Map> comments = new HashMap<>(); + } diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java index d6ee7f91..d1d03fae 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java @@ -109,7 +109,7 @@ public class AnnotationHighlightService { if (manualRedactions != null && !manualRedactions.getIdsToRemove().isEmpty()) { for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) { if (manualRemoval.getId().equals(entityPositionSequence.getId())) { - comments = manualRemoval.getComments(); + comments = manualRedactions.getComments().get(manualRemoval.getId()); String manualOverrideReason = null; if (manualRemoval.getStatus().equals(Status.APPROVED)) { entity.setRedaction(false); @@ -138,6 +138,10 @@ public class AnnotationHighlightService { .flatMap(seq -> seq.getTextPositions().stream()) .collect(Collectors.toList()), page); + if (manualRedactions != null) { + comments = manualRedactions.getComments().get(entityPositionSequence.getId()); + } + redactionLogEntry.getPositions().addAll(rectanglesPerLine); annotations.addAll(createAnnotation(rectanglesPerLine, prefixId(entity, entityPositionSequence.getId(), requestedToRemove, removeFromDictionary), createAnnotationContent(entity), getColor(entity, requestedToRemove), comments, !isHint(entity))); } @@ -221,7 +225,7 @@ public class AnnotationHighlightService { if (!rectanglesOnPage.isEmpty()) { annotations.addAll(createAnnotation(rectanglesOnPage, prefixId(manualRedactionEntry, id), createAnnotationContent(manualRedactionEntry), getColorForManualAdd(manualRedactionEntry - .getType(), manualRedactionEntry.getStatus()), manualRedactionEntry.getComments(), true)); + .getType(), manualRedactionEntry.getStatus()), manualRedactions.getComments().get(id), true)); classifiedDoc.getRedactionLogEntities().add(redactionLogEntry); } } @@ -234,7 +238,7 @@ public class AnnotationHighlightService { return "redaction:" + manualRedactionEntry.getType() + ":" + id; } - if(manualRedactionEntry.getStatus().equals(Status.REQUESTED)) { + if (manualRedactionEntry.getStatus().equals(Status.REQUESTED)) { if (manualRedactionEntry.isAddToDictionary()) { return "request:add:" + manualRedactionEntry.getType() + ":" + id; } @@ -318,8 +322,8 @@ public class AnnotationHighlightService { private String createAnnotationContent(Entity entity) { - return "\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\nLegal basis:" - + entity.getLegalBasis() + "\n\nIn section: \"" + entity.getHeadline() + "\""; + return "\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\nLegal basis:" + entity + .getLegalBasis() + "\n\nIn section: \"" + entity.getHeadline() + "\""; } @@ -415,7 +419,7 @@ public class AnnotationHighlightService { if (status.equals(Status.REQUESTED)) { return dictionaryService.getRequestAddColor(); - } else if (status.equals(Status.DECLINED)){ + } else if (status.equals(Status.DECLINED)) { return dictionaryService.getNotRedactedColor(); } return getColor(type); @@ -511,4 +515,4 @@ public class AnnotationHighlightService { } } -} \ No newline at end of file +} diff --git a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java index e5d97df8..e8349e3f 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java +++ b/redaction-service-v1/redaction-service-server-v1/src/test/java/com/iqser/red/service/redaction/v1/server/RedactionIntegrationTest.java @@ -20,6 +20,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import java.util.stream.Collectors; import org.apache.commons.io.IOUtils; @@ -341,6 +342,8 @@ public class RedactionIntegrationTest { ManualRedactions manualRedactions = new ManualRedactions(); + String manualAddId = UUID.randomUUID().toString(); + Comment comment = Comment.builder() .date(OffsetDateTime.now()) .user("TEST_USER") @@ -349,12 +352,16 @@ public class RedactionIntegrationTest { manualRedactions.setIdsToRemove(Set.of(IdRemoval.builder() .id("0836727c3508a0b2ea271da69c04cc2f") .status(Status.REQUESTED) - .comments(List.of(comment)) .build())); + manualRedactions.getComments().put("e5be0f1d941bbb92a068e198648d06c4", List.of(comment)); + manualRedactions.getComments().put("0836727c3508a0b2ea271da69c04cc2f", List.of(comment)); + manualRedactions.getComments().put(manualAddId, List.of(comment)); + + ManualRedactionEntry manualRedactionEntry = new ManualRedactionEntry(); + manualRedactionEntry.setId(manualAddId); manualRedactionEntry.setStatus(Status.REQUESTED); - manualRedactionEntry.setComments(List.of(comment)); manualRedactionEntry.setType("name"); manualRedactionEntry.setValue("O'Loughlin C.K."); manualRedactionEntry.setReason("Manual Redaction");