From e7ea12a1b03f7f79e0f4fa12671f91ee326eef73 Mon Sep 17 00:00:00 2001 From: deiflaender Date: Wed, 22 Jul 2020 14:14:10 +0200 Subject: [PATCH] CodeStyle --- .../service/AnnotationHighlightService.java | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java index 565893c6..4b63523e 100644 --- a/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java +++ b/redaction-service-v1/redaction-service-server-v1/src/main/java/com/iqser/red/service/redaction/v1/server/visualization/service/AnnotationHighlightService.java @@ -36,8 +36,10 @@ import lombok.extern.slf4j.Slf4j; @Service @RequiredArgsConstructor public class AnnotationHighlightService { + private final DictionaryService dictionaryService; + public void highlight(PDDocument document, Document classifiedDoc, boolean flatRedaction) throws IOException { for (int page = 1; page <= document.getNumberOfPages(); page++) { @@ -98,18 +100,29 @@ public class AnnotationHighlightService { posXEnd = textPositions.getTextPositions().get(0).getYDirAdj() + 2; posXInit = textPositions.getTextPositions().get(0).getYDirAdj() - height; posYInit = textPositions.getTextPositions().get(0).getXDirAdj(); - posYEnd = textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getXDirAdj() - height + 4; + posYEnd = textPositions.getTextPositions() + .get(textPositions.getTextPositions().size() - 1) + .getXDirAdj() - height + 4; } else { posXInit = textPositions.getTextPositions().get(0).getXDirAdj(); - posXEnd = textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getXDirAdj() + textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getWidth() + 1; - posYInit = textPositions.getTextPositions().get(0).getPageHeight() - textPositions.getTextPositions().get(0).getYDirAdj() - 2; - posYEnd = textPositions.getTextPositions().get(0).getPageHeight() - textPositions.getTextPositions().get(textPositions.getTextPositions().size() - 1).getYDirAdj() + 2; + posXEnd = textPositions.getTextPositions() + .get(textPositions.getTextPositions().size() - 1) + .getXDirAdj() + textPositions.getTextPositions() + .get(textPositions.getTextPositions().size() - 1) + .getWidth() + 1; + posYInit = textPositions.getTextPositions() + .get(0) + .getPageHeight() - textPositions.getTextPositions().get(0).getYDirAdj() - 2; + posYEnd = textPositions.getTextPositions() + .get(0) + .getPageHeight() - textPositions.getTextPositions() + .get(textPositions.getTextPositions().size() - 1) + .getYDirAdj() + 2; } Rectangle textHighlightRectangle = new Rectangle(new Point(posXInit, posYInit), posXEnd - posXInit, posYEnd - posYInit + height, page); - List annotations = pdPage.getAnnotations(); PDAnnotationTextMarkup highlight = new PDAnnotationTextMarkup(PDAnnotationTextMarkup.SUB_TYPE_HIGHLIGHT); highlight.constructAppearances(); @@ -124,7 +137,8 @@ public class AnnotationHighlightService { if (!flatRedaction && !isHint(entity)) { highlight.setAnnotationName(entityPositionSequence.getId().toString()); highlight.setTitlePopup(entityPositionSequence.getId().toString()); - highlight.setContents("\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\n" + "In Section : \"" + entity.getHeadline() + "\""); + highlight.setContents("\nRule " + entity.getMatchedRule() + " matched\n\n" + entity.getRedactionReason() + "\n\n" + "In Section : \"" + entity + .getHeadline() + "\""); } highlight.setQuadPoints(toQuadPoints(textHighlightRectangle)); @@ -162,31 +176,32 @@ public class AnnotationHighlightService { // 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().getY() + rectangle.getHeight(), - rectangle.getTopLeft().getX() + rectangle.getWidth(), rectangle.getTopLeft().getY() + rectangle.getHeight()}; + return new float[]{rectangle.getTopLeft().getX(), rectangle.getTopLeft().getY(), 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()}; } private boolean isRedactionType(Entity entity) { + if (!entity.isRedaction()) { return false; } - if(isHint(entity)){ + if (isHint(entity)) { return false; } return true; } + private float[] getColor(Entity entity) { if (!entity.isRedaction() && !isHint(entity)) { return new float[]{0.627f, 0.627f, 0.627f}; } - if(!dictionaryService.getEntryColors().containsKey(entity.getType())){ + if (!dictionaryService.getEntryColors().containsKey(entity.getType())) { return dictionaryService.getEntryColors().get("default"); } @@ -194,14 +209,16 @@ public class AnnotationHighlightService { } - private boolean isHint(Entity entity){ + private boolean isHint(Entity entity) { // TODO in RED-161. - if(entity.getType().equalsIgnoreCase("vertebrate") || entity.getType().equalsIgnoreCase("no_redaction_indicator")){ + if (entity.getType().equalsIgnoreCase("vertebrate") || entity.getType() + .equalsIgnoreCase("no_redaction_indicator")) { return true; } return false; } + private void visualizeTextBlock(TextBlock textBlock, PDPageContentStream contentStream) throws IOException { contentStream.setStrokingColor(Color.LIGHT_GRAY); @@ -226,13 +243,15 @@ public class AnnotationHighlightService { private void visualizeTable(Table table, PDPageContentStream contentStream) throws IOException { + for (List row : table.getRows()) { for (Cell cell : row) { if (cell != null) { contentStream.setLineWidth(0.5f); contentStream.setStrokingColor(Color.CYAN); - contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(), (float) cell.getHeight()); + contentStream.addRect((float) cell.getX(), (float) cell.getY(), (float) cell.getWidth(), (float) cell + .getHeight()); contentStream.stroke(); // contentStream.setStrokingColor(Color.GREEN); @@ -257,4 +276,5 @@ public class AnnotationHighlightService { contentStream.endText(); } } + } \ No newline at end of file