RED-305: Added ids to manual redaction entries, RED-306: set redacet to false in redactionLog for manual deletions
This commit is contained in:
parent
65a29fb3a5
commit
e52a54b0a3
@ -2,7 +2,9 @@ package com.iqser.red.service.redaction.v1.server.visualization.service;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
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 {
|
||||
|
||||
Set<Integer> manualRedactionPages = getManualRedactionPages(manualRedactions);
|
||||
|
||||
for (int page = 1; page <= document.getNumberOfPages(); page++) {
|
||||
|
||||
PDPage pdPage = document.getPage(page - 1);
|
||||
|
||||
drawSectionFrames(document, classifiedDoc, flatRedaction, pdPage, page);
|
||||
|
||||
if (classifiedDoc.getEntities().get(page) == null) {
|
||||
continue;
|
||||
if (classifiedDoc.getEntities().get(page) != null) {
|
||||
addAnnotations(pdPage, classifiedDoc, flatRedaction, manualRedactions, page);
|
||||
}
|
||||
|
||||
addAnnotations(pdPage, classifiedDoc, flatRedaction, manualRedactions, page);
|
||||
addManualAnnotations(pdPage, classifiedDoc, manualRedactions, page);
|
||||
if (manualRedactionPages.contains(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 {
|
||||
|
||||
List<PDAnnotation> annotations = pdPage.getAnnotations();
|
||||
@ -77,8 +99,11 @@ public class AnnotationHighlightService {
|
||||
|
||||
if (manualRedactions != null && manualRedactions.getIdsToRemove()
|
||||
.contains(entityPositionSequence.getId())) {
|
||||
String manualOverrideReason = entity.getRedactionReason() + ", removed by manual override";
|
||||
entity.setRedaction(false);
|
||||
entity.setRedactionReason(entity.getRedactionReason() + ", removed by manual override");
|
||||
entity.setRedactionReason(manualOverrideReason);
|
||||
redactionLogEntry.setRedacted(false);
|
||||
redactionLogEntry.setReason(manualOverrideReason);
|
||||
redactionLogEntry.setManual(true);
|
||||
}
|
||||
|
||||
@ -107,28 +132,34 @@ public class AnnotationHighlightService {
|
||||
|
||||
String id = IdBuilder.buildId(manualRedactionEntry);
|
||||
|
||||
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry);
|
||||
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, id);
|
||||
|
||||
boolean foundOnPage = false;
|
||||
for (Rectangle rectangle : manualRedactionEntry.getPositions()) {
|
||||
|
||||
if (page != rectangle.getPage()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foundOnPage = true;
|
||||
|
||||
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
|
||||
.getType()), true);
|
||||
annotations.add(highlight);
|
||||
|
||||
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()
|
||||
.id(id)
|
||||
.color(getColor(manualRedactionEntry.getType()))
|
||||
.reason(manualRedactionEntry.getReason())
|
||||
.value(manualRedactionEntry.getValue())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user