diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RedactionLogConverterService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RedactionLogConverterService.java index f71e6ff..53de784 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RedactionLogConverterService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/RedactionLogConverterService.java @@ -5,9 +5,11 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Optional; import java.util.Set; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -56,7 +58,7 @@ public class RedactionLogConverterService { } var legalBasisMappings = redactionLog.getLegalBasis(); - return convertAndSort(redactionLog, legalBasisMappings, mapOfEntityDisplayName); + return convertAndSort(redactionLog, legalBasisMappings, mapOfEntityDisplayName, dossierId); } @@ -77,12 +79,17 @@ public class RedactionLogConverterService { } - public List convertAndSort(RedactionLog redactionLog, List legalBasisMappings, Map mapOfEntityDisplayName) { + public List convertAndSort(RedactionLog redactionLog, + List legalBasisMappings, + Map mapOfEntityDisplayName, + String dossierId) { List reportEntries = new ArrayList<>(); + var allTypes = dictionaryClient.getAllTypesForDossier(dossierId, false); + redactionLog.getRedactionLogEntry().forEach(entry -> { - var isSkipped = !entry.isRedacted() && !entry.isHint() && !entry.getType().equals("hint_only") && !entry.getType().equals("published_information"); + var isSkipped = !entry.isRedacted() && !entry.isHint() && !isHintType(allTypes, entry.getType()); if (entry.isRedacted() || isSkipped) { if (entry.lastChangeIsRemoved()) { @@ -199,4 +206,21 @@ public class RedactionLogConverterService { return "Text on page " + position.getPage(); } + + /* + This method catches types like hint_only or published_information + */ + private boolean isHintType(List types, String type) { + + var matchingTypes = getMatchingTypes(types, type); + Optional foundType = matchingTypes.stream().findFirst(); + return foundType.map(Type::isHint).orElse(false); + } + + + private List getMatchingTypes(List types, String type) { + + return types.stream().filter(t -> t.getType().equals(type)).collect(Collectors.toList()); + } + } 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 9af5354..43e7937 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 @@ -124,7 +124,7 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); var wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx"); var imageResource = new ClassPathResource("files/exampleImage.jpg"); @@ -161,7 +161,7 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); var wordTemplateResource = new ClassPathResource("templates/Justification Appendix A2.docx"); var imageResource = new ClassPathResource("files/exampleImage.jpg"); @@ -198,7 +198,7 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); FileModel fileStatus = FileModel.builder().filename("filename").build(); Dossier dossier = Dossier.builder().dossierName("dossierName").build(); @@ -224,7 +224,7 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); FileModel fileStatus = FileModel.builder().filename("filename").build(); Dossier dossier = Dossier.builder().dossierName("dossierName").build(); @@ -250,10 +250,10 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class); - List reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, new HashMap<>()); + List reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, new HashMap<>(), null); FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build(); FileModel fileStatus = FileModel.builder().filename("filename").build(); @@ -281,7 +281,7 @@ public class RedactionReportIntegrationTest { RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class); List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>()); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), null); var wordTemplateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx"); var imageResource = new ClassPathResource("files/exampleImage.jpg"); @@ -319,7 +319,7 @@ public class RedactionReportIntegrationTest { List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); Map mapOfEntityDisplayName = createEntityDisplayNames(redactionLog); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, null); FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(Map.of("TestAttribute", "Lorem Ipsum")).build(); @@ -349,7 +349,7 @@ public class RedactionReportIntegrationTest { List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); Map mapOfEntityDisplayName = createEntityDisplayNames(redactionLog); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, null); FileModel fileModel = FileModel.builder().filename("filename").build(); @@ -364,7 +364,7 @@ public class RedactionReportIntegrationTest { excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, false); RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class); - List reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName); + List reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName, null); FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build(); excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile, placeholders, @@ -390,7 +390,7 @@ public class RedactionReportIntegrationTest { List legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() { }); Map mapOfEntityDisplayName = createEntityDisplayNames(redactionLog); - List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName); + List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, null); var imageResource = new ClassPathResource("files/exampleImage.jpg"); FileModel fileModel = FileModel.builder().filename("filename").build();