Merge branch 'RED-5624' into 'master'

RED-5624: Refactoring of justifications

Closes RED-5624

See merge request redactmanager/redaction-report-service!90
This commit is contained in:
Yannik Hampe 2024-08-12 11:03:02 +02:00
commit 673e754430
3 changed files with 112 additions and 95 deletions

View File

@ -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 {

View File

@ -70,8 +70,8 @@ public class EntityLogConverterService {
private Map<String, String> fillMapOfTypeAndEntityDisplayName(String dossierId) {
List<Type> 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<String, String> 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<EntityLogLegalBasis> 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()

View File

@ -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<EntityLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLog, legalBasisMapping, Map.of("signature", "Signature", "logo", "Logo"));
List<ReportRedactionEntry> 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<EntityLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(entityLog);
List<ReportRedactionEntry> reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID,entityLog, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> 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<ReportRedactionEntry> reportEntriesSecondFile = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID, entityLogSecondFile, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> 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<EntityLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(entityLog);
List<ReportRedactionEntry> 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<EntityLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(entityLog);
List<ReportRedactionEntry> reportEntries = entityLogConverterService.convertAndSort(DOSSIER_ID, FILE_ID,entityLog, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> 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<EntityLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(entityLog);
List<ReportRedactionEntry> 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<Type> 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<String, String> entityDisplayNames = new HashMap<>();
for (var entry : entityLog.getEntityLogEntry()) {
@ -634,14 +641,14 @@ public class RedactionReportIntegrationTest {
private PlaceholderModel buildPlaceHolderModel(Map<String, String> dossierAttributes, Map<String, String> fileAttributes, List<ImagePlaceholder> 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<>());