Add legal basis to report

This commit is contained in:
Thierry Göckel 2020-10-27 15:54:35 +01:00
parent e98fe6868f
commit 3a3e923c75
4 changed files with 29 additions and 17 deletions

View File

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

View File

@ -2,10 +2,9 @@ package com.iqser.red.service.redaction.report.v1.server.service;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
@ -16,6 +15,7 @@ import org.springframework.stereotype.Service;
import com.iqser.red.service.redaction.report.v1.api.model.MultiFileRedactionLog;
import com.iqser.red.service.redaction.report.v1.server.utils.ResourceLoader;
import com.iqser.red.service.redaction.v1.model.Rectangle;
import com.iqser.red.service.redaction.v1.model.Status;
@Service
@ -35,7 +35,7 @@ public class ReportGenerationService {
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
XWPFDocument doc = new XWPFDocument(is);
doc = addTableRows(doc, multiFileRedactionLog);
addTableRows(doc, multiFileRedactionLog);
return toByteArray(doc);
} catch (IOException e) {
throw new RuntimeException(e);
@ -43,36 +43,37 @@ public class ReportGenerationService {
}
private XWPFDocument addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog) {
private void addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog) {
XWPFTable table = doc.getTables().get(1);
multiFileRedactionLog.getRedactionLogs().forEach(fileRedactionLog -> {
fileRedactionLog.getRedactionLogEntry().forEach(redactionLogEntry -> {
if(redactionLogEntry.isRedacted()) {
if(redactionLogEntry.isManual() && !redactionLogEntry.getStatus().equals(Status.APPROVED)){
if (redactionLogEntry.isRedacted()) {
if (redactionLogEntry.isManual() && !redactionLogEntry.getStatus().equals(Status.APPROVED)) {
return;
}
Set<Integer> pages = new HashSet<>();
redactionLogEntry.getPositions().forEach(position -> {
pages.add(position.getPage());
});
List<Integer> pages = redactionLogEntry.getPositions()
.stream()
.map(Rectangle::getPage)
.distinct()
.sorted()
.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());
row.getCell(3).setText(redactionLogEntry.getReason() + "; " + redactionLogEntry.getLegalBasis());
});
}
});
});
return doc;
}
private byte[] toByteArray(XWPFDocument doc) throws FileNotFoundException, IOException {
private byte[] toByteArray(XWPFDocument doc) throws IOException {
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
doc.write(byteArrayOutputStream);

View File

@ -1,6 +1,5 @@
package com.iqser.red.service.redaction.report.v1.server;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT;
import java.io.FileOutputStream;
@ -47,7 +46,6 @@ public class RedactionReportIntegrationTest {
fileOutputStream.write(reportResult.getDocument());
}
assertThat(true).isTrue();
}
}

View File

@ -5,6 +5,7 @@
"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": [
@ -33,6 +34,7 @@
"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": [
@ -70,6 +72,7 @@
"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": [
@ -107,6 +110,7 @@
"type": "hint_only",
"value": "N",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
@ -135,6 +139,7 @@
"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": [
@ -172,6 +177,7 @@
"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": [
@ -200,6 +206,7 @@
"type": "hint_only",
"value": "N",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
@ -228,6 +235,7 @@
"type": "vertebrate",
"value": "rats",
"reason": null,
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": false,
"section": "Table in: ",
"color": [
@ -256,6 +264,7 @@
"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": [
@ -284,6 +293,7 @@
"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": [
@ -321,6 +331,7 @@
"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": [
@ -358,6 +369,7 @@
"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": [
@ -386,6 +398,7 @@
"type": "name",
"value": null,
"reason": "Manual Redaction",
"legalBasis": "Reg (EC) No 1107/2009 Art. 63 (2g)",
"redacted": true,
"section": null,
"color": [