RSS-115: Write Firstline for rss only once

This commit is contained in:
deiflaender 2022-09-21 14:48:05 +02:00
parent 060861e7c3
commit af1dfa6bc6
2 changed files with 18 additions and 2 deletions

View File

@ -26,5 +26,8 @@ public class ExcelModel {
private List<Integer> writtenRows = new ArrayList<>();
private boolean rowsBeforeRedactionEntryRowsAdded;
private boolean hasRssPlaceHolders;
private boolean placeholderInFirstRow;
private boolean firstRowWritten;
}

View File

@ -123,9 +123,15 @@ public class ExcelReportGenerationService {
String filename, ExcelModel excelModel) {
Set<Integer> createdCopyRows = new HashSet<>();
int skipRows = excelModel.isHasRssPlaceHolders() && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow() ? 1 : 0;
for (Map.Entry<CellIdentifier, Cell> cellsToCopyEntry : copiedCells.entrySet()) {
int indexToAddRow = cellsToCopyEntry.getKey().getRowIndex() + numberOfRowsToShift;
if(excelModel.isHasRssPlaceHolders() && cellsToCopyEntry.getKey().getRowIndex() == 0 && excelModel.isFirstRowWritten() && !excelModel.isPlaceholderInFirstRow()){
continue;
}
int indexToAddRow = cellsToCopyEntry.getKey().getRowIndex() + numberOfRowsToShift - skipRows;
if (!createdCopyRows.contains(indexToAddRow)) {
sheet.createRow(indexToAddRow);
@ -146,6 +152,8 @@ public class ExcelReportGenerationService {
replacePlaceholders(createdCell, placeholderModel, dossierName, filename);
replacePlaceholdersForImagePlaceholder(workbook, sheet, createdCell, placeholderModel);
}
excelModel.setFirstRowWritten(true);
}
@ -171,6 +179,7 @@ public class ExcelReportGenerationService {
Map<CellIdentifier, Cell> cellsToCopyInPlaceholderRow = new HashMap<>();
boolean hasRssPlaceHolders = false;
int placeholderRow = -1;
boolean placeholderInFirstRow = false;
for (int j = 0; j < sheet.getLastRowNum() + 1; j++) {
Row actualRow = sheet.getRow(j);
if (actualRow != null) {
@ -181,6 +190,10 @@ public class ExcelReportGenerationService {
columnWidths.put(i, columnWidth);
String cellStringValue = cell.getStringCellValue();
if(j == 0 && cellStringValue.contains("{{")){
placeholderInFirstRow = true;
}
if(cellStringValue.contains(RSS_PLACEHOLDER_BASE)){
hasRssPlaceHolders = true;
}
@ -208,7 +221,7 @@ public class ExcelReportGenerationService {
}
log.debug("Calculate Placeholder Cells took: {}", System.currentTimeMillis() - start);
return new ExcelModel(placeholderCellPos, placeholderRow, columnWidths, cellsToCopyBeforePlaceholderRow, cellsToCopyAfterPlaceholderRow, new ArrayList<>(), false, hasRssPlaceHolders);
return new ExcelModel(placeholderCellPos, placeholderRow, columnWidths, cellsToCopyBeforePlaceholderRow, cellsToCopyAfterPlaceholderRow, new ArrayList<>(), false, hasRssPlaceHolders, placeholderInFirstRow, false);
}