Pull request #55: RED-413: Added user to manual redactions, approved flag to Status.APPROVED

Merge in RED/redaction-service from RED-413 to master

* commit '638c4f9c65d35406bba1fd33e20c3bae8a6e6a13':
  RED-413: Added user to manual redactions, approved flag to Status.APPROVED
This commit is contained in:
Dominique Eiflaender 2020-10-12 12:32:30 +02:00
commit 268dd0200e
6 changed files with 35 additions and 17 deletions

View File

@ -15,7 +15,8 @@ import lombok.NoArgsConstructor;
public class IdRemoval {
private String id;
private boolean approved;
private String user;
private Status status;
private boolean removeFromDictionary;
@Builder.Default

View File

@ -15,11 +15,12 @@ import lombok.NoArgsConstructor;
public class ManualRedactionEntry {
private String id;
private String user;
private String type;
private String value;
private String reason;
private List<Rectangle> positions = new ArrayList<>();
private boolean approved;
private Status status;
private boolean addToDictionary;
@Builder.Default

View File

@ -27,6 +27,6 @@ public class RedactionLogEntry {
private List<Rectangle> positions = new ArrayList<>();
private int sectionNumber;
private boolean manual;
private boolean approved;
private Status status;
}

View File

@ -0,0 +1,5 @@
package com.iqser.red.service.redaction.v1.model;
public enum Status {
REQUESTED, APPROVED, DECLINED
}

View File

@ -29,6 +29,7 @@ import com.iqser.red.service.redaction.v1.model.ManualRedactionEntry;
import com.iqser.red.service.redaction.v1.model.ManualRedactions;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import com.iqser.red.service.redaction.v1.model.RedactionLogEntry;
import com.iqser.red.service.redaction.v1.model.Status;
import com.iqser.red.service.redaction.v1.server.classification.model.Document;
import com.iqser.red.service.redaction.v1.server.classification.model.Paragraph;
import com.iqser.red.service.redaction.v1.server.classification.model.TextBlock;
@ -109,13 +110,13 @@ public class AnnotationHighlightService {
for (IdRemoval manualRemoval : manualRedactions.getIdsToRemove()) {
if (manualRemoval.getId().equals(entityPositionSequence.getId())) {
comments = manualRemoval.getComments();
String manualOverrideReason;
if (manualRemoval.isApproved()) {
String manualOverrideReason = null;
if (manualRemoval.getStatus().equals(Status.APPROVED)) {
entity.setRedaction(false);
redactionLogEntry.setRedacted(false);
redactionLogEntry.setApproved(true);
redactionLogEntry.setStatus(Status.APPROVED);
manualOverrideReason = entity.getRedactionReason() + ", removed by manual override";
} else {
} else if (manualRemoval.getStatus().equals(Status.REQUESTED)) {
requestedToRemove = true;
manualOverrideReason = entity.getRedactionReason() + ", requested to remove";
if (manualRemoval.isRemoveFromDictionary()) {
@ -123,7 +124,7 @@ public class AnnotationHighlightService {
}
}
entity.setRedactionReason(manualOverrideReason);
entity.setRedactionReason(manualOverrideReason != null ? manualOverrideReason : entity.getRedactionReason());
redactionLogEntry.setReason(manualOverrideReason);
redactionLogEntry.setManual(true);
}
@ -220,7 +221,7 @@ public class AnnotationHighlightService {
if (!rectanglesOnPage.isEmpty()) {
annotations.addAll(createAnnotation(rectanglesOnPage, prefixId(manualRedactionEntry, id), createAnnotationContent(manualRedactionEntry), getColorForManualAdd(manualRedactionEntry
.getType(), manualRedactionEntry.isApproved()), manualRedactionEntry.getComments(), true));
.getType(), manualRedactionEntry.getStatus()), manualRedactionEntry.getComments(), true));
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
}
}
@ -229,13 +230,18 @@ public class AnnotationHighlightService {
private String prefixId(ManualRedactionEntry manualRedactionEntry, String id) {
if (manualRedactionEntry.isApproved()) {
if (manualRedactionEntry.getStatus().equals(Status.APPROVED)) {
return "redaction:" + manualRedactionEntry.getType() + ":" + id;
}
if (manualRedactionEntry.isAddToDictionary()) {
return "request:add:" + manualRedactionEntry.getType() + ":" + id;
if(manualRedactionEntry.getStatus().equals(Status.REQUESTED)) {
if (manualRedactionEntry.isAddToDictionary()) {
return "request:add:" + manualRedactionEntry.getType() + ":" + id;
}
return "request:add:only_here" + ":" + id;
}
return "request:add:only_here" + ":" + id;
return "ignore:" + manualRedactionEntry.getType() + ":" + id;
}
@ -252,7 +258,7 @@ public class AnnotationHighlightService {
.section(manualRedactionEntry.getSection())
.sectionNumber(manualRedactionEntry.getSectionNumber())
.manual(true)
.approved(manualRedactionEntry.isApproved())
.status(manualRedactionEntry.getStatus())
.build();
}
@ -403,10 +409,12 @@ public class AnnotationHighlightService {
}
private float[] getColorForManualAdd(String type, boolean approved) {
private float[] getColorForManualAdd(String type, Status status) {
if (!approved) {
if (status.equals(Status.REQUESTED)) {
return dictionaryService.getRequestAddColor();
} else if (status.equals(Status.DECLINED)){
return dictionaryService.getNotRedactedColor();
}
return getColor(type);
}

View File

@ -52,6 +52,7 @@ import com.iqser.red.service.redaction.v1.model.Point;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import com.iqser.red.service.redaction.v1.model.RedactionRequest;
import com.iqser.red.service.redaction.v1.model.RedactionResult;
import com.iqser.red.service.redaction.v1.model.Status;
import com.iqser.red.service.redaction.v1.server.client.DictionaryClient;
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
import com.iqser.red.service.redaction.v1.server.controller.RedactionController;
@ -347,10 +348,12 @@ public class RedactionIntegrationTest {
.build();
manualRedactions.setIdsToRemove(Set.of(IdRemoval.builder()
.id("0836727c3508a0b2ea271da69c04cc2f")
.approved(false)
.status(Status.REQUESTED)
.comments(List.of(comment))
.build()));
ManualRedactionEntry manualRedactionEntry = new ManualRedactionEntry();
manualRedactionEntry.setStatus(Status.REQUESTED);
manualRedactionEntry.setComments(List.of(comment));
manualRedactionEntry.setType("name");
manualRedactionEntry.setValue("O'Loughlin C.K.");