Added new Templates
This commit is contained in:
parent
522bd6c106
commit
5708a2b9cd
@ -1,5 +1,5 @@
|
||||
package com.iqser.red.service.redaction.report.v1.api.model;
|
||||
|
||||
public enum ReportType {
|
||||
WORD_SINGLE_FILE_EFSA_TEMPLATE, WORD_SINGLE_FILE_SYNGENTA_TEMPLATE, EXCEL_MULTI_FILE, EXCEL_SINGLE_FILE
|
||||
WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE, WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE, EXCEL_MULTI_FILE, EXCEL_SINGLE_FILE
|
||||
}
|
||||
|
||||
@ -67,18 +67,18 @@ public class ReportGenerationService {
|
||||
storedFileInformation.add(new StoredFileInformation(fileId, redactionLog.getFilename(), storageId, ReportType.EXCEL_SINGLE_FILE));
|
||||
}
|
||||
|
||||
if (reportMessage.getReportTypes().contains(ReportType.WORD_SINGLE_FILE_EFSA_TEMPLATE)) {
|
||||
byte[] wordEFSATemplate = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_EFSA_TEMPLATE, reportEntries, redactionLog
|
||||
if (reportMessage.getReportTypes().contains(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE)) {
|
||||
byte[] wordEFSATemplate = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE, reportEntries, redactionLog
|
||||
.getFilename());
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), wordEFSATemplate);
|
||||
storedFileInformation.add(new StoredFileInformation(fileId, redactionLog.getFilename(), storageId, ReportType.WORD_SINGLE_FILE_EFSA_TEMPLATE));
|
||||
storedFileInformation.add(new StoredFileInformation(fileId, redactionLog.getFilename(), storageId, ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE));
|
||||
}
|
||||
|
||||
if (reportMessage.getReportTypes().contains(ReportType.WORD_SINGLE_FILE_SYNGENTA_TEMPLATE)) {
|
||||
byte[] wordSyngentaTemplate = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_SYNGENTA_TEMPLATE, reportEntries, redactionLog
|
||||
if (reportMessage.getReportTypes().contains(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE)) {
|
||||
byte[] wordSyngentaTemplate = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE, reportEntries, redactionLog
|
||||
.getFilename());
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), wordSyngentaTemplate);
|
||||
storedFileInformation.add(new StoredFileInformation(fileId, redactionLog.getFilename(), storageId, ReportType.WORD_SINGLE_FILE_SYNGENTA_TEMPLATE));
|
||||
storedFileInformation.add(new StoredFileInformation(fileId, redactionLog.getFilename(), storageId, ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE));
|
||||
}
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
@ -13,7 +13,6 @@ import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||
import org.apache.xmlbeans.XmlCursor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
@ -26,15 +25,15 @@ import lombok.RequiredArgsConstructor;
|
||||
@RequiredArgsConstructor
|
||||
public class WordReportGenerationService {
|
||||
|
||||
private byte[] efsaTemplate;
|
||||
private byte[] syngentaTemplate;
|
||||
private byte[] appendixA1Template;
|
||||
private byte[] appendixA2Template;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
efsaTemplate = ResourceLoader.load("templates/EFSA Template.docx");
|
||||
syngentaTemplate = ResourceLoader.load("templates/Syngenta Template.docx");
|
||||
appendixA1Template = ResourceLoader.load("templates/Sanitisation justification Appendix A1.docx");
|
||||
appendixA2Template = ResourceLoader.load("templates/Sanitisation justification Appendix A2.docx");
|
||||
}
|
||||
|
||||
|
||||
@ -42,12 +41,12 @@ public class WordReportGenerationService {
|
||||
|
||||
byte[] template;
|
||||
|
||||
if (reportType.equals(ReportType.WORD_SINGLE_FILE_EFSA_TEMPLATE)) {
|
||||
template = efsaTemplate;
|
||||
} else if (reportType.equals(ReportType.WORD_SINGLE_FILE_SYNGENTA_TEMPLATE)) {
|
||||
template = syngentaTemplate;
|
||||
if (reportType.equals(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE)) {
|
||||
template = appendixA1Template;
|
||||
} else if (reportType.equals(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE)) {
|
||||
template = appendixA2Template;
|
||||
} else {
|
||||
template = syngentaTemplate;
|
||||
template = appendixA2Template;
|
||||
}
|
||||
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
|
||||
@ -63,13 +62,13 @@ public class WordReportGenerationService {
|
||||
|
||||
private void addTableRows(XWPFDocument doc, List<ReportRedactionEntry> reportEntries, String filename) {
|
||||
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
XWPFTable table = doc.getTables().get(1);
|
||||
|
||||
XmlCursor cursor = table.getCTTbl().newCursor();
|
||||
XWPFParagraph newParagraph = doc.insertNewParagraph(cursor);
|
||||
XWPFRun run = newParagraph.createRun();
|
||||
run.setText("Applied rules: EFSA 1 (Vertebrate Authors)");
|
||||
run.setFontSize(10);
|
||||
// XmlCursor cursor = table.getCTTbl().newCursor();
|
||||
// XWPFParagraph newParagraph = doc.insertNewParagraph(cursor);
|
||||
// XWPFRun run = newParagraph.createRun();
|
||||
// run.setText("Applied rules: EFSA 1 (Vertebrate Authors)");
|
||||
// run.setFontSize(10);
|
||||
|
||||
reportEntries.forEach(entry -> {
|
||||
XWPFTableRow row = table.createRow();
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -73,7 +73,7 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
|
||||
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_EFSA_TEMPLATE, reportEntries, redactionLog
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE, reportEntries, redactionLog
|
||||
.getFilename());
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template.docx")) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user