Pull request #47: RED-373: Use a single multiline annotation instead of seperate annotations per line for one Entity

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

* commit 'dd02296face3c32bf7675301cf9969103e65f52f':
  Changed formating
  RED-373: Use a single multiline annotation instead of seperate annotations per line for one Entity
This commit is contained in:
Dominique Eiflaender 2020-10-01 12:47:58 +02:00
commit 107dbe1910

View File

@ -111,19 +111,20 @@ public class AnnotationHighlightService {
}
if (CollectionUtils.isNotEmpty(entityPositionSequence.getSequences())) {
for (Rectangle rectangle : getRectanglesPerLine(entityPositionSequence.getSequences()
List<Rectangle> rectanglesPerline = getRectanglesPerLine(entityPositionSequence.getSequences()
.stream()
.flatMap(seq -> seq.getTextPositions().stream())
.collect(Collectors.toList()), page)) {
redactionLogEntry.getPositions().add(rectangle);
annotations.add(createAnnotation(rectangle, entityPositionSequence.getId(),
createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
}
.collect(Collectors.toList()), page);
redactionLogEntry.getPositions().addAll(rectanglesPerline);
annotations.add(createAnnotation(rectanglesPerline, entityPositionSequence.getId(), createAnnotationContent(entity), getColor(entity), !flatRedaction && !isHint(entity)));
}
redactionLogEntry.setId(entityPositionSequence.getId());
}
classifiedDoc.getRedactionLogEntities().add(redactionLogEntry);
}
}
@ -176,8 +177,8 @@ public class AnnotationHighlightService {
foundOnPage = true;
PDAnnotationTextMarkup highlight = createAnnotation(rectangle, id,
createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry.getType()), true);
PDAnnotationTextMarkup highlight = createAnnotation(List.of(rectangle), id, createAnnotationContent(manualRedactionEntry), getColor(manualRedactionEntry
.getType()), true);
annotations.add(highlight);
redactionLogEntry.getPositions().add(rectangle);
@ -221,13 +222,13 @@ public class AnnotationHighlightService {
}
private PDAnnotationTextMarkup createAnnotation(Rectangle rectangle, String id, String content, float[] color,
boolean popup) {
private PDAnnotationTextMarkup createAnnotation(List<Rectangle> rectangles, String id, String content,
float[] color, boolean popup) {
PDAnnotationTextMarkup annotation = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT);
annotation.constructAppearances();
annotation.setRectangle(toPDRectangle(rectangle));
annotation.setQuadPoints(toQuadPoints(rectangle));
annotation.setRectangle(toPDRectangle(rectangles.get(0)));
annotation.setQuadPoints(toQuadPoints(rectangles));
if (popup) {
annotation.setAnnotationName(id);
annotation.setTitlePopup(id);
@ -240,8 +241,7 @@ public class AnnotationHighlightService {
private String createAnnotationContent(Entity entity) {
return "\nRule " + entity.getMatchedRule() + " matched" + "\n\n" + entity.getRedactionReason() + "\n\nIn " +
"Section : \"" + entity
return "\nRule " + entity.getMatchedRule() + " matched" + "\n\n" + entity.getRedactionReason() + "\n\nIn " + "Section : \"" + entity
.getHeadline() + "\"";
}
@ -263,13 +263,28 @@ public class AnnotationHighlightService {
}
private float[] toQuadPoints(Rectangle rectangle) {
private float[] toQuadPoints(List<Rectangle> rectangles) {
float[] quadPoints = new float[rectangles.size() * 8];
int i = 0;
for (Rectangle rectangle : rectangles) {
float[] quadPoint = toQuadPoint(rectangle);
for (int j = 0; j <= 7; j++) {
quadPoints[i + j] = quadPoint[j];
}
i += 8;
}
return quadPoints;
}
private float[] toQuadPoint(Rectangle rectangle) {
// quadPoints is array of x,y coordinates in Z-like order (top-left, top-right, bottom-left,bottom-right)
// of the area to be highlighted
return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), rectangle.getTopLeft()
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(),
rectangle.getTopLeft()
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY(), rectangle.getTopLeft().getX(), rectangle.getTopLeft()
.getY() + rectangle.getHeight(), rectangle.getTopLeft()
.getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()};
}
@ -319,8 +334,7 @@ public class AnnotationHighlightService {
return;
}
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage,
PDPageContentStream.AppendMode.APPEND, true);
PDPageContentStream contentStream = new PDPageContentStream(document, pdPage, PDPageContentStream.AppendMode.APPEND, true);
for (Paragraph paragraph : classifiedDoc.getParagraphs()) {
for (int i = 0; i <= paragraph.getPageBlocks().size() - 1; i++) {
@ -369,8 +383,7 @@ public class AnnotationHighlightService {
if (cell != null) {
contentStream.setLineWidth(0.5f);
contentStream.setStrokingColor(Color.CYAN);
contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(),
(float) cell
contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(), (float) cell
.getHeight());
contentStream.stroke();
}