From 56ad432feaf758da5e24359dd84d1fa1aa808559 Mon Sep 17 00:00:00 2001 From: Timo Date: Tue, 19 Jan 2021 17:51:18 +0200 Subject: [PATCH] Reverted to reading legal basis, optimistically --- .../report/v1/server/Application.java | 8 +++- .../client/LegalBasisMappingClient.java | 8 ++++ .../service/ReportGenerationService.java | 17 ++++++-- .../RedactionReportIntegrationTest.java | 16 ++++++++ .../resources/files/LegalBasisMapping.json | 39 ++++++++++++++----- 5 files changed, 73 insertions(+), 15 deletions(-) create mode 100644 redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/LegalBasisMappingClient.java diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/Application.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/Application.java index 27a365f..c626006 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/Application.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/Application.java @@ -1,19 +1,23 @@ package com.iqser.red.service.redaction.report.v1.server; -import com.iqser.red.commons.spring.DefaultWebMvcConfiguration; -import com.iqser.red.service.redaction.report.v1.server.settings.RedactionReportSettings; import org.springframework.boot.SpringApplication; import org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.cloud.openfeign.EnableFeignClients; 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(basePackageClasses = {LegalBasisMappingClient.class}) public class Application { /** diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/LegalBasisMappingClient.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/LegalBasisMappingClient.java new file mode 100644 index 0000000..98116e5 --- /dev/null +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/LegalBasisMappingClient.java @@ -0,0 +1,8 @@ +package com.iqser.red.service.redaction.report.v1.server.client; + +import com.iqser.red.service.configuration.v1.api.resource.LegalBasisMappingResource; +import org.springframework.cloud.openfeign.FeignClient; + +@FeignClient(name = "LegalBasisMappingResource", url = "${configuration-service.url}") +public interface LegalBasisMappingClient extends LegalBasisMappingResource { +} \ No newline at end of file diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ReportGenerationService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ReportGenerationService.java index 6ca1cf5..2f6d5f4 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ReportGenerationService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ReportGenerationService.java @@ -1,6 +1,8 @@ package com.iqser.red.service.redaction.report.v1.server.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; @@ -28,6 +30,7 @@ import java.util.stream.Collectors; @RequiredArgsConstructor public class ReportGenerationService { + private final LegalBasisMappingClient legalBasisMappingClient; private byte[] efsaTemplate; private byte[] syngentaTemplate; @@ -54,7 +57,8 @@ public class ReportGenerationService { try (ByteArrayInputStream is = new ByteArrayInputStream(template)) { XWPFDocument doc = new XWPFDocument(is); - addTableRows(doc, multiFileRedactionLog); + List legalBasisMappings = legalBasisMappingClient.getLegalBasisMapping(multiFileRedactionLog.getRuleSetId()); + addTableRows(doc, multiFileRedactionLog, legalBasisMappings); return toByteArray(doc); } catch (IOException e) { throw new RuntimeException(e); @@ -62,7 +66,8 @@ public class ReportGenerationService { } - private void addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog) { + private void addTableRows(XWPFDocument doc, MultiFileRedactionLog multiFileRedactionLog, + List legalBasisMappings) { XWPFTable table = doc.getTables().get(0); @@ -103,7 +108,13 @@ public class ReportGenerationService { 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() + " " + entry.getReason()); + setText(row.getCell(3), entry.getLegalBasis() + " " + + legalBasisMappings + .stream() + .filter(lbm -> lbm.getReason().equalsIgnoreCase(entry.getLegalBasis())) + .findAny() + .map(LegalBasisMapping::getDescription) + .orElse("")); }); } }); diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java index d217db1..4b5a5ef 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/java/com/iqser/red/service/redaction/report/v1/server/RedactionReportIntegrationTest.java @@ -1,14 +1,18 @@ package com.iqser.red.service.redaction.report.v1.server; +import com.fasterxml.jackson.core.type.TypeReference; 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; 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; @@ -16,6 +20,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.List; +import static org.mockito.Mockito.when; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; @RunWith(SpringRunner.class) @@ -28,9 +33,20 @@ public class RedactionReportIntegrationTest { @Autowired private RedactionReportController redactionReportController; + @MockBean + private LegalBasisMappingClient legalBasisMappingClient; + + @Test public void testReportGeneration() throws IOException { + ClassPathResource legalBasisMappingResource = new ClassPathResource("files/LegalBasisMapping.json"); + + List legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() { + }); + + when(legalBasisMappingClient.getLegalBasisMapping("123")).thenReturn(legalBasisMapping); + ClassPathResource redactionLogResource = new ClassPathResource("files/RedactedLog.txt"); RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class); diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/files/LegalBasisMapping.json b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/files/LegalBasisMapping.json index 938ce6e..9c042de 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/files/LegalBasisMapping.json +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/test/resources/files/LegalBasisMapping.json @@ -1,11 +1,30 @@ -{ - "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" +[ + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2d)", + "description": "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" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2c)", + "description": "results of production batches of the active substance including impurities" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2b)", + "description": "the specification of impurity of the active substance except for the impurities that are considered to be toxicologically, ecotoxicologically or environmentally relevant" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2a)", + "description": "the method of manufacture" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2g)", + "description": "names and addresses of persons involved in testing on vertebrate animals" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2f)", + "description": "information on the complete composition of a plant protection product" + }, + { + "reason": "Reg (EC) No 1107/2009 Art. 63 (2e)", + "description": "links between a producer or importer and the applicant or the authorisation holder" } -} \ No newline at end of file +]