Pull request #193: RSS-194: Added scm function placeholder

Merge in RED/redaction-report-service from RSS-194 to master

* commit 'e82bb9950a1977b69038a57c3b8bf7ef4845f946':
  RSS-194: Added scm function placeholder
This commit is contained in:
Dominique Eiflaender 2022-11-18 15:34:11 +01:00
commit f4bf290194
3 changed files with 58 additions and 3 deletions

View File

@ -28,5 +28,6 @@ public class ExcelModel {
private boolean hasRssPlaceHolders;
private boolean placeholderInFirstRow;
private boolean firstRowWritten;
private boolean hasScmFunctionPlaceholder;
}

View File

@ -23,6 +23,7 @@ import static com.iqser.red.service.redaction.report.v1.server.service.Placehold
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.REDACTION_VALUE_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.RSS_PLACEHOLDER_BASE;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SCM_FUNCTION_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER;
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER;
@ -74,6 +75,9 @@ import lombok.extern.slf4j.Slf4j;
@RequiredArgsConstructor
public class ExcelReportGenerationService {
private final RSSPoc2Service rSSPoc2Service;
@Timed("redactmanager_generateExcelReport")
public void generateExcelReport(List<ReportRedactionEntry> reportEntries,
PlaceholderModel placeholderModel,
@ -110,10 +114,14 @@ public class ExcelReportGenerationService {
}
}
if (!excelModel.isHasRssPlaceHolders()) {
if (!excelModel.isHasRssPlaceHolders() && !excelModel.isHasScmFunctionPlaceholder()) {
addRedactionEntryRows(sheet, reportEntries, fileModel.getFilename(), excelModel, placeholderModel);
}
if (excelModel.isHasScmFunctionPlaceholder()) {
addSCMEntryRows(sheet, fileModel, excelModel);
}
if (isLastFile) {
addRows(workbook,
sheet,
@ -207,6 +215,7 @@ public class ExcelReportGenerationService {
Map<CellIdentifier, Cell> cellsToCopyAfterPlaceholderRow = new HashMap<>();
Map<CellIdentifier, Cell> cellsToCopyInPlaceholderRow = new HashMap<>();
boolean hasRssPlaceHolders = false;
boolean hasScmFunctionPlaceholder = false;
int placeholderRow = -1;
boolean placeholderInFirstRow = false;
for (int j = 0; j < sheet.getLastRowNum() + 1; j++) {
@ -227,6 +236,10 @@ public class ExcelReportGenerationService {
hasRssPlaceHolders = true;
}
if (cellStringValue.contains(SCM_FUNCTION_PLACEHOLDER)) {
hasScmFunctionPlaceholder = true;
}
if (containsRedactionPlaceholder(cellStringValue)) {
placeholderCellPos.put(i, getFunctionForPlaceHolder(cellStringValue));
placeholderRow = j;
@ -259,7 +272,47 @@ public class ExcelReportGenerationService {
false,
hasRssPlaceHolders,
placeholderInFirstRow,
false);
false,
hasScmFunctionPlaceholder);
}
private void addSCMEntryRows(Sheet sheet, FileModel fileModel, ExcelModel excelModel) {
var scm = rSSPoc2Service.getRSS(fileModel.getDossierId(), fileModel.getId());
var scmResultMap = scm.getFiles().get(0).getResult();
AtomicInteger rowIndex = new AtomicInteger(excelModel.getRedactionPlaceholderRow());
var oecd = scmResultMap.get("Study_Type_Number");
for (Map.Entry<String, String> entry : scmResultMap.entrySet()) {
if(entry.getKey().equals("Study_Type_Number")){
continue;
}
sheet.createRow(rowIndex.get());
excelModel.getWrittenRows().add(rowIndex.get());
Cell filenameCell = sheet.getRow(rowIndex.get()).createCell(0);
filenameCell.setCellValue(fileModel.getFilename());
Cell keyCell = sheet.getRow(rowIndex.get()).createCell(1);
keyCell.setCellValue(oecd + "-" + entry.getKey());
Cell valueCell = sheet.getRow(rowIndex.get()).createCell(2);
valueCell.setCellValue(entry.getValue());
rowIndex.getAndIncrement();
}
sheet.createRow(rowIndex.get());
excelModel.getWrittenRows().add(rowIndex.get());
excelModel.setRedactionPlaceholderRow(rowIndex.getAndIncrement());
}
@ -294,7 +347,7 @@ public class ExcelReportGenerationService {
JUSTIFICATION_PARAGRAPH_PLACEHOLDER) || text.contains(JUSTIFICATION_REASON_PLACEHOLDER) || text.contains(REDACTION_VALUE_PLACEHOLDER) || text.contains(
JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER) || text.contains(JUSTIFICATION_TEXT_PLACEHOLDER) || text.contains(
SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER) || text.contains(SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER) || text.contains(
REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER);
REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER) || text.contains(SCM_FUNCTION_PLACEHOLDER);
}

View File

@ -48,6 +48,7 @@ public class PlaceholderService {
public static final String EXCERPT_PLACEHOLDER = "{{redaction.excerpt}}";
public static final String REDACTION_VALUE_PLACEHOLDER = "{{redaction.value}}";
public static final String REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER = "{{redaction.entity.displayName}}";
public static final String SCM_FUNCTION_PLACEHOLDER = "{{function.scm}}";
public static final String FILE_ATTRIBUTE_PLACEHOLDER_BASE = "{{file.attribute.";
public static final String DOSSIER_ATTRIBUTE_PLACEHOLDER_BASE = "{{dossier.attribute.";
public static final String RSS_PLACEHOLDER_BASE = "{{component.";