diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/build.gradle.kts b/redaction-report-service-v1/redaction-report-service-server-v1/build.gradle.kts index d42a76f..ec2282a 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/build.gradle.kts +++ b/redaction-report-service-v1/redaction-report-service-server-v1/build.gradle.kts @@ -17,7 +17,7 @@ val storageCommonsVersion = "2.45.0" val lifecycleCommonsVersion = "0.4.0" val poiVersion = "5.2.3" val metricCommonsVersion = "2.1.0" -val persistenceServiceVersion = "2.467.0" +val persistenceServiceVersion = "2.509.0" val springBootStarterVersion = "3.2.3" configurations { diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/EntityLogConverterService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/EntityLogConverterService.java index e869924..f73ab12 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/EntityLogConverterService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/EntityLogConverterService.java @@ -70,8 +70,8 @@ public class EntityLogConverterService { private Map fillMapOfTypeAndEntityDisplayName(String dossierId) { List typeList = new ArrayList<>(); - typeList.addAll(dictionaryClient.getAllTypesForDossier(dossierId, false)); - typeList.addAll(dictionaryClient.getAllTypesForDossierTemplate(dossierClient.getDossierById(dossierId, true, false).getDossierTemplateId(), false)); + typeList.addAll(dictionaryClient.getAllTypesForDossier(dossierId, null, false)); + typeList.addAll(dictionaryClient.getAllTypesForDossierTemplate(dossierClient.getDossierById(dossierId, true, false).getDossierTemplateId(), null, false)); Map mapOfEntityDisplayName = new HashMap<>(); @@ -160,18 +160,10 @@ public class EntityLogConverterService { position.x(), position.y(), getSection(entry, position), - checkTextForNull(entry.getLegalBasis()) + " " + legalBasisMappings.stream() - .filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis())) - .findAny() - .map(EntityLogLegalBasis::getDescription) - .orElse(""), + checkTextForNull(entry.getLegalBasis()) + " " + getJustificationReason(legalBasisMappings, entry), entry.getLegalBasis(), entry.getParagraphPageIdx(), - legalBasisMappings.stream() - .filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis())) - .findAny() - .map(EntityLogLegalBasis::getDescription) - .orElse(""), + getJustificationReason(legalBasisMappings, entry), checkTextForNull(entry.getTextBefore()) + entry.getValue() + checkTextForNull(entry.getTextAfter()), entry.getValue(), mapOfEntityDisplayName.get(entry.getType()), @@ -195,6 +187,24 @@ public class EntityLogConverterService { } + private static String getJustificationReason(List legalBasisMappings, EntityLogEntry entry) { + + return legalBasisMappings.stream() + .filter((EntityLogLegalBasis lbm) -> { + if (lbm.getTechnicalName() == null) { + return false; + } + if (lbm.getTechnicalName().equalsIgnoreCase(entry.getLegalBasis())) { + return true; + } + return false; + }) + .findAny() + .map(EntityLogLegalBasis::getDescription) + .orElse(""); + } + + private static ManualChange getLastManualChange(EntityLogEntry entry) { return entry.getManualChanges() diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java index 4d90483..afbc2b5 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java @@ -168,17 +168,17 @@ public class RedactionReportIntegrationTest { var imageResource = new ClassPathResource("files/exampleImage.jpg"); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", - "Aktive Substanz \n Test Return", - "{{dossier.attribute.RapporteurMemberState}}", - "Reporter Status", - "{{dossier.attribute.Name}}", - "Dossier Name", - "{{dossier.attribute.Company}}", - "Firma", - "{{dossier.attribute.Date}}", - "2021-11-09T23:00:00.000Z"), - Map.of("{{file.attribute.placeholder}}", "Test"), - List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); + "Aktive Substanz \n Test Return", + "{{dossier.attribute.RapporteurMemberState}}", + "Reporter Status", + "{{dossier.attribute.Name}}", + "Dossier Name", + "{{dossier.attribute.Company}}", + "Firma", + "{{dossier.attribute.Date}}", + "2021-11-09T23:00:00.000Z"), + Map.of("{{file.attribute.placeholder}}", "Test"), + List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); @@ -205,17 +205,17 @@ public class RedactionReportIntegrationTest { var imageResource = new ClassPathResource("files/exampleImage.jpg"); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", - "Aktive Substanz \n Test Return", - "{{dossier.attribute.RapporteurMemberState}}", - "Reporter Status", - "{{dossier.attribute.Name}}", - "Dossier Name", - "{{dossier.attribute.Company}}", - "Firma", - "{{dossier.attribute.Date}}", - "2021-11-09T23:00:00.000Z"), - Map.of("{{file.attribute.placeholder}}", "Test"), - List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); + "Aktive Substanz \n Test Return", + "{{dossier.attribute.RapporteurMemberState}}", + "Reporter Status", + "{{dossier.attribute.Name}}", + "Dossier Name", + "{{dossier.attribute.Company}}", + "Firma", + "{{dossier.attribute.Date}}", + "2021-11-09T23:00:00.000Z"), + Map.of("{{file.attribute.placeholder}}", "Test"), + List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); @@ -277,7 +277,11 @@ public class RedactionReportIntegrationTest { EntityLog entityLog = objectMapper.readValue(new ClassPathResource("files/entityLog.json").getInputStream(), EntityLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLog, legalBasisMapping, Map.of("signature", "Signature", "logo", "Logo")); + List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, + FILE_ID, + entityLog, + legalBasisMapping, + Map.of("signature", "Signature", "logo", "Logo")); ClassPathResource templateResource = new ClassPathResource("templates/IUCLID_Template.docx"); XWPFDocument doc = new XWPFDocument(templateResource.getInputStream()); @@ -365,17 +369,17 @@ public class RedactionReportIntegrationTest { var imageResource = new ClassPathResource("files/exampleImage.jpg"); var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}", - "Aktive Substanz \n Test Return", - "{{dossier.attribute.RapporteurMemberState}}", - "Reporter Status", - "{{dossier.attribute.Name}}", - "Dossier Name", - "{{dossier.attribute.Company}}", - "Firma", - "{{dossier.attribute.Date}}", - "2021-11-09T23:00:00.000Z"), - Map.of("{{file.attribute.placeholder}}", "Test"), - List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); + "Aktive Substanz \n Test Return", + "{{dossier.attribute.RapporteurMemberState}}", + "Reporter Status", + "{{dossier.attribute.Name}}", + "Dossier Name", + "{{dossier.attribute.Company}}", + "Firma", + "{{dossier.attribute.Date}}", + "2021-11-09T23:00:00.000Z"), + Map.of("{{file.attribute.placeholder}}", "Test"), + List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream()); wordReportGenerationService.generateWordReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true); @@ -426,7 +430,7 @@ public class RedactionReportIntegrationTest { List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); Map mapOfEntityDisplayName = createEntityDisplayNames(entityLog); - List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID,entityLog, legalBasisMapping, mapOfEntityDisplayName); + List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLog, legalBasisMapping, mapOfEntityDisplayName); FileModel fileModel = FileModel.builder().filename("filename").build(); @@ -441,7 +445,11 @@ public class RedactionReportIntegrationTest { excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, false); EntityLog entityLogSecondFile = objectMapper.readValue(new ClassPathResource("files/entityLog.json").getInputStream(), EntityLog.class); - List reportEntriesSecondFile = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLogSecondFile, legalBasisMapping, mapOfEntityDisplayName); + List reportEntriesSecondFile = entityLogConverterService.convertAndSort(DOSSIER_ID, + FILE_ID, + entityLogSecondFile, + legalBasisMapping, + mapOfEntityDisplayName); FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build(); excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile, placeholders, @@ -503,41 +511,7 @@ public class RedactionReportIntegrationTest { List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); Map mapOfEntityDisplayName = createEntityDisplayNames(entityLog); - List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID,entityLog, legalBasisMapping, mapOfEntityDisplayName); - var imageResource = new ClassPathResource("files/exampleImage.jpg"); - - FileModel fileModel = FileModel.builder().filename("filename").build(); - - ClassPathResource templateResource = new ClassPathResource("templates/Excel Report_PlaceholderTest.xlsx"); - - var placeholders = buildPlaceHolderModel(Map.of("{{dossier_attribute.test1}}", "replaced_dossier_test1"), - Map.of("{{file_attribute.test1}}", "replaced_file_test1", "{{file_attribute.test2}}", "replaced_file_test2"), - List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); - - XSSFWorkbook readWorkbook = new XSSFWorkbook(templateResource.getInputStream()); - var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0), dossier.getDossierTemplateId()); - SXSSFWorkbook writeWorkbook = new SXSSFWorkbook(); - writeWorkbook.createSheet("Sheet1"); - excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, true); - - byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook); - try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/PlaceholderTest_justification.xlsx")) { - fileOutputStream.write(excelTemplateReport3); - } - } - - - - @Test - @SneakyThrows - public void testExcelReportWithPendingEntries() { - - Dossier dossier = prepareDossier(); - EntityLog entityLog = objectMapper.readValue(new ClassPathResource("files/entityLogWithPendingEntries.json").getInputStream(), EntityLog.class); - List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { - }); - Map mapOfEntityDisplayName = createEntityDisplayNames(entityLog); - List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID,entityLog, legalBasisMapping, mapOfEntityDisplayName); + List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLog, legalBasisMapping, mapOfEntityDisplayName); var imageResource = new ClassPathResource("files/exampleImage.jpg"); FileModel fileModel = FileModel.builder().filename("filename").build(); @@ -555,7 +529,40 @@ public class RedactionReportIntegrationTest { excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, true); byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook); - try (FileOutputStream fileOutputStream = new FileOutputStream( getTemporaryDirectory() + "Report_Without_Pending_Entries.xlsx")) { + try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/PlaceholderTest_justification.xlsx")) { + fileOutputStream.write(excelTemplateReport3); + } + } + + + @Test + @SneakyThrows + public void testExcelReportWithPendingEntries() { + + Dossier dossier = prepareDossier(); + EntityLog entityLog = objectMapper.readValue(new ClassPathResource("files/entityLogWithPendingEntries.json").getInputStream(), EntityLog.class); + List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { + }); + Map mapOfEntityDisplayName = createEntityDisplayNames(entityLog); + List reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLog, legalBasisMapping, mapOfEntityDisplayName); + var imageResource = new ClassPathResource("files/exampleImage.jpg"); + + FileModel fileModel = FileModel.builder().filename("filename").build(); + + ClassPathResource templateResource = new ClassPathResource("templates/Excel Report_PlaceholderTest.xlsx"); + + var placeholders = buildPlaceHolderModel(Map.of("{{dossier_attribute.test1}}", "replaced_dossier_test1"), + Map.of("{{file_attribute.test1}}", "replaced_file_test1", "{{file_attribute.test2}}", "replaced_file_test2"), + List.of(new ImagePlaceholder("{{dossier.attribute.Signature}}", IOUtils.toByteArray(imageResource.getInputStream())))); + + XSSFWorkbook readWorkbook = new XSSFWorkbook(templateResource.getInputStream()); + var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0), dossier.getDossierTemplateId()); + SXSSFWorkbook writeWorkbook = new SXSSFWorkbook(); + writeWorkbook.createSheet("Sheet1"); + excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, true); + + byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook); + try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "Report_Without_Pending_Entries.xlsx")) { fileOutputStream.write(excelTemplateReport3); } } @@ -615,8 +622,8 @@ public class RedactionReportIntegrationTest { t3.setLabel("Type 3"); t3.setType("Type 3"); List ednList = new ArrayList<>(Arrays.asList(t1, t2, t3)); - Mockito.when(dictionaryClient.getAllTypesForDossier(Mockito.anyString(), Mockito.anyBoolean())).thenReturn(ednList); - Mockito.when(dictionaryClient.getAllTypesForDossierTemplate(Mockito.any(), Mockito.anyBoolean())).thenReturn(ednList); + Mockito.when(dictionaryClient.getAllTypesForDossier(Mockito.anyString(), Mockito.anyLong(), Mockito.anyBoolean())).thenReturn(ednList); + Mockito.when(dictionaryClient.getAllTypesForDossierTemplate(Mockito.any(), Mockito.anyLong(), Mockito.anyBoolean())).thenReturn(ednList); Map entityDisplayNames = new HashMap<>(); for (var entry : entityLog.getEntityLogEntry()) { @@ -634,14 +641,14 @@ public class RedactionReportIntegrationTest { private PlaceholderModel buildPlaceHolderModel(Map dossierAttributes, Map fileAttributes, List imagePlaceholders) { var defaultPlaceHolder = new HashSet<>(Set.of(FILE_NAME_PLACEHOLDER, - FORMAT_DATE_ISO_PLACEHOLDER, - FORMAT_DATE_GER_PLACEHOLDER, - FORMAT_DATE_ENG_PLACEHOLDER, - FORMAT_TIME_ISO_PLACEHOLDER, - DOSSIER_NAME_PLACEHOLDER, - IUCLID_FUNCTION_PLACEHOLDER, - SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, - SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)); + FORMAT_DATE_ISO_PLACEHOLDER, + FORMAT_DATE_GER_PLACEHOLDER, + FORMAT_DATE_ENG_PLACEHOLDER, + FORMAT_TIME_ISO_PLACEHOLDER, + DOSSIER_NAME_PLACEHOLDER, + IUCLID_FUNCTION_PLACEHOLDER, + SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, + SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)); defaultPlaceHolder.addAll(dossierAttributes.keySet()); defaultPlaceHolder.addAll(fileAttributes.keySet()); return new PlaceholderModel(defaultPlaceHolder, imagePlaceholders, dossierAttributes, null, fileAttributes, new HashMap<>());