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) { private void setText(XWPFTableCell cell, String value) {
cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
cell.removeParagraph(0);
XWPFParagraph addParagraph = cell.addParagraph(); XWPFParagraph addParagraph = cell.addParagraph();
XWPFRun run = addParagraph.createRun(); XWPFRun run = addParagraph.createRun();
run.setFontSize(10); run.setFontSize(10);

View File

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