Pull request #37: RED-305: Added ids to manual redaction entries, RED-306: set redacet to false in redactionLog for manual deletions
Merge in RED/redaction-service from RED-305 to master * commit 'e52a54b0a3eb8491ed3e79b3f514364a5cf22f76': RED-305: Added ids to manual redaction entries, RED-306: set redacet to false in redactionLog for manual deletions
This commit is contained in:
commit
a0a78440d8
@ -2,7 +2,9 @@ package com.iqser.red.service.redaction.v1.server.visualization.service;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||||
@ -45,22 +47,42 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions) throws IOException {
|
public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions) throws IOException {
|
||||||
|
|
||||||
|
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
||||||
|
|
||||||
for (int page = 1; page <= document.getNumberOfPages(); page++) {
|
for (int page = 1; page <= document.getNumberOfPages(); page++) {
|
||||||
|
|
||||||
PDPage pdPage = document.getPage(page - 1);
|
PDPage pdPage = document.getPage(page - 1);
|
||||||
|
|
||||||
drawSectionFrames(document, classifiedDoc, flatRedaction, pdPage, page);
|
drawSectionFrames(document, classifiedDoc, flatRedaction, pdPage, page);
|
||||||
|
|
||||||
if (classifiedDoc.getEntities().get(page) == null) {
|
if (classifiedDoc.getEntities().get(page) != null) {
|
||||||
continue;
|
addAnnotations(pdPage, classifiedDoc, flatRedaction, manualRedactions, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
addAnnotations(pdPage, classifiedDoc, flatRedaction, manualRedactions, page);
|
if (manualRedactionPages.contains(page)) {
|
||||||
addManualAnnotations(pdPage, classifiedDoc, manualRedactions, page);
|
addManualAnnotations(pdPage, classifiedDoc, manualRedactions, page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<Integer> getManualRedactionPages(ManualRedactions manualRedactions) {
|
||||||
|
|
||||||
|
Set<Integer> manualRedactionPages = new HashSet<>();
|
||||||
|
|
||||||
|
if (manualRedactions == null) {
|
||||||
|
return manualRedactionPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
manualRedactions.getEntriesToAdd().forEach(entry -> {
|
||||||
|
entry.getPositions().forEach(pos -> {
|
||||||
|
manualRedactionPages.add(pos.getPage());
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return manualRedactionPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions, int page) throws IOException {
|
private void addAnnotations(PDPage pdPage, Document classifiedDoc, boolean flatRedaction, ManualRedactions manualRedactions, int page) throws IOException {
|
||||||
|
|
||||||
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
||||||
@ -77,8 +99,11 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
if (manualRedactions != null && manualRedactions.getIdsToRemove()
|
if (manualRedactions != null && manualRedactions.getIdsToRemove()
|
||||||
.contains(entityPositionSequence.getId())) {
|
.contains(entityPositionSequence.getId())) {
|
||||||
|
String manualOverrideReason = entity.getRedactionReason() + ", removed by manual override";
|
||||||
entity.setRedaction(false);
|
entity.setRedaction(false);
|
||||||
entity.setRedactionReason(entity.getRedactionReason() + ", removed by manual override");
|
entity.setRedactionReason(manualOverrideReason);
|
||||||
|
redactionLogEntry.setRedacted(false);
|
||||||
|
redactionLogEntry.setReason(manualOverrideReason);
|
||||||
redactionLogEntry.setManual(true);
|
redactionLogEntry.setManual(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,28 +132,34 @@ public class AnnotationHighlightService {
|
|||||||
|
|
||||||
String id = IdBuilder.buildId(manualRedactionEntry);
|
String id = IdBuilder.buildId(manualRedactionEntry);
|
||||||
|
|
||||||
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry);
|
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, id);
|
||||||
|
|
||||||
|
boolean foundOnPage = false;
|
||||||
for (Rectangle rectangle : manualRedactionEntry.getPositions()) {
|
for (Rectangle rectangle : manualRedactionEntry.getPositions()) {
|
||||||
|
|
||||||
if (page != rectangle.getPage()) {
|
if (page != rectangle.getPage()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foundOnPage = true;
|
||||||
|
|
||||||
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
||||||
.getType()), true);
|
.getType()), true);
|
||||||
annotations.add(highlight);
|
annotations.add(highlight);
|
||||||
|
|
||||||
redactionLogEntry.getPositions().add(rectangle);
|
redactionLogEntry.getPositions().add(rectangle);
|
||||||
}
|
}
|
||||||
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
|
if (foundOnPage) {
|
||||||
|
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private RedactionLogEntry createRedactionLogEntry(ManualRedactionEntry manualRedactionEntry) {
|
private RedactionLogEntry createRedactionLogEntry(ManualRedactionEntry manualRedactionEntry, String id) {
|
||||||
|
|
||||||
return RedactionLogEntry.builder()
|
return RedactionLogEntry.builder()
|
||||||
|
.id(id)
|
||||||
.color(getColor(manualRedactionEntry.getType()))
|
.color(getColor(manualRedactionEntry.getType()))
|
||||||
.reason(manualRedactionEntry.getReason())
|
.reason(manualRedactionEntry.getReason())
|
||||||
.value(manualRedactionEntry.getValue())
|
.value(manualRedactionEntry.getValue())
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user