RED-2337: Fix word report generation and update tests for redaction report

This commit is contained in:
aoezyetimoglu 2021-10-04 17:14:22 +02:00
parent c03acedcdd
commit 04ca2cf70e
3 changed files with 216 additions and 223 deletions

View File

@ -310,7 +310,6 @@ public class WordReportGenerationService {
private void setText(XWPFTableCell cell, String value) {
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
cell.removeParagraph(0);
XWPFParagraph addParagraph = cell.addParagraph();
XWPFRun run = addParagraph.createRun();
run.setFontSize(10);

View File

@ -12,6 +12,7 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import org.apache.commons.io.IOUtils;
@ -37,6 +38,7 @@ import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.do
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileAttributeType;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.legalbasis.LegalBasis;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.legalbasis.LegalBasisMapping;
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
@ -68,7 +70,7 @@ public class RedactionReportIntegrationTest {
private ReportTemplateClient reportTemplateClient;
@MockBean
private FileAttributesConfigClient fileAttributesClient;
private FileAttributesConfigClient fileAttributesConfigClient;
@MockBean
private AmazonS3 s3Client;
@ -91,7 +93,6 @@ public class RedactionReportIntegrationTest {
@Autowired
private ExcelTemplateReportGenerationService excelTemplateReportGenerationService;
@Test
public void testWordReportGeneration() throws IOException {
@ -160,7 +161,7 @@ public class RedactionReportIntegrationTest {
.type(FileAttributeType.TEXT)
.build();
when(fileAttributesClient.getFileAttributeConfigs(dossierTemplateId)).thenReturn(List.of(fileAttributeConfig1));
when(fileAttributesConfigClient.getFileAttributeConfigs(dossierTemplateId)).thenReturn(List.of(fileAttributeConfig1));
FileModel fileStatus = FileModel.builder().filename("filename").fileAttributes(Map.of("3e9b9569-5d2e-4619-848b-dd0a3e96527f","Test" )).build();
@ -190,224 +191,217 @@ public class RedactionReportIntegrationTest {
}
}
// TODO Reactivate Tests
// @Test
// public void testExcelTemplateReportGeneration() throws IOException {
//
// ClassPathResource redactionLogResource = new ClassPathResource("files/redactionLog.json");
// ClassPathResource excelRedactionLogResource = new ClassPathResource("files/excelReportRedactionLog.json");
// ClassPathResource imageResource = new ClassPathResource("files/exampleImage.jpg");
//
// RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
// RedactionLog redactionLog2 = objectMapper.readValue(excelRedactionLogResource.getInputStream(), RedactionLog.class);
//
// String dossierTemplateId = "dossierTemplateId";
// String storageId = "storageId";
// String templateId = "templateId";
//
// ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx");
// XSSFWorkbook workbook = new XSSFWorkbook(templateResource.getInputStream());
//
// ClassPathResource legalBasisMappingResource = new ClassPathResource("files/legalBasisMapping.json");
// List<LegalBasis> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
// });
// List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
// List<ReportRedactionEntry> reportEntries2 = redactionLogConverterService.convertAndSort(redactionLog2, legalBasisMapping);
//
// DossierAttributesConfig dossierAttributesConfig = new DossierAttributesConfig(Arrays.asList(new DossierAttributeConfig("id", "label", true, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.name}}"), new DossierAttributeConfig("id2", "label2", false, DossierAttributeConfig.DossierAttributeType.IMAGE, "{{dossier.attribute.image}}")));
// when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(dossierAttributesConfig);
//
// DossierAttributes dossierAttributes = new DossierAttributes(Arrays.asList(new DossierAttribute("id", "Michael"), new DossierAttribute("id2", Base64.getEncoder()
// .encodeToString(IOUtils.toByteArray(imageResource.getInputStream())))));
// when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(dossierAttributes);
//
// List<FileAttributeConfig> fileAttributeConfigs = new ArrayList<>();
// fileAttributeConfigs.add(new FileAttributeConfig("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "", "Document Title", true, true, false, false, FileAttributeConfig.FileAttributeType.TEXT, "{{file.attribute.placeholder}}"));
// FileAttributesConfig fileAttributesConfig = new FileAttributesConfig("", "", fileAttributeConfigs);
// when(fileAttributesClient.getFileAttributes(dossierTemplateId)).thenReturn(fileAttributesConfig);
//
// Map<String, String> attributeIdToValue = new HashMap();
// attributeIdToValue.put("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test");
// FileAttributes fileAttributes = new FileAttributes(attributeIdToValue);
// FileStatus fileStatus = FileStatus.builder().filename("filename").fileAttributes(fileAttributes).build();
// FileStatus fileStatus2 = FileStatus.builder().filename("other file").fileAttributes(fileAttributes).build();
//
// Dossier dossier = Dossier.builder().dossierId("dossierId").dossierName("dossierName").build();
//
// when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
// .dossierTemplateId(dossierTemplateId)
// .storageId(storageId)
// .build());
//
// excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileStatus, dossier, false);
// excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileStatus2, dossier, true);
// byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
//
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template.xlsx")) {
// fileOutputStream.write(excelTemplateReport);
// }
// }
//
//
// @Test
// public void testReportGeneration() 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<LegalBasisMapping> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
// });
//
// String dossierTemplateId = "dossierTemplateId";
// String storageId = "storageId";
// String templateId = "templateId";
//
// 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);
//
// DossierAttributesConfig dossierAttributesConfig = new DossierAttributesConfig(Arrays.asList(new DossierAttributeConfig("id", "label", true, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.name}}"), new DossierAttributeConfig("id2", "label2", false, DossierAttributeConfig.DossierAttributeType.IMAGE, "{{dossier.attribute.image}}")));
// when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(dossierAttributesConfig);
// DossierAttributes dossierAttributes = new DossierAttributes(Arrays.asList(new DossierAttribute("id", "Michael"), new DossierAttribute("id2", Base64.getEncoder()
// .encodeToString(IOUtils.toByteArray(imageResource.getInputStream())))));
// when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(dossierAttributes);
//
// List<FileAttributeConfig> fileAttributeConfigs = new ArrayList<>();
// fileAttributeConfigs.add(new FileAttributeConfig("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "", "Document Title", true, true, false, false, FileAttributeConfig.FileAttributeType.TEXT, "{{file.attribute.placeholder}}"));
// FileAttributesConfig fileAttributesConfig = new FileAttributesConfig("", "", fileAttributeConfigs);
// when(fileAttributesClient.getFileAttributes(dossierTemplateId)).thenReturn(fileAttributesConfig);
// Map<String, String> attributeIdToValue = new HashMap();
// attributeIdToValue.put("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test");
// FileAttributes fileAttributes = new FileAttributes(attributeIdToValue);
// FileStatus fileStatus = FileStatus.builder().filename("filename").fileAttributes(fileAttributes).build();
// FileStatus fileStatus2 = FileStatus.builder().filename("other file").fileAttributes(fileAttributes).build();
//
// Dossier dossier = Dossier.builder().dossierId("dossierId").dossierName("projectName").build();
//
// when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
// .dossierTemplateId(dossierTemplateId)
// .storageId(storageId)
// .build());
//
// ClassPathResource wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
// when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(wordTemplateResource.getInputStream()));
// ReportTemplate reportTemplate = ReportTemplate.builder()
// .dossierTemplateId("dossierTemplateId")
// .templateId("templateId")
// .fileName("fileName")
// .storageId("storageId")
// .uploadDate(OffsetDateTime.now())
// .build();
// byte[] wordReport = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileStatus, dossier);
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template.docx")) {
// fileOutputStream.write(wordReport);
// }
// ReportTemplate reportTemplate2 = ReportTemplate.builder()
// .dossierTemplateId("dossierTemplateId")
// .templateId("templateId")
// .fileName("fileNameReportTemplate2")
// .storageId("storageId")
// .uploadDate(OffsetDateTime.now())
// .build();
// byte[] wordReport2 = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries2, dossierTemplateId, reportTemplate2, fileStatus2, dossier);
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template2.docx")) {
// fileOutputStream.write(wordReport2);
// }
//
// ClassPathResource excelTemplateResource = new ClassPathResource("templates/Excel Report.xlsx");
// XSSFWorkbook workbook = new XSSFWorkbook(excelTemplateResource.getInputStream());
// excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileStatus, dossier, false);
// excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileStatus2, dossier, true);
// byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template.xlsx")) {
// fileOutputStream.write(excelTemplateReport);
// }
// XSSFWorkbook workbook2 = new XSSFWorkbook(excelTemplateResource.getInputStream());
// excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook2, fileStatus, dossier, true);
// byte[] excelTemplateReport2 = excelTemplateReportGenerationService.toByteArray(workbook2);
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template2.xlsx")) {
// fileOutputStream.write(excelTemplateReport2);
// }
// XSSFWorkbook workbook3 = new XSSFWorkbook(excelTemplateResource.getInputStream());
// excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook3, fileStatus2, dossier, true);
// byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(workbook3);
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template3.xlsx")) {
// fileOutputStream.write(excelTemplateReport3);
// }
// }
//
// @Test
// public void testExcerptReportGeneration() throws IOException {
//
// String dossierTemplateId = "dossierTemplateId";
//
// ClassPathResource redactionLogResource = new ClassPathResource("files/S11RedactionLog.json");
// ClassPathResource imageResource = new ClassPathResource("files/exampleImage.jpg");
//
// RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
//
// ClassPathResource legalBasisMappingResource = new ClassPathResource("files/S1116LegalBasis.json");
//
// List<LegalBasisMapping> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
// });
//
// List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
//
// DossierAttributesConfig dossierAttributesConfig = new DossierAttributesConfig(Arrays.asList(
// new DossierAttributeConfig("id", "Active Substance", true, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.ActiveSubstance}}"),
// new DossierAttributeConfig("id2", "Rapporteur Member State", false, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.RapporteurMemberState}}"),
// new DossierAttributeConfig("id3", "Dossier Name", true, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.Name}}"),
// new DossierAttributeConfig("id4", "Company", false, DossierAttributeConfig.DossierAttributeType.TEXT, "{{dossier.attribute.Company}}"),
// new DossierAttributeConfig("id5", "Date", true, DossierAttributeConfig.DossierAttributeType.DATE, "{{dossier.attribute.Date}}"),
// new DossierAttributeConfig("id6", "Signature", false, DossierAttributeConfig.DossierAttributeType.IMAGE, "{{dossier.attribute.Signature}}")));
// when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(dossierAttributesConfig);
//
// DossierAttributes dossierAttributes = new DossierAttributes(Arrays.asList(
// new DossierAttribute("id", "Aktive Substanz"),
// new DossierAttribute("id2", "Reporter Status"),
// new DossierAttribute("id3", "Dossier Name"),
// new DossierAttribute("id4", "Firma"),
// new DossierAttribute("id5", OffsetDateTime.now().format(FORMAT_DATE_ENG)),
// new DossierAttribute("id6", "data:image/png;base64," + Base64.getEncoder().encodeToString(IOUtils.toByteArray(imageResource.getInputStream())))));
//
// when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(dossierAttributes);
//
// List<FileAttributeConfig> fileAttributeConfigs = new ArrayList<>();
// fileAttributeConfigs.add(new FileAttributeConfig("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "", "Document Title", true, true, false, false, FileAttributeConfig.FileAttributeType.TEXT, "{{file.attribute.placeholder}}"));
// FileAttributesConfig fileAttributesConfig = new FileAttributesConfig("", "", fileAttributeConfigs);
// when(fileAttributesClient.getFileAttributes(dossierTemplateId)).thenReturn(fileAttributesConfig);
//
// Map<String, String> attributeIdToValue = new HashMap();
// attributeIdToValue.put("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test");
//
// FileAttributes fileAttributes = new FileAttributes(attributeIdToValue);
// FileStatus fileStatus = FileStatus.builder().filename("filename").fileAttributes(fileAttributes).build();
//
// Dossier project = Dossier.builder().dossierId("dossierId").dossierName("projectName").build();
//
// String templateId = "templateId";
// String storageId = "storageId";
// when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
// .dossierTemplateId(dossierTemplateId)
// .storageId(storageId)
// .build());
//
// ClassPathResource templateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx");
// when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
// ReportTemplate reportTemplate = ReportTemplate.builder()
// .dossierTemplateId("dossierTemplateId")
// .templateId("templateId")
// .fileName("filename")
// .storageId("storageId")
// .uploadDate(OffsetDateTime.now())
// .build();
// byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileStatus, project);
//
// try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template13.docx")) {
// fileOutputStream.write(report);
// }
// }
@Test
public void testExcelTemplateReportGeneration() throws IOException {
ClassPathResource redactionLogResource = new ClassPathResource("files/redactionLog.json");
ClassPathResource excelRedactionLogResource = new ClassPathResource("files/excelReportRedactionLog.json");
ClassPathResource imageResource = new ClassPathResource("files/exampleImage.jpg");
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
RedactionLog redactionLog2 = objectMapper.readValue(excelRedactionLogResource.getInputStream(), RedactionLog.class);
String dossierTemplateId = "dossierTemplateId";
String storageId = "storageId";
String templateId = "templateId";
String dossierId = "dossierId";
ClassPathResource templateResource = new ClassPathResource("templates/Excel Report.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(templateResource.getInputStream());
ClassPathResource legalBasisMappingResource = new ClassPathResource("files/legalBasisMapping.json");
List<LegalBasis> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
List<ReportRedactionEntry> reportEntries2 = redactionLogConverterService.convertAndSort(redactionLog2, legalBasisMapping);
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "label", true, "{{dossier.attribute.name}}", DossierAttributeType.TEXT, dossierTemplateId);//
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "label2", false, "{{dossier.attribute.image}}", DossierAttributeType.IMAGE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2));
DossierAttribute dossierAttribute = new DossierAttribute(dossierId, dossierAttributeConfig.getId(), "Michael");
DossierAttribute dossierAttribute2 = new DossierAttribute(dossierId, dossierAttributeConfig2.getId(), Base64.getEncoder().encodeToString(IOUtils.toByteArray(imageResource.getInputStream())));
when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(List.of(dossierAttribute, dossierAttribute2));
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("dossierName").build();
when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
.dossierTemplateId(dossierTemplateId)
.storageId(storageId)
.build());
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template.xlsx")) {
fileOutputStream.write(excelTemplateReport);
}
}
@Test
public void testReportGeneration() 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);
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "label", true, "{{dossier.attribute.name}}", DossierAttributeType.TEXT, dossierTemplateId);
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "label2", false, "{{dossier.attribute.image}}", DossierAttributeType.IMAGE, dossierTemplateId);
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2));
DossierAttribute dossierAttribute = new DossierAttribute(dossierId, "id", "Michael");
DossierAttribute dossierAttribute2 = new DossierAttribute(dossierId, "id2", Base64.getEncoder().encodeToString(IOUtils.toByteArray(imageResource.getInputStream())));
when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(List.of(dossierAttribute, dossierAttribute2));
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 wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(wordTemplateResource.getInputStream()));
ReportTemplate reportTemplate = ReportTemplate.builder()
.dossierTemplateId("dossierTemplateId")
.templateId("templateId")
.fileName("fileName")
.storageId("storageId")
.uploadDate(OffsetDateTime.now())
.build();
byte[] wordReport = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileModel, dossier);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template.docx")) {
fileOutputStream.write(wordReport);
}
ReportTemplate reportTemplate2 = ReportTemplate.builder()
.dossierTemplateId("dossierTemplateId")
.templateId("templateId")
.fileName("fileNameReportTemplate2")
.storageId("storageId")
.uploadDate(OffsetDateTime.now())
.build();
byte[] wordReport2 = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries2, dossierTemplateId, reportTemplate2, fileModel2, dossier);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template2.docx")) {
fileOutputStream.write(wordReport2);
}
ClassPathResource excelTemplateResource = new ClassPathResource("templates/Excel Report.xlsx");
XSSFWorkbook workbook = new XSSFWorkbook(excelTemplateResource.getInputStream());
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template.xlsx")) {
fileOutputStream.write(excelTemplateReport);
}
XSSFWorkbook workbook2 = new XSSFWorkbook(excelTemplateResource.getInputStream());
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook2, fileModel, dossier, true);
byte[] excelTemplateReport2 = excelTemplateReportGenerationService.toByteArray(workbook2);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template2.xlsx")) {
fileOutputStream.write(excelTemplateReport2);
}
XSSFWorkbook workbook3 = new XSSFWorkbook(excelTemplateResource.getInputStream());
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook3, fileModel2, dossier, true);
byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(workbook3);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/report_excel_template3.xlsx")) {
fileOutputStream.write(excelTemplateReport3);
}
}
@Test
public void testExcerptReportGeneration() throws IOException {
String dossierTemplateId = "dossierTemplateId";
String dossierId = "dossierId";
ClassPathResource redactionLogResource = new ClassPathResource("files/S11RedactionLog.json");
ClassPathResource imageResource = new ClassPathResource("files/exampleImage.jpg");
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
ClassPathResource legalBasisMappingResource = new ClassPathResource("files/S1116LegalBasis.json");
List<LegalBasis> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
});
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
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");
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", OffsetDateTime.now().format(FORMAT_DATE_ENG));
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();
Dossier project = Dossier.builder().id("dossierId").dossierName("projectName").build();
String templateId = "templateId";
String storageId = "storageId";
when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
.dossierTemplateId(dossierTemplateId)
.storageId(storageId)
.build());
ClassPathResource templateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx");
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
ReportTemplate reportTemplate = ReportTemplate.builder()
.dossierTemplateId("dossierTemplateId")
.templateId("templateId")
.fileName("filename")
.storageId("storageId")
.uploadDate(OffsetDateTime.now())
.build();
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileModel, project);
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template13.docx")) {
fileOutputStream.write(report);
}
}
}