Refactor multiple positions to one

This commit is contained in:
Thierry Göckel 2020-09-28 17:47:55 +02:00
parent 5448153096
commit 6638f0cf9e
5 changed files with 25 additions and 38 deletions

View File

@ -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.Data;
import lombok.NoArgsConstructor;
@ -15,7 +12,7 @@ public class ManualRedactionEntry {
private String type;
private String value;
private String reason;
private List<Rectangle> positions = new ArrayList<>();
private Rectangle position;
private String section;
private int sectionNumber;

View File

@ -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;
@ -23,8 +20,7 @@ public class RedactionLogEntry {
private String section;
private float[] color;
@Builder.Default
private List<Rectangle> positions = new ArrayList<>();
private Rectangle position;
private int sectionNumber;
private boolean manual;

View File

@ -213,11 +213,10 @@ public class EntityRedactionService {
for (TextBlock textBlock : textBlocks) {
for (ManualRedactionEntry manualRedactionEntry : manualRedactions.getEntriesToAdd()) {
for (Rectangle rectangle : manualRedactionEntry.getPositions()) {
if (textBlock.contains(rectangle)) {
manualRedactionEntry.setSection(section);
manualRedactionEntry.setSectionNumber(sectionNumber);
}
Rectangle rectangle = manualRedactionEntry.getPosition();
if (textBlock.contains(rectangle)) {
manualRedactionEntry.setSection(section);
manualRedactionEntry.setSectionNumber(sectionNumber);
}
}
}

View File

@ -73,11 +73,7 @@ public class AnnotationHighlightService {
return manualRedactionPages;
}
manualRedactions.getEntriesToAdd().forEach(entry -> {
entry.getPositions().forEach(pos -> {
manualRedactionPages.add(pos.getPage());
});
});
manualRedactions.getEntriesToAdd().forEach(entry -> manualRedactionPages.add(entry.getPosition().getPage()));
return manualRedactionPages;
}
@ -120,7 +116,7 @@ public class AnnotationHighlightService {
.mapToDouble(TextPositionSequence::getWidth)
.sum());
rectangle.setPage(page);
redactionLogEntry.getPositions().add(rectangle);
redactionLogEntry.setPosition(rectangle);
annotations.add(createAnnotation(rectangle, entityPositionSequence.getId(),
createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
}
@ -146,25 +142,19 @@ public class AnnotationHighlightService {
RedactionLogEntry redactionLogEntry = createRedactionLogEntry(manualRedactionEntry, id);
boolean foundOnPage = false;
for (Rectangle rectangle : manualRedactionEntry.getPositions()) {
Rectangle rectangle = manualRedactionEntry.getPosition();
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);
}
if (foundOnPage) {
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
if (page != rectangle.getPage()) {
continue;
}
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id,
createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
.getType()), true);
annotations.add(highlight);
redactionLogEntry.setPosition(rectangle);
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
}
}

View File

@ -325,7 +325,12 @@ public class RedactionIntegrationTest {
manualRedactionEntry.setType("name");
manualRedactionEntry.setValue("O'Loughlin C.K.");
manualRedactionEntry.setReason("Manual Redaction");
manualRedactionEntry.setPositions(List.of(new Rectangle(new Point(375.61096f, 241.282f), 7.648041f, 43.72262f, 1), new Rectangle(new Point(384.83517f, 241.282f), 7.648041f, 17.043358f, 1)));
Rectangle position = new Rectangle();
position.setTopLeft(new Point(375.61096f, 241.282f));
position.setHeight(43.72262f);
position.setWidth(15.296082f);
position.setPage(1);
manualRedactionEntry.setPosition(position);
manualRedactions.getEntriesToAdd().add(manualRedactionEntry);