Pull request #134: RED-3230: Placeholders in report for excluded file

Merge in RED/redaction-report-service from RED-3230-rrs3 to master

* commit 'e176388d1c34ef128229a1a99b26cf8528c9936a':
  RED-3230: Placeholders in report for excluded file
This commit is contained in:
Ali Oezyetimoglu 2022-01-20 09:31:56 +01:00
commit 7b080b3b48
2 changed files with 66 additions and 2 deletions

View File

@ -193,10 +193,12 @@ public class ExcelTemplateReportGenerationService {
sheet.shiftRows(rowIndex.get(), rowIndex.get() + reportEntries.size() - 1, reportEntries.size() - 1, true, true);
}
} else {
sheet.shiftRows(rowIndex.get(), rowIndex.get() + reportEntries.size(), reportEntries.size(), true, true);
if(!reportEntries.isEmpty()) {
sheet.shiftRows(rowIndex.get(), rowIndex.get() + reportEntries.size(), reportEntries.size(), true, true);
}
}
if(reportEntries.isEmpty()) {
if(reportEntries.isEmpty() && isLastFile) {
sheet.createRow(rowIndex.get());
for (Map.Entry<Integer, String> entry1 : placeholderCellPos.entrySet()) {
sheet.getRow(rowIndex.get()).createCell(entry1.getKey()).setCellValue("");

View File

@ -460,5 +460,67 @@ public class RedactionReportIntegrationTest {
}
}
@Test
public void testExcelReportGeneration() throws IOException {
ClassPathResource redactionLogResource = new ClassPathResource("files/redactionLog.json");
ClassPathResource redactionLogResource2 = new ClassPathResource("files/excelReportRedactionLog.json");
ClassPathResource imageResource = new ClassPathResource("files/exampleImage.jpg");
ClassPathResource legalBasisMappingResource = new ClassPathResource("files/legalBasisMapping.json");
List<LegalBasis> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
});
String dossierTemplateId = "dossierTemplateId";
String storageId = "storageId";
String templateId = "templateId";
String dossierId = "dossierId";
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
RedactionLog redactionLog2 = objectMapper.readValue(redactionLogResource2.getInputStream(), RedactionLog.class);
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
List<ReportRedactionEntry> reportEntries2 = redactionLogConverterService.convertAndSort(redactionLog2, legalBasisMapping);
List<ReportRedactionEntry> emptyReportEntries = new ArrayList<>();
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "Active Substance", true, "{{dossier.attribute.ActiveSubstance}}", DossierAttributeType.TEXT, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "Rapporteur Member State", false, "{{dossier.attribute.RapporteurMemberState}}", DossierAttributeType.TEXT, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig3 = new DossierAttributeConfig("id3", "Dossier Name", true, "{{dossier.attribute.Name}}", DossierAttributeType.TEXT, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig4 = new DossierAttributeConfig("id4", "Company", false, "{{dossier.attribute.Company}}", DossierAttributeType.TEXT, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig5 = new DossierAttributeConfig("id5", "Date", true, "{{dossier.attribute.Date}}", DossierAttributeType.DATE, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig6 = new DossierAttributeConfig("id6", "Signature", false, "{{dossier.attribute.Signature}}", DossierAttributeType.IMAGE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2, dossierAttributeConfig3, dossierAttributeConfig4, dossierAttributeConfig5, dossierAttributeConfig6));
DossierAttribute dossierAttribute = new DossierAttribute(dossierId, "id", "Aktive Substanz \n Test Return");
DossierAttribute dossierAttribute2 = new DossierAttribute(dossierId, "id2", "Reporter Status");
DossierAttribute dossierAttribute3 = new DossierAttribute(dossierId, "id3", "Dossier Name");
DossierAttribute dossierAttribute4 = new DossierAttribute(dossierId, "id4", "Firma");
DossierAttribute dossierAttribute5 = new DossierAttribute(dossierId, "id5", "2021-11-09T23:00:00.000Z");
DossierAttribute dossierAttribute6 = new DossierAttribute(dossierId, "id6", "data:image/png;base64," + Base64.getEncoder().encodeToString(IOUtils.toByteArray(imageResource.getInputStream())));
when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(List.of(dossierAttribute, dossierAttribute2, dossierAttribute3, dossierAttribute4, dossierAttribute5, dossierAttribute6));
FileAttributeConfig fileAttributeConfig = new FileAttributeConfig("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "", "Document Title", true, true, false, false, "{{file.attribute.placeholder}}", FileAttributeType.TEXT, dossierTemplateId);
when(fileAttributesConfigClient.getFileAttributeConfigs(dossierTemplateId)).thenReturn(List.of(fileAttributeConfig));
Map<String, String> attributeIdToValue = new HashMap();
attributeIdToValue.put("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test");
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(attributeIdToValue).build();
FileModel fileModel2 = FileModel.builder().filename("other file").fileAttributes(attributeIdToValue).build();
Dossier dossier = Dossier.builder().id("dossierId").dossierName("projectName").build();
when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
.dossierTemplateId(dossierTemplateId)
.storageId(storageId)
.build());
ClassPathResource excelTemplateResource = new ClassPathResource("templates/Excel Report.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(excelTemplateResource.getInputStream());
excelTemplateReportGenerationService.generateReport(emptyReportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/report_excel_templateAAA.xlsx")) {
fileOutputStream.write(excelTemplateReport);
}
}
}