Merge branch 'RED-10246' into 'release/4.73.x'

RED-10246: RM-196: Paragraphs in all created Reports/Justification sheets

See merge request redactmanager/redaction-report-service!101
This commit is contained in:
Maverick Studer 2024-10-24 17:16:04 +02:00
commit 28d6950b55
2 changed files with 21 additions and 0 deletions

View File

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

View File

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