RED-10683: fix NPE for firstRow
This commit is contained in:
parent
1c6ab159f9
commit
a525fe6887
@ -28,8 +28,13 @@ public class ExcelModel {
|
||||
private boolean placeholderInFirstRow;
|
||||
private boolean firstRowWritten;
|
||||
private boolean skippedPlaceholderPresent;
|
||||
private boolean fileAttributesPlaceholderPresent;
|
||||
private boolean scmFunctionPlaceholderPresent;
|
||||
private ComponentReportModel componentReport;
|
||||
private List<FileAttributeModel> fileAttributeColumns;
|
||||
|
||||
public boolean isFileAttributesPlaceholderPresent() {
|
||||
|
||||
return !fileAttributeColumns.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -42,6 +42,7 @@ import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesCon
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.CellIdentifier;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ComponentReportModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ExcelModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.FileAttributeModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderInput;
|
||||
|
||||
import io.micrometer.core.annotation.Timed;
|
||||
@ -93,12 +94,12 @@ public class ExcelModelFactory {
|
||||
Map<CellIdentifier, Cell> cellsToCopyInPlaceholderRow = new HashMap<>();
|
||||
Integer componentColumn = null;
|
||||
Integer componentValueIndexColumn = null;
|
||||
List<FileAttributeModel> fileAttributeCols = new ArrayList<>();
|
||||
|
||||
boolean hasRssPlaceHolders = false;
|
||||
boolean hasSkippedPlaceholder = false;
|
||||
int placeholderRow = -1;
|
||||
boolean placeholderInFirstRow = false;
|
||||
boolean fileAttributesPlaceholder = false;
|
||||
boolean hasScmFunctionPlaceholder = false;
|
||||
|
||||
for (int row = 0; row < sheet.getLastRowNum() + 1; row++) {
|
||||
@ -117,7 +118,7 @@ public class ExcelModelFactory {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean skipCopy = false;
|
||||
boolean isFileAttributesPlaceholder = false;
|
||||
int columnWidth = sheet.getColumnWidth(col);
|
||||
columnWidths.put(col, columnWidth);
|
||||
String cellStringValue = cell.getStringCellValue();
|
||||
@ -143,18 +144,19 @@ public class ExcelModelFactory {
|
||||
}
|
||||
|
||||
if (cellStringValue.contains(FILE_ATTRIBUTES_PLACEHOLDER)) {
|
||||
fileAttributesPlaceholder = true;
|
||||
|
||||
// For each file attribute we have to replace the column header with the corresponding file attribute.
|
||||
List<FileAttributeConfig> fileAttributeConfigs = fileAttributesConfigClient.getFileAttributeConfigs(dossierTemplateId);
|
||||
|
||||
var iterator = fileAttributeConfigs.iterator();
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
|
||||
cell = getOrCreateCell(actualRow, col);
|
||||
cell.setCellValue(iterator.next().getLabel());
|
||||
FileAttributeConfig fileAttributeConfig = iterator.next();
|
||||
cell.setCellValue(fileAttributeConfig.getLabel());
|
||||
cellsToCopyBeforePlaceholderRow.put(new CellIdentifier(row, col), cell);
|
||||
|
||||
fileAttributeCols.add(FileAttributeModel.builder().id(fileAttributeConfig.getId()).cell(cell).build());
|
||||
// If there is more than one file attribute we have to insert a new column, so we shift all columns to the right by 1
|
||||
// and increase the current and last cell index.
|
||||
if (iterator.hasNext()) {
|
||||
@ -164,10 +166,10 @@ public class ExcelModelFactory {
|
||||
}
|
||||
}
|
||||
|
||||
skipCopy = true;
|
||||
isFileAttributesPlaceholder = true;
|
||||
}
|
||||
|
||||
if (!skipCopy) {
|
||||
if (!isFileAttributesPlaceholder) {
|
||||
if (isRedactionPlaceholder(cellStringValue)) {
|
||||
if (cellStringValue.equals(SKIPPED_PLACEHOLDER)) {
|
||||
hasSkippedPlaceholder = true;
|
||||
@ -205,9 +207,9 @@ public class ExcelModelFactory {
|
||||
placeholderInFirstRow,
|
||||
false,
|
||||
hasSkippedPlaceholder,
|
||||
fileAttributesPlaceholder,
|
||||
hasScmFunctionPlaceholder,
|
||||
componentReport);
|
||||
componentReport,
|
||||
fileAttributeCols);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -163,7 +163,7 @@ public class ExcelReportGenerationService {
|
||||
continue;
|
||||
}
|
||||
|
||||
log.info("Copying cell {},{} with content {} from template",
|
||||
log.debug("Copying cell {},{} with content {} from template",
|
||||
cellsToCopyEntry.getKey().getRowIndex(),
|
||||
cellsToCopyEntry.getKey().getColumnIndex(),
|
||||
formatter.formatCellValue(cellsToCopyEntry.getValue()));
|
||||
|
||||
@ -6,9 +6,14 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
||||
import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||
import org.apache.poi.ss.util.CellUtil;
|
||||
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLog;
|
||||
@ -38,9 +43,9 @@ public class ScmReportService {
|
||||
|
||||
public void addComponentRows(Sheet sheet, FileModel fileModel, ExcelModel excelModel) {
|
||||
|
||||
Row firstRow = findFirstRow(sheet);
|
||||
// Row firstRow = findFirstRow(sheet);
|
||||
|
||||
CellUtil.setAlignment(getOrCreateCell(firstRow, excelModel.getComponentReport().getComponentValueColumn()), HorizontalAlignment.LEFT);
|
||||
// CellUtil.setAlignment(getOrCreateCell(firstRow, excelModel.getComponentReport().getComponentValueColumn()), HorizontalAlignment.LEFT);
|
||||
|
||||
ComponentLog componentLog = componentResource.getComponentLog(fileModel.getDossierId(), fileModel.getId(), true);
|
||||
|
||||
@ -56,17 +61,17 @@ public class ScmReportService {
|
||||
}
|
||||
|
||||
// Process each ComponentLogEntryValue
|
||||
addOtherCells(sheet, excelModel, rowIndex, componentIndexMap, componentLogEntry, fileModel, firstRow);
|
||||
addOtherCells(sheet, excelModel, rowIndex, componentIndexMap, componentLogEntry, fileModel);
|
||||
|
||||
});
|
||||
|
||||
// Autosize all cells besides the last column because the extracted text should be multiline
|
||||
if (sheet instanceof SXSSFSheet) {
|
||||
((SXSSFSheet) sheet).trackAllColumnsForAutoSizing();
|
||||
for (int i = 0; i < firstRow.getLastCellNum() - 1; i++) {
|
||||
sheet.autoSizeColumn(i);
|
||||
}
|
||||
}
|
||||
// // Autosize all cells besides the last column because the extracted text should be multiline
|
||||
// if (sheet instanceof SXSSFSheet) {
|
||||
// ((SXSSFSheet) sheet).trackAllColumnsForAutoSizing();
|
||||
// for (int i = 0; i < firstRow.getLastCellNum() - 1; i++) {
|
||||
// sheet.autoSizeColumn(i);
|
||||
// }
|
||||
// }
|
||||
|
||||
sheet.createRow(rowIndex.get());
|
||||
excelModel.getWrittenRows().add(rowIndex.get());
|
||||
@ -112,14 +117,13 @@ public class ScmReportService {
|
||||
AtomicInteger rowIndex,
|
||||
Map<String, Integer> componentIndexMap,
|
||||
ComponentLogEntry componentLogEntry,
|
||||
FileModel fileModel,
|
||||
Row firstRow) {
|
||||
FileModel fileModel) {
|
||||
|
||||
String componentValue = componentLogEntry.getName().replaceAll("_", " ");
|
||||
|
||||
int componentIndex = componentIndexMap.getOrDefault(componentValue, 0);
|
||||
|
||||
List<FileAttributeModel> fileAttributeModels = buildFileAttributeModels(fileModel, firstRow);
|
||||
List<FileAttributeModel> fileAttributeModels = excelModel.getFileAttributeColumns();
|
||||
|
||||
for (ComponentLogEntryValue componentLogEntryValue : componentLogEntry.getComponentValues()) {
|
||||
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<configuration>
|
||||
|
||||
<springProperty scope="configuration" name="logType" source="logging.type"/>
|
||||
<springProperty scope="context" name="application.name" source="spring.application.name"/>
|
||||
<springProperty scope="context" name="version" source="project.version"/>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||
|
||||
<appender name="JSON" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="${logType}"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Loading…
x
Reference in New Issue
Block a user