Reverted to reading legal basis, optimistically

This commit is contained in:
Timo 2021-01-19 17:51:18 +02:00
parent 3480ce3851
commit 56ad432fea
5 changed files with 73 additions and 15 deletions

View File

@ -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 {
/**

View File

@ -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 {
}

View File

@ -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<LegalBasisMapping> 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<LegalBasisMapping> 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(""));
});
}
});

View File

@ -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> 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);

View File

@ -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"
}
}
]