Merge branch 'DM-578-backwards-compatible' into 'master'
DM-578 - Add backwards compatibility to be able to use old report template Closes DM-578 See merge request redactmanager/redaction-report-service!34
This commit is contained in:
commit
5f1c47dfec
@ -30,5 +30,6 @@ public class ExcelModel {
|
||||
private boolean firstRowWritten;
|
||||
private boolean skippedPlaceholderPresent;
|
||||
private boolean fileAttributesPlaceholderPresent;
|
||||
private boolean scmFunctionPlaceholderPresent;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,81 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.service;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.componentlog.ComponentLog;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileAttributeConfig;
|
||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.ComponentClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ExcelModel;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
public class ComponentRowsReportService {
|
||||
|
||||
ComponentClient componentResource;
|
||||
FileAttributesConfigClient fileAttributesClient;
|
||||
|
||||
@SuppressWarnings("checkstyle:all")
|
||||
static int COMPONENT_NAME_COL = 0;
|
||||
static int COMPONENT_VALUE_STARTING_COL = 1;
|
||||
|
||||
|
||||
public void addComponentRows(Sheet sheet, FileModel fileModel, ExcelModel excelModel) {
|
||||
|
||||
ComponentLog componentLog = componentResource.getComponentLog(fileModel.getDossierId(), fileModel.getId(), true);
|
||||
|
||||
AtomicInteger rowIndex = new AtomicInteger(excelModel.getRedactionPlaceholderRow());
|
||||
|
||||
String oecd = getOecdNumber(fileModel);
|
||||
|
||||
componentLog.getComponentLogEntries().forEach(componentLogEntry -> {
|
||||
|
||||
if (componentLogEntry.getComponentValues().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
int componentRowIdx = rowIndex.getAndIncrement();
|
||||
Row componentRow = sheet.createRow(componentRowIdx);
|
||||
excelModel.getWrittenRows().add(componentRowIdx);
|
||||
|
||||
Cell componentNameCell = componentRow.createCell(COMPONENT_NAME_COL);
|
||||
componentNameCell.setCellValue(oecd + "-" + componentLogEntry.getName().replaceAll("_", " "));
|
||||
|
||||
for (int valueIdx = 0; valueIdx < componentLogEntry.getComponentValues().size(); valueIdx++) {
|
||||
String value = componentLogEntry.getComponentValues().get(valueIdx).getValue();
|
||||
componentRow.createCell(COMPONENT_VALUE_STARTING_COL + valueIdx).setCellValue(value);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
sheet.createRow(rowIndex.get());
|
||||
excelModel.getWrittenRows().add(rowIndex.get());
|
||||
|
||||
excelModel.setRedactionPlaceholderRow(rowIndex.getAndIncrement());
|
||||
|
||||
}
|
||||
|
||||
|
||||
private String getOecdNumber(FileModel file) {
|
||||
|
||||
return fileAttributesClient.getFileAttributeConfigs(file.getDossierTemplateId())
|
||||
.stream()
|
||||
.filter(f -> f.getLabel().equals("OECD Number"))
|
||||
.map(FileAttributeConfig::getId)
|
||||
.findFirst()
|
||||
.map(oecd -> file.getFileAttributes().get(oecd))
|
||||
.orElse(null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -105,6 +105,7 @@ public class ExcelReportGenerationService {
|
||||
|
||||
private final ScmReportService componentReportService;
|
||||
private final FileAttributesConfigClient fileAttributesConfigClient;
|
||||
private final ComponentRowsReportService componentRowsReportService;
|
||||
|
||||
|
||||
@Timed("redactmanager_generateExcelReport")
|
||||
@ -147,7 +148,7 @@ public class ExcelReportGenerationService {
|
||||
}
|
||||
}
|
||||
|
||||
if (!excelModel.isRssPlaceholdersPresent() && !excelModel.isFileAttributesPlaceholderPresent()) {
|
||||
if (!excelModel.isRssPlaceholdersPresent() && !excelModel.isFileAttributesPlaceholderPresent() && !excelModel.isScmFunctionPlaceholderPresent()) {
|
||||
addRedactionEntryRows(sheet, reportEntries, fileModel.getFilename(), excelModel, placeholderModel);
|
||||
}
|
||||
|
||||
@ -155,6 +156,11 @@ public class ExcelReportGenerationService {
|
||||
componentReportService.addScmRows(sheet, fileModel, excelModel);
|
||||
}
|
||||
|
||||
if (excelModel.isScmFunctionPlaceholderPresent()) {
|
||||
componentRowsReportService.addComponentRows(sheet, fileModel, excelModel);
|
||||
}
|
||||
|
||||
|
||||
if (isLastFile) {
|
||||
addRows(workbook,
|
||||
sheet,
|
||||
@ -386,6 +392,7 @@ public class ExcelReportGenerationService {
|
||||
int placeholderRow = -1;
|
||||
boolean placeholderInFirstRow = false;
|
||||
boolean fileAttributesPlaceholder = false;
|
||||
boolean hasScmFunctionPlaceholder = false;
|
||||
|
||||
for (int j = 0; j < sheet.getLastRowNum() + 1; j++) {
|
||||
Row actualRow = sheet.getRow(j);
|
||||
@ -408,6 +415,10 @@ public class ExcelReportGenerationService {
|
||||
hasRssPlaceHolders = true;
|
||||
}
|
||||
|
||||
if (cellStringValue.contains(SCM_FUNCTION_PLACEHOLDER)) {
|
||||
hasScmFunctionPlaceholder = true;
|
||||
}
|
||||
|
||||
if (cellStringValue.contains(FILE_ATTRIBUTES_PLACEHOLDER)) {
|
||||
fileAttributesPlaceholder = true;
|
||||
|
||||
@ -481,7 +492,8 @@ public class ExcelReportGenerationService {
|
||||
placeholderInFirstRow,
|
||||
false,
|
||||
hasSkippedPlaceholder,
|
||||
fileAttributesPlaceholder);
|
||||
fileAttributesPlaceholder,
|
||||
hasScmFunctionPlaceholder);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user