Pull request #227: RED-6098: Changed check for skipped entries in report for not having Ignored Hints and Removed published information

Merge in RED/redaction-report-service from RED-6098-F to master

* commit '29c57a02b1f7812e65d99e1aee55bc793f9ec99f':
  RED-6098: removed logs for debugging
  RED-6098: fixed tests
  RED-6098: Added logs for debugging
  RED-6098: Added logs for debugging
  RED-6098: Added logs for debugging
  RED-6098: Added methods to get types which are hint and changed check for skipped entries in report accordingly
  RED-6098: Added methods to get types which are hint and changed check for skipped entries in report accordingly
  RED-6098: Added methods to get types which are hint and changed check for skipped entries in report accordingly
  RED-6098: Changed check for skipped entries in report for not having Ignored Hints and Removed published information
This commit is contained in:
Ali Oezyetimoglu 2023-04-26 09:41:48 +02:00
commit 8bc2f1e654
3 changed files with 84 additions and 34 deletions

View File

@ -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<ReportRedactionEntry> convertAndSort(RedactionLog redactionLog, List<RedactionLogLegalBasis> legalBasisMappings, Map<String, String> mapOfEntityDisplayName) {
public List<ReportRedactionEntry> convertAndSort(RedactionLog redactionLog,
List<RedactionLogLegalBasis> legalBasisMappings,
Map<String, String> mapOfEntityDisplayName,
String dossierId) {
List<ReportRedactionEntry> reportEntries = new ArrayList<>();
var allTypes = dictionaryClient.getAllTypesForDossierTemplate(dossierClient.getDossierById(dossierId, false, false).getDossierTemplateId(), false);
redactionLog.getRedactionLogEntry().forEach(entry -> {
var isSkipped = !entry.isRedacted() && !entry.isHint() && !entry.isManuallyRemoved();
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<Type> types, String type) {
var matchingTypes = getMatchingTypes(types, type);
Optional<Type> foundType = matchingTypes.stream().findFirst();
return foundType.map(Type::isHint).orElse(false);
}
private List<Type> getMatchingTypes(List<Type> types, String type) {
return types.stream().filter(t -> t.getType().equals(type)).collect(Collectors.toList());
}
}

View File

@ -10,6 +10,7 @@ import static com.iqser.red.service.redaction.report.v1.server.service.Placehold
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.utils.OsUtils.getTemporaryDirectory;
import static org.mockito.Mockito.when;
import java.io.FileOutputStream;
import java.util.ArrayList;
@ -49,6 +50,7 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.redactionlo
import com.iqser.red.service.redaction.report.v1.server.client.DictionaryClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateClient;
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
@ -116,21 +118,37 @@ public class RedactionReportIntegrationTest {
@MockBean
private DictionaryClient dictionaryClient;
@MockBean
private DossierClient dossierClient;
@SneakyThrows
private Dossier prepareDossier() {
var testDossier = new Dossier();
testDossier.setDossierName("Test Dossier");
testDossier.setDossierTemplateId("dossierTemplateId");
testDossier.setId("dossierId");
when(dossierClient.getDossierById("dossierId", false, false)).thenReturn(testDossier);
return testDossier;
}
@Test
@SneakyThrows
public void testWordJustificationAppendixA1() {
Dossier dossier = prepareDossier();
FileModel fileModel = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
var wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
var imageResource = new ClassPathResource("files/exampleImage.jpg");
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
@ -158,17 +176,17 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testWordJustificationAppendixA2() {
Dossier dossier = prepareDossier();
FileModel fileModel = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
var wordTemplateResource = new ClassPathResource("templates/Justification Appendix A2.docx");
var imageResource = new ClassPathResource("files/exampleImage.jpg");
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
"{{dossier.attribute.RapporteurMemberState}}",
@ -195,13 +213,13 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testWordIUCLIDFile() {
Dossier dossier = prepareDossier();
FileModel fileStatus = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
FileModel fileStatus = FileModel.builder().filename("filename").build();
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
ClassPathResource templateResource = new ClassPathResource("templates/IUCLID_Template.docx");
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
@ -221,13 +239,13 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testWordSeedReportSingleFile() {
Dossier dossier = prepareDossier();
FileModel fileStatus = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
FileModel fileStatus = FileModel.builder().filename("filename").build();
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
ClassPathResource templateResource = new ClassPathResource("templates/Seeds - New Justification Form.docx");
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
@ -247,17 +265,17 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testWordSeedReportMultiFile() {
Dossier dossier = prepareDossier();
FileModel fileStatus = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class);
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, new HashMap<>());
FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build();
FileModel fileStatus = FileModel.builder().filename("filename").build();
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
RedactionLog redactionLogSecondFile = objectMapper.readValue(new ClassPathResource("files/excelReportRedactionLog.json").getInputStream(), RedactionLog.class);
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
ClassPathResource templateResource = new ClassPathResource("templates/Seeds-NewJustificationForm.docx");
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
@ -278,17 +296,17 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testWord6464JustificationAppendix() {
Dossier dossier = prepareDossier();
FileModel fileModel = FileModel.builder().filename("filename").build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>());
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, new HashMap<>(), dossier.getDossierId());
var wordTemplateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx");
var imageResource = new ClassPathResource("files/exampleImage.jpg");
Dossier dossier = Dossier.builder().dossierName("dossierName").build();
FileModel fileModel = FileModel.builder().filename("filename").build();
var placeholders = buildPlaceHolderModel(Map.of("{{dossier.attribute.ActiveSubstance}}",
"Aktive Substanz \n Test Return",
"{{dossier.attribute.RapporteurMemberState}}",
@ -315,13 +333,15 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testExcelTemplateReportGenerationSingleFile() {
Dossier dossier = prepareDossier();
FileModel fileModel = FileModel.builder().filename("filename").dossierId(dossier.getDossierId()).fileAttributes(Map.of("TestAttribute", "Lorem Ipsum")).build();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLogWithManualRedactions.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(Map.of("TestAttribute", "Lorem Ipsum")).build();
ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx");
@ -331,7 +351,7 @@ public class RedactionReportIntegrationTest {
var excelModel = excelTemplateReportGenerationService.calculateExcelModel(readWorkbook.getSheetAt(0));
SXSSFWorkbook writeWorkbook = new SXSSFWorkbook();
writeWorkbook.createSheet("Sheet1");
excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, "dossierName", fileModel, excelModel, true);
excelTemplateReportGenerationService.generateExcelReport(reportEntries, placeholders, "test", writeWorkbook, dossier.getDossierName(), fileModel, excelModel, true);
byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(writeWorkbook);
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/Excel Report_justification.xlsx")) {
@ -345,11 +365,12 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testExcelTemplateReportGenerationMultiFile() {
Dossier dossier = prepareDossier();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
FileModel fileModel = FileModel.builder().filename("filename").build();
@ -364,7 +385,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<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> reportEntriesSecondFile = redactionLogConverterService.convertAndSort(redactionLogSecondFile, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
FileModel fileModelSecondFile = FileModel.builder().filename("secondFile").build();
excelTemplateReportGenerationService.generateExcelReport(reportEntriesSecondFile,
placeholders,
@ -386,11 +407,12 @@ public class RedactionReportIntegrationTest {
@SneakyThrows
public void testExcelPlaceholders() {
Dossier dossier = prepareDossier();
RedactionLog redactionLog = objectMapper.readValue(new ClassPathResource("files/redactionLog.json").getInputStream(), RedactionLog.class);
List<RedactionLogLegalBasis> legalBasisMapping = objectMapper.readValue(new ClassPathResource("files/legalBasisMapping.json").getInputStream(), new TypeReference<>() {
});
Map<String, String> mapOfEntityDisplayName = createEntityDisplayNames(redactionLog);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping, mapOfEntityDisplayName, dossier.getDossierId());
var imageResource = new ClassPathResource("files/exampleImage.jpg");
FileModel fileModel = FileModel.builder().filename("filename").build();
@ -418,10 +440,13 @@ public class RedactionReportIntegrationTest {
Type t1 = new Type();
t1.setLabel("Type 1");
t1.setType("Type 1");
Type t2 = new Type();
t2.setLabel("Type 2");
t2.setType("Type 2");
Type t3 = new Type();
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);

View File

@ -128,6 +128,7 @@ public class RedactionReportV2IntegrationTest {
testDossier.setId("dossierId");
when(dossierClient.getDossierById("dossierId", true, false)).thenReturn(testDossier);
when(dossierClient.getDossierById("dossierId", false, false)).thenReturn(testDossier);
var testDossierAttributes = new ArrayList<DossierAttribute>();
testDossierAttributes.add(DossierAttribute.builder().dossierId("dossierId").dossierAttributeConfigId("testDossierAttribute").value("Dossier Attribute Value").build());