diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/Placeholder.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/Placeholder.java new file mode 100644 index 0000000..0ad800f --- /dev/null +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/Placeholder.java @@ -0,0 +1,13 @@ +package com.iqser.red.service.redaction.report.v1.server.client; + +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class Placeholder { + + private String placeholder; + private String value; + +} diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/PlaceholderClient.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/PlaceholderClient.java new file mode 100644 index 0000000..a016b36 --- /dev/null +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/client/PlaceholderClient.java @@ -0,0 +1,11 @@ +package com.iqser.red.service.redaction.report.v1.server.client; + +import java.util.List; + +import org.springframework.cloud.openfeign.FeignClient; + +@FeignClient(name = "PlaceholderResource", url = "${configuration-service.url}") +public interface PlaceholderClient { + + List getPlaceholders(); +} diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java index 49264ac..62b969e 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/WordReportGenerationService.java @@ -16,6 +16,8 @@ import org.apache.poi.xwpf.usermodel.XWPFTableRow; import org.springframework.stereotype.Service; import com.iqser.red.service.redaction.report.v1.api.model.ReportType; +import com.iqser.red.service.redaction.report.v1.server.client.Placeholder; +import com.iqser.red.service.redaction.report.v1.server.client.PlaceholderClient; import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry; import com.iqser.red.service.redaction.report.v1.server.utils.ResourceLoader; @@ -27,6 +29,7 @@ public class WordReportGenerationService { private byte[] appendixA1Template; private byte[] appendixA2Template; + private PlaceholderClient placeholderClient; @PostConstruct @@ -39,6 +42,10 @@ public class WordReportGenerationService { public byte[] generateReport(ReportType reportType, List reportEntries, String filename) { + + List placeholder = placeholderClient.getPlaceholders(); + + byte[] template; if (reportType.equals(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE)) { @@ -52,6 +59,8 @@ public class WordReportGenerationService { try (ByteArrayInputStream is = new ByteArrayInputStream(template)) { XWPFDocument doc = new XWPFDocument(is); + // Replace placeholders. + addTableRows(doc, reportEntries, filename); return toByteArray(doc); } catch (IOException e) { diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/resources/templates/Sanitisation justification Appendix A1.docx b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/resources/templates/Sanitisation justification Appendix A1.docx index 9defb47..ca05278 100644 Binary files a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/resources/templates/Sanitisation justification Appendix A1.docx and b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/resources/templates/Sanitisation justification Appendix A1.docx differ 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 72b19c9..c45845d 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,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.RANDOM_PORT; import java.io.FileOutputStream; @@ -8,6 +9,8 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -20,6 +23,8 @@ 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.ReportType; import com.iqser.red.service.redaction.report.v1.server.client.LegalBasisMappingClient; +import com.iqser.red.service.redaction.report.v1.server.client.Placeholder; +import com.iqser.red.service.redaction.report.v1.server.client.PlaceholderClient; import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration; import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry; import com.iqser.red.service.redaction.report.v1.server.service.ExcelReportGenerationService; @@ -44,7 +49,7 @@ public class RedactionReportIntegrationTest { @MockBean private AmazonS3 s3Client; - @Autowired + @InjectMocks private WordReportGenerationService wordReportGenerationService; @Autowired @@ -56,10 +61,15 @@ public class RedactionReportIntegrationTest { @Autowired private RedactionLogConverterService redactionLogConverterService; + @Mock + private PlaceholderClient placeholderClient; + @Test public void testWordReportGeneration() throws IOException { + when(placeholderClient.getPlaceholders()).thenReturn(List.of(Placeholder.builder().placeholder("{{dossier.name}}").value("Dossier 1").build())); + ClassPathResource redactionLogResource = new ClassPathResource("files/RedactedLog.txt"); RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class); @@ -73,12 +83,14 @@ public class RedactionReportIntegrationTest { List reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping); - byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A2_TEMPLATE, reportEntries, redactionLog + wordReportGenerationService.init(); + byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE_APPENDIX_A1_TEMPLATE, reportEntries, redactionLog .getFilename()); try (FileOutputStream fileOutputStream = new FileOutputStream("/tmp/efsa_template.docx")) { fileOutputStream.write(report); } + }