Pull request #11: RED-811: Added possiblity to select template, changed current template
Merge in RED/redaction-report-service from RED-811 to master * commit '0b98ed81f8c6e873bc2358ca31c0a9d8b1779996': RED-811: Added possiblity to select template, changed current template
This commit is contained in:
commit
e170e6327f
@ -17,7 +17,7 @@
|
||||
<dependency>
|
||||
<groupId>com.iqser.red.service</groupId>
|
||||
<artifactId>redaction-service-api-v1</artifactId>
|
||||
<version>1.5.4</version>
|
||||
<version>1.5.8</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- This dependency contains annotations that are used in specifying REST endpoints. -->
|
||||
|
||||
@ -16,4 +16,6 @@ public class MultiFileRedactionLog {
|
||||
|
||||
private List<RedactionLog> redactionLogs = new ArrayList<>();
|
||||
|
||||
private String template;
|
||||
|
||||
}
|
||||
|
||||
@ -15,6 +15,7 @@ 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.configuration.v1.api.model.LegalBasisMapping;
|
||||
@ -32,18 +33,30 @@ import lombok.RequiredArgsConstructor;
|
||||
public class ReportGenerationService {
|
||||
|
||||
private final LegalBasisMappingClient legalBasisMappingClient;
|
||||
private byte[] template;
|
||||
private byte[] efsaTemplate;
|
||||
private byte[] syngentaTemplate;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
|
||||
template = ResourceLoader.load("templates/EFSA Template 1.docx");
|
||||
efsaTemplate = ResourceLoader.load("templates/EFSA Template.docx");
|
||||
syngentaTemplate = ResourceLoader.load("templates/Syngenta Template.docx");
|
||||
}
|
||||
|
||||
|
||||
public byte[] generateReport(MultiFileRedactionLog multiFileRedactionLog) {
|
||||
|
||||
byte[] template;
|
||||
|
||||
if(multiFileRedactionLog.getTemplate().equals("EFSA Template")){
|
||||
template = efsaTemplate;
|
||||
} else if(multiFileRedactionLog.getTemplate().equals("Syngenta Template")){
|
||||
template = syngentaTemplate;
|
||||
} else {
|
||||
template = syngentaTemplate;
|
||||
}
|
||||
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
LegalBasisMapping legalBasisMapping = legalBasisMappingClient.getLegalBasisMapping();
|
||||
@ -60,13 +73,13 @@ public class ReportGenerationService {
|
||||
|
||||
XWPFTable table = doc.getTables().get(0);
|
||||
|
||||
multiFileRedactionLog.getRedactionLogs().forEach(fileRedactionLog -> {
|
||||
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);
|
||||
|
||||
XWPFTableRow singelColumnRow = table.createRow();
|
||||
singelColumnRow.getCell(3).getCTTc().newCursor().removeXml();
|
||||
singelColumnRow.getCell(2).getCTTc().newCursor().removeXml();
|
||||
singelColumnRow.getCell(1).getCTTc().newCursor().removeXml();
|
||||
setText(singelColumnRow.getCell(0), fileRedactionLog.getFilename());
|
||||
multiFileRedactionLog.getRedactionLogs().forEach(fileRedactionLog -> {
|
||||
|
||||
fileRedactionLog.getRedactionLogEntry().forEach(entry -> {
|
||||
|
||||
@ -94,10 +107,10 @@ public class ReportGenerationService {
|
||||
.collect(Collectors.toList());
|
||||
pages.forEach(page -> {
|
||||
XWPFTableRow row = table.createRow();
|
||||
setText(row.getCell(0), String.valueOf(page));
|
||||
setText(row.getCell(1), entry.getSection());
|
||||
setText(row.getCell(2), entry.getLegalBasis());
|
||||
setText(row.getCell(3), reasonByLegalBasis.get(entry.getLegalBasis()));
|
||||
setText(row.getCell(0), fileRedactionLog.getFilename());
|
||||
setText(row.getCell(1), String.valueOf(page));
|
||||
setText(row.getCell(2), entry.getSection());
|
||||
setText(row.getCell(3), entry.getLegalBasis() + " " + reasonByLegalBasis.get(entry.getLegalBasis()));
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -51,7 +51,7 @@ public class RedactionReportIntegrationTest {
|
||||
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
|
||||
|
||||
redactionLog.setFilename("TestFile");
|
||||
MultiFileRedactionLog multiFileRedactionLog = new MultiFileRedactionLog(List.of(redactionLog));
|
||||
MultiFileRedactionLog multiFileRedactionLog = new MultiFileRedactionLog(List.of(redactionLog), "EFSA Template");
|
||||
|
||||
ReportResult reportResult = redactionReportController.generateReport(multiFileRedactionLog);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user