From 06c86087741ee223ef8d62dc75312704b1dab18a Mon Sep 17 00:00:00 2001 From: Maverick Studer Date: Thu, 24 Oct 2024 17:16:04 +0200 Subject: [PATCH] RED-10246: RM-196: Paragraphs in all created Reports/Justification sheets --- .../service/WordReportGenerationService.java | 4 ++++ .../server/RedactionReportIntegrationTest.java | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) 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 d33c318..8e5bd57 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 @@ -586,6 +586,10 @@ public class WordReportGenerationService { private int setText(XWPFTableCell cell, String value) { + // Apache POI automatically adds an initial empty paragraph to a cell resulting in a break line. + if (cell.getParagraphs() != null && !cell.getParagraphs().isEmpty()) { + cell.removeParagraph(0); + } cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER); XWPFParagraph addParagraph = cell.addParagraph(); XWPFRun run = addParagraph.createRun(); 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 9d69d4e..2400207 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 @@ -32,6 +32,10 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook; 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.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mockito; @@ -186,6 +190,19 @@ public class RedactionReportIntegrationTest { try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/Justification Appendix A1_justification.docx")) { fileOutputStream.write(wordReport); } + + for (XWPFTable table : doc.getTables()) { + for (XWPFTableRow row : table.getRows()) { + for (XWPFTableCell cell : row.getTableCells()) { + for (XWPFParagraph paragraph : cell.getParagraphs()) { + String paragraphText = paragraph.getText(); + if (!paragraphText.equals("\n")) { + Assertions.assertFalse(paragraphText.startsWith("\n"), "Paragraph starts with an empty line."); + } + } + } + } + } }