diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelTemplateReportGenerationService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelTemplateReportGenerationService.java index 3128e86..bd86af1 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelTemplateReportGenerationService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelTemplateReportGenerationService.java @@ -11,9 +11,11 @@ import static com.iqser.red.service.redaction.report.v1.server.service.Placehold import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ISO_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO_PLACEHOLDER; +import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PARAGRAPH_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_REASON_PLACEHOLDER; +import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_TEXT_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PAGE_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PARAGRAPH_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.REDACTION_VALUE_PLACEHOLDER; @@ -213,7 +215,7 @@ public class ExcelTemplateReportGenerationService { private boolean containsRedactionPlaceholder(String text) { - return text.contains(FILE_NAME_PLACEHOLDER) || text.contains(PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER); + return text.contains(FILE_NAME_PLACEHOLDER) || text.contains(PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER) || text.contains(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || text.contains(JUSTIFICATION_TEXT_PLACEHOLDER); } @@ -237,6 +239,12 @@ public class ExcelTemplateReportGenerationService { if (placeholder.equals(JUSTIFICATION_REASON_PLACEHOLDER)) { return entry.getJustificationReason(); } + if (placeholder.equals(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER)) { + return entry.getJustificationParagraph(); + } + if (placeholder.equals(JUSTIFICATION_TEXT_PLACEHOLDER)) { + return entry.getJustificationReason(); + } if (placeholder.equals(EXCERPT_PLACEHOLDER)) { return entry.getExcerpt(); } @@ -273,7 +281,8 @@ public class ExcelTemplateReportGenerationService { // ByteArrayInputStream scaledImage = getScaledImage(is, PixelUtil.widthUnits2Pixel((short) sheet.getColumnWidth(cell.getColumnIndex())), PixelUtil.heightUnits2Pixel(cell.getRow().getHeight())); // is.reset(); - double factor = calculateScale(is, PixelUtil.widthUnits2Pixel((short) sheet.getColumnWidth(cell.getColumnIndex())), PixelUtil.heightUnits2Pixel(cell.getRow().getHeight())); + double factor = calculateScale(is, PixelUtil.widthUnits2Pixel((short) sheet.getColumnWidth(cell.getColumnIndex())), PixelUtil.heightUnits2Pixel(cell.getRow() + .getHeight())); is.reset(); int pictureIdx = workbook.addPicture(is, XSSFWorkbook.PICTURE_TYPE_JPEG); @@ -302,16 +311,18 @@ public class ExcelTemplateReportGenerationService { } - private double calculateScale(ByteArrayInputStream imageByteArrayInputStream, float cellWidth, float cellHeight) throws IOException { + private double calculateScale(ByteArrayInputStream imageByteArrayInputStream, float cellWidth, + float cellHeight) throws IOException { + BufferedImage img = ImageIO.read(imageByteArrayInputStream); double imageWidth = img.getWidth(); double imageHeight = img.getHeight(); - double widthFactor = (double) cellWidth/ imageWidth; - double heightFactor = (double) cellHeight/ imageHeight; + double widthFactor = (double) cellWidth / imageWidth; + double heightFactor = (double) cellHeight / imageHeight; - if (imageWidth < cellWidth && imageHeight < cellHeight) { + if (imageWidth < cellWidth && imageHeight < cellHeight) { return 1; } else if (cellWidth > cellHeight) { return heightFactor; @@ -347,7 +358,6 @@ public class ExcelTemplateReportGenerationService { if (fileAttributePlaceholders.containsKey(placeholder)) { String id = fileAttributePlaceholders.get(placeholder); - if (fileStatus.getFileAttributes().containsKey(id)) { return fileStatus.getFileAttributes().get(id); } else { @@ -360,6 +370,7 @@ public class ExcelTemplateReportGenerationService { throw new RuntimeException("unknown placeholder"); } + @SneakyThrows public byte[] toByteArray(XSSFWorkbook workbook) { diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/PlaceholderService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/PlaceholderService.java index f41af3e..94dd45c 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/PlaceholderService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/PlaceholderService.java @@ -18,7 +18,9 @@ public class PlaceholderService { public static final String PARAGRAPH_PLACEHOLDER = "{{redaction.paragraph}}"; public static final String JUSTIFICATION_PLACEHOLDER = "{{redaction.justification}}"; public static final String JUSTIFICATION_PARAGRAPH_PLACEHOLDER = "{{redaction.justificationParagraph}}"; + public static final String JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER = "{{redaction.justificationLegalBasis}}"; public static final String JUSTIFICATION_REASON_PLACEHOLDER = "{{redaction.justificationReason}}"; + public static final String JUSTIFICATION_TEXT_PLACEHOLDER = "{{redaction.justificationText}}"; public static final String EXCERPT_PLACEHOLDER = "{{redaction.excerpt}}"; public static final String REDACTION_VALUE_PLACEHOLDER = "{{redaction.value}}"; @@ -39,7 +41,7 @@ public class PlaceholderService { public List getGeneralPlaceholders() { - return List.of(FILE_NAME_PLACEHOLDER, PAGE_PLACEHOLDER, PARAGRAPH_PLACEHOLDER, JUSTIFICATION_PLACEHOLDER, JUSTIFICATION_PARAGRAPH_PLACEHOLDER, JUSTIFICATION_REASON_PLACEHOLDER, EXCERPT_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, REDACTION_VALUE_PLACEHOLDER); + return List.of(FILE_NAME_PLACEHOLDER, PAGE_PLACEHOLDER, PARAGRAPH_PLACEHOLDER, JUSTIFICATION_PLACEHOLDER, EXCERPT_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, REDACTION_VALUE_PLACEHOLDER, JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER, JUSTIFICATION_TEXT_PLACEHOLDER); } } diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java index 9773357..4fe35f2 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java @@ -12,9 +12,11 @@ import static com.iqser.red.service.redaction.report.v1.server.service.Placehold import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.IUCLID_FUNCTION_PLACEHOLDER; +import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PARAGRAPH_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_REASON_PLACEHOLDER; +import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_TEXT_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PAGE_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PARAGRAPH_PLACEHOLDER; import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.REDACTION_VALUE_PLACEHOLDER; @@ -111,7 +113,7 @@ public class WordReportGenerationService { if (dossierAttribute.getValue() == null) { dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), ""); } else { - if(attributeConfig.getType().equals(DossierAttributeType.DATE)) { + if (attributeConfig.getType().equals(DossierAttributeType.DATE)) { OffsetDateTime dt = OffsetDateTime.parse(dossierAttribute.getValue()); String date = FORMAT_DATE_ISO.format(dt); dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), date); @@ -243,8 +245,7 @@ public class WordReportGenerationService { run.setText("", 0); run.addBreak(); Dimension2DDouble dim = getImageDimension(is2); - run.addPicture(is2, XWPFDocument.PICTURE_TYPE_JPEG, "image.jpg", Units.toEMU(dim.getWidth()), Units.toEMU(dim - .getHeight())); + run.addPicture(is2, XWPFDocument.PICTURE_TYPE_JPEG, "image.jpg", Units.toEMU(dim.getWidth()), Units.toEMU(dim.getHeight())); int size = p.getRuns().size(); for (int i = 1; i < size; i++) { p.removeRun(1); @@ -315,8 +316,7 @@ public class WordReportGenerationService { for (XWPFTable tbl : doc.getTables()) { String tblText = tbl.getText(); - if (tblText.contains(PAGE_PLACEHOLDER) || tblText.contains(PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PLACEHOLDER) || tblText - .contains(EXCERPT_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_REASON_PLACEHOLDER)) { + if (tblText.contains(PAGE_PLACEHOLDER) || tblText.contains(PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PLACEHOLDER) || tblText.contains(EXCERPT_PLACEHOLDER) || tblText.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || tblText.contains(JUSTIFICATION_REASON_PLACEHOLDER) || tblText.contains(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || tblText.contains(JUSTIFICATION_TEXT_PLACEHOLDER)) { return tbl; } } @@ -326,9 +326,7 @@ public class WordReportGenerationService { private boolean containsRedactionPlaceholder(String text) { - return text.contains(FILE_NAME_PLACEHOLDER) || text.contains(PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text - .contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text - .contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER); + return text.contains(FILE_NAME_PLACEHOLDER) || text.contains(PAGE_PLACEHOLDER) || text.contains(PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_PLACEHOLDER) || text.contains(EXCERPT_PLACEHOLDER) || text.contains(JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER) || text.contains(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || text.contains(JUSTIFICATION_TEXT_PLACEHOLDER); } @@ -388,6 +386,12 @@ public class WordReportGenerationService { if (placeholder.equals(JUSTIFICATION_REASON_PLACEHOLDER)) { return entry.getJustificationReason(); } + if (placeholder.equals(JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER)) { + return entry.getJustificationParagraph(); + } + if (placeholder.equals(JUSTIFICATION_TEXT_PLACEHOLDER)) { + return entry.getJustificationReason(); + } if (placeholder.equals(EXCERPT_PLACEHOLDER)) { return entry.getExcerpt(); } diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/templates/6464 appendix_b EFSA dRAR justification.docx b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/templates/6464 appendix_b EFSA dRAR justification.docx index a5e3cd5..07f36e2 100644 Binary files a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/templates/6464 appendix_b EFSA dRAR justification.docx and b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/templates/6464 appendix_b EFSA dRAR justification.docx differ