RED-456: Changed to new template

This commit is contained in:
deiflaender 2020-11-20 13:42:46 +01:00
parent e1a5a7a545
commit 7be44a7f21
12 changed files with 86 additions and 445 deletions

View File

@ -17,7 +17,7 @@
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>redaction-service-api-v1</artifactId>
<version>1.3.3</version>
<version>1.4.7</version>
</dependency>
<dependency>
<!-- This dependency contains annotations that are used in specifying REST endpoints. -->

View File

@ -19,6 +19,11 @@
<artifactId>redaction-report-service-api-v1</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>configuration-service-api-v1</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>

View File

@ -10,13 +10,14 @@ import org.springframework.context.annotation.Import;
import org.springframework.scheduling.annotation.EnableAsync;
import com.iqser.red.commons.spring.DefaultWebMvcConfiguration;
import com.iqser.red.service.redaction.report.v1.server.client.LegalBasisMappingClient;
import com.iqser.red.service.redaction.report.v1.server.settings.RedactionReportSettings;
@EnableAsync
@EnableConfigurationProperties(RedactionReportSettings.class)
@SpringBootApplication(exclude = {SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class})
@Import(DefaultWebMvcConfiguration.class)
@EnableFeignClients // TODO specify basePackageClasses
@EnableFeignClients(basePackageClasses = {LegalBasisMappingClient.class})
public class Application {
/**

View File

@ -0,0 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client;
import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.configuration.v1.api.resource.LegalBasisMappingResource;
import com.iqser.red.service.configuration.v1.api.resource.RulesResource;
@FeignClient(name = "LegalBasisMappingResource", url = "http://" + RulesResource.SERVICE_NAME + ":8080")
public interface LegalBasisMappingClient extends LegalBasisMappingResource {
}

View File

@ -4,30 +4,41 @@ import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
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.springframework.stereotype.Service;
import com.iqser.red.service.configuration.v1.api.model.LegalBasisMapping;
import com.iqser.red.service.redaction.report.v1.api.model.MultiFileRedactionLog;
import com.iqser.red.service.redaction.report.v1.server.client.LegalBasisMappingClient;
import com.iqser.red.service.redaction.report.v1.server.utils.ResourceLoader;
import com.iqser.red.service.redaction.v1.model.ManualRedactionType;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import com.iqser.red.service.redaction.v1.model.Status;
import lombok.RequiredArgsConstructor;
@Service
@RequiredArgsConstructor
public class ReportGenerationService {
private final LegalBasisMappingClient legalBasisMappingClient;
private byte[] template;
@PostConstruct
public void init() {
template = ResourceLoader.load("templates/Appendix A2.docx");
template = ResourceLoader.load("templates/EFSA Template 1.docx");
}
@ -35,7 +46,8 @@ public class ReportGenerationService {
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
XWPFDocument doc = new XWPFDocument(is);
addTableRows(doc, multiFileRedactionLog);
LegalBasisMapping legalBasisMapping = legalBasisMappingClient.getLegalBasisMapping();
addTableRows(doc, multiFileRedactionLog, legalBasisMapping.getReasonByLegalBasis());
return toByteArray(doc);
} catch (IOException e) {
throw new RuntimeException(e);
@ -43,17 +55,34 @@ public class ReportGenerationService {
}
private void addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog) {
private void addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog,
Map<String, String> reasonByLegalBasis) {
XWPFTable table = doc.getTables().get(1);
XWPFTable table = doc.getTables().get(0);
multiFileRedactionLog.getRedactionLogs().forEach(fileRedactionLog -> {
fileRedactionLog.getRedactionLogEntry().forEach(redactionLogEntry -> {
if (redactionLogEntry.isRedacted()) {
if (redactionLogEntry.isManual() && !redactionLogEntry.getStatus().equals(Status.APPROVED)) {
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());
fileRedactionLog.getRedactionLogEntry().forEach(entry -> {
if (entry.isRedacted()) {
if (entry.isManual() && entry.getManualRedactionType()
.equals(ManualRedactionType.ADD) && !entry.getStatus().equals(Status.APPROVED)) {
return;
}
List<Integer> pages = redactionLogEntry.getPositions()
if (entry.isManual() && entry.getManualRedactionType()
.equals(ManualRedactionType.REMOVE) && entry.getStatus().equals(Status.APPROVED)) {
return;
}
List<Integer> pages = entry.getPositions()
.stream()
.map(Rectangle::getPage)
.distinct()
@ -61,10 +90,10 @@ public class ReportGenerationService {
.collect(Collectors.toList());
pages.forEach(page -> {
XWPFTableRow row = table.createRow();
row.getCell(0).setText(fileRedactionLog.getFilename());
row.getCell(1).setText(String.valueOf(page));
row.getCell(2).setText(redactionLogEntry.getSection());
row.getCell(3).setText(redactionLogEntry.getReason() + "; " + redactionLogEntry.getLegalBasis());
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()));
});
}
});
@ -73,6 +102,17 @@ public class ReportGenerationService {
}
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);
run.setText(value);
}
private byte[] toByteArray(XWPFDocument doc) throws IOException {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {

View File

@ -1,5 +1,6 @@
package com.iqser.red.service.redaction.report.v1.server;
import static org.mockito.Mockito.when;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
import java.io.FileOutputStream;
@ -10,12 +11,15 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.test.context.junit4.SpringRunner;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.configuration.v1.api.model.LegalBasisMapping;
import com.iqser.red.service.redaction.report.v1.api.model.MultiFileRedactionLog;
import com.iqser.red.service.redaction.report.v1.api.model.ReportResult;
import com.iqser.red.service.redaction.report.v1.server.client.LegalBasisMappingClient;
import com.iqser.red.service.redaction.report.v1.server.controller.RedactionReportController;
import com.iqser.red.service.redaction.v1.model.RedactionLog;
@ -29,11 +33,20 @@ public class RedactionReportIntegrationTest {
@Autowired
private RedactionReportController redactionReportController;
@MockBean
private LegalBasisMappingClient legalBasisMappingClient;
@Test
public void testReportGeneration() throws IOException {
ClassPathResource redactionLogResource = new ClassPathResource("files/RedactionLogManual.txt");
ClassPathResource legalBasisMappingResource = new ClassPathResource("files/LegalBasisMapping.json");
LegalBasisMapping legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), LegalBasisMapping.class);
when(legalBasisMappingClient.getLegalBasisMapping()).thenReturn(legalBasisMapping);
ClassPathResource redactionLogResource = new ClassPathResource("files/RedactedLog.txt");
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);

View File

@ -0,0 +1 @@
{"reasonByLegalBasis":{"Reg (EC) No 1107/2009 Art. 63 (2d)":"methods of analysis for impurities in the active substance as manufactured except for methods for impurities that are considered to be toxicologically, ecotoxicologically or environmentally relevant","Reg (EC) No 1107/2009 Art. 63 (2c)":"results of production batches of the active substance including impurities","Reg (EC) No 1107/2009 Art. 63 (2b)":"the specification of impurity of the active substance except for the impurities that are considered to be toxicologically, ecotoxicologically or environmentally relevant","Reg (EC) No 1107/2009 Art. 63 (2a)":"the method of manufacture","Reg (EC) No 1107/2009 Art. 63 (2g)":"names and addresses of persons involved in testing on vertebrate animals","Reg (EC) No 1107/2009 Art. 63 (2f)":"information on the complete composition of a plant protection product","Reg (EC) No 1107/2009 Art. 63 (2e)":"links between a producer or importer and the applicant or the authorisation holder"}}

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"redactionLogEntry":[{"id":"3080535605f06a5a397c4a9a5e501e9e","type":"address","value":"Regina Dorn","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":226.28998},"width":32.17697,"height":11.017679,"page":1},{"topLeft":{"x":181.79697,"y":226.28998},"width":23.68721,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false},{"id":"b54d906a78a3988c54c67f188acab849","type":"address","value":"Schwarzwaldallee 215 P.O. Box CH-4002 Basel Switzerland","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":289.52997},"width":81.095245,"height":11.017679,"page":1},{"topLeft":{"x":230.73732,"y":289.52997},"width":17.438568,"height":11.017679,"page":1},{"topLeft":{"x":147.86,"y":276.93},"width":20.562881,"height":11.017679,"page":1},{"topLeft":{"x":170.18288,"y":276.93},"width":19.359528,"height":11.017679,"page":1},{"topLeft":{"x":147.86,"y":264.21002},"width":41.950012,"height":11.017679,"page":1},{"topLeft":{"x":191.57,"y":264.21002},"width":25.519852,"height":11.017679,"page":1},{"topLeft":{"x":147.86,"y":251.60999},"width":53.649796,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false},{"id":"7b4ff6e32a8bdaa7de5dcdeb13ff8edd","type":"address","value":"regina.dorn@syngenta.com","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":188.34003},"width":122.451065,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false},{"id":"c357d6781fb4bb7e7020a67dbc63763c","type":"address","value":"Syngenta Crop Protection AG","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":302.25},"width":41.88115,"height":11.017679,"page":1},{"topLeft":{"x":191.50114,"y":302.25},"width":23.080002,"height":11.017679,"page":1},{"topLeft":{"x":216.34114,"y":302.25},"width":46.23088,"height":11.017679,"page":1},{"topLeft":{"x":264.2106,"y":302.25},"width":16.886566,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false},{"id":"946a2cc404d6568d34b1ca9a4c688ec9","type":"address","value":"+41 (61) 323 6358","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":213.65997},"width":18.266571,"height":11.017679,"page":1},{"topLeft":{"x":167.88657,"y":213.65997},"width":19.315353,"height":11.017679,"page":1},{"topLeft":{"x":188.99504,"y":213.65997},"width":17.438568,"height":11.017679,"page":1},{"topLeft":{"x":208.1936,"y":213.65997},"width":23.080017,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false},{"id":"687171974a4fc3aa0f43ec2118256590","type":"address","value":"+41 (61) 323 6155","reason":"Applicant information was found","redacted":true,"section":"1.2.1 Name and address of applicant(s) for approval of the active substance","color":[0.0,1.0,1.0],"positions":[{"topLeft":{"x":147.86,"y":200.94},"width":18.266571,"height":11.017679,"page":1},{"topLeft":{"x":167.88657,"y":200.94},"width":19.315353,"height":11.017679,"page":1},{"topLeft":{"x":188.99504,"y":200.94},"width":17.438568,"height":11.017679,"page":1},{"topLeft":{"x":208.1936,"y":200.94},"width":23.080017,"height":11.017679,"page":1}],"sectionNumber":3,"manual":false,"hint":false}]}

View File

@ -1,429 +0,0 @@
{
"redactionLogEntry": [
{
"id": "e5be0f1d941bbb92a068e198648d06c4",
"type": "name",
"value": "Robinson N.",
"reason": "Not redacted because row is not a vertebrate study",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0.8,
0.8,
0.8
],
"positions": [
{
"topLeft": {
"x": 142.04396,
"y": 241.282
},
"width": 7.648056,
"height": 42.43087,
"page": 1
}
],
"sectionNumber": 3,
"manual": false,
"status": null,
"hint": false
},
{
"id": "0295bbdff66926ebb57b03641bba7ba8",
"type": "address",
"value": "Syngenta Crop Protection AG, Basel, Switzerland",
"reason": "Not redacted because row is not a vertebrate study",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0.8,
0.8,
0.8
],
"positions": [
{
"topLeft": {
"x": 289.44595,
"y": 327.567
},
"width": 7.648041,
"height": 82.51475,
"page": 1
},
{
"topLeft": {
"x": 298.67056,
"y": 327.567
},
"width": 7.648041,
"height": 75.32377,
"page": 1
}
],
"sectionNumber": 4,
"manual": false,
"status": null,
"hint": false
},
{
"id": "1bd556e9b3dd82987f9775b19bb26fa4",
"type": "address",
"value": "RCC Ltd., Itingen, Switzerland",
"reason": "Not redacted because row is not a vertebrate study",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0.8,
0.8,
0.8
],
"positions": [
{
"topLeft": {
"x": 307.89517,
"y": 327.567
},
"width": 7.648041,
"height": 61.670967,
"page": 1
},
{
"topLeft": {
"x": 316.99985,
"y": 327.567
},
"width": 7.648041,
"height": 38.104286,
"page": 1
}
],
"sectionNumber": 4,
"manual": false,
"status": null,
"hint": false
},
{
"id": "e4eb6f849b60753c59897d1da21f3d83",
"type": "hint_only",
"value": "N",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0,
0.9882353,
0.69411767
],
"positions": [
{
"topLeft": {
"x": 145.03896,
"y": 448.34
},
"width": 7.648056,
"height": 4.000008,
"page": 1
}
],
"sectionNumber": 3,
"manual": false,
"status": null,
"hint": true
},
{
"id": "76dcc148fca080479fb3856d6e404813",
"type": "address",
"value": "Syngenta Crop Protection AG, Basel, Switzerland",
"reason": "Not redacted because row is not a vertebrate study",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0.8,
0.8,
0.8
],
"positions": [
{
"topLeft": {
"x": 169.62755,
"y": 327.567
},
"width": 7.648056,
"height": 82.51475,
"page": 1
},
{
"topLeft": {
"x": 178.73225,
"y": 327.567
},
"width": 7.648056,
"height": 75.32377,
"page": 1
}
],
"sectionNumber": 3,
"manual": false,
"status": null,
"hint": false
},
{
"id": "109c034945053697a8c3ff5449d4dbd5",
"type": "name",
"value": "Wolf S.",
"reason": "Not redacted because row is not a vertebrate study",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0.8,
0.8,
0.8
],
"positions": [
{
"topLeft": {
"x": 261.87195,
"y": 241.282
},
"width": 7.648041,
"height": 26.739037,
"page": 1
}
],
"sectionNumber": 4,
"manual": false,
"status": null,
"hint": false
},
{
"id": "8d4060e4761dfccfdaa6310d6e9c3407",
"type": "hint_only",
"value": "N",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0,
0.9882353,
0.69411767
],
"positions": [
{
"topLeft": {
"x": 264.88797,
"y": 448.34
},
"width": 7.648041,
"height": 4.000008,
"page": 1
}
],
"sectionNumber": 4,
"manual": false,
"status": null,
"hint": true
},
{
"id": "6b1338e3a108d3993c6da186f57ea019",
"type": "vertebrate",
"value": "rats",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
0,
1,
0
],
"positions": [
{
"topLeft": {
"x": 381.84018,
"y": 377.10638
},
"width": 7.648041,
"height": 12.379707,
"page": 1
}
],
"sectionNumber": 5,
"manual": false,
"status": null,
"hint": true
},
{
"id": "258d1236aa4ff9de4260a9d4284efdc5",
"type": "name",
"value": "Casey, H.W.",
"reason": "Redacted because Section contains Vertebrate",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": "Table in: ",
"color": [
1,
1,
0
],
"positions": [
{
"topLeft": {
"x": 421.61328,
"y": 241.282
},
"width": 7.648041,
"height": 42.66442,
"page": 1
}
],
"sectionNumber": 5,
"manual": false,
"status": null,
"hint": false
},
{
"id": "0836727c3508a0b2ea271da69c04cc2f",
"type": "address",
"value": "Toxigenics, Inc., Decatur, IL 62526, USA",
"reason": "Redacted because Section contains Vertebrate",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": "Table in: ",
"color": [
0,
1,
1
],
"positions": [
{
"topLeft": {
"x": 400.16907,
"y": 327.567
},
"width": 7.648041,
"height": 91.46436,
"page": 1
},
{
"topLeft": {
"x": 409.39368,
"y": 327.567
},
"width": 7.648041,
"height": 38.232735,
"page": 1
}
],
"sectionNumber": 5,
"manual": false,
"status": null,
"hint": false
},
{
"id": "0372ec83feed162bdd478b201027bc25",
"type": "name",
"value": "Salamon, C.M.",
"reason": "Redacted because Section contains Vertebrate",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": "Table in: ",
"color": [
1,
1,
0
],
"positions": [
{
"topLeft": {
"x": 394.0594,
"y": 241.282
},
"width": 7.648041,
"height": 32.012077,
"page": 1
},
{
"topLeft": {
"x": 403.16406,
"y": 241.282
},
"width": 7.648041,
"height": 18.487892,
"page": 1
}
],
"sectionNumber": 5,
"manual": false,
"status": null,
"hint": false
},
{
"id": "8734c14e72b7750de7637627ed5d572c",
"type": "name",
"value": "Smith, S.H.",
"reason": "Redacted because Section contains Vertebrate",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": "Table in: ",
"color": [
1,
1,
0
],
"positions": [
{
"topLeft": {
"x": 412.38867,
"y": 241.282
},
"width": 7.648041,
"height": 39.300346,
"page": 1
}
],
"sectionNumber": 5,
"manual": false,
"status": null,
"hint": false
},
{
"id": "2f4459be7301d8689a0f405399e55d69",
"type": "name",
"value": null,
"reason": "Manual Redaction",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": null,
"color": [
1,
1,
0
],
"positions": [
{
"topLeft": {
"x": 375.61096,
"y": 241.282
},
"width": 7.648041,
"height": 43.72262,
"page": 1
}
],
"sectionNumber": 0,
"manual": true,
"status": "APPROVED",
"hint": false
}
],
"dictionaryVersion": 9,
"rulesVersion": 2,
"filename": "Single Table.pdf"
}