From 9da3e2d966b912433a6fda53a3d5c2c40f095e23 Mon Sep 17 00:00:00 2001 From: Kilian Schuettler Date: Wed, 4 Oct 2023 15:26:07 +0200 Subject: [PATCH] DM-285: adjust reports to new component log --- redaction-report-service-v1/pom.xml | 2 +- .../pom.xml | 6 +- .../service/ComponentRowsReportService.java | 90 +++++++++++++++++++ .../service/ExcelReportGenerationService.java | 34 +------ 4 files changed, 99 insertions(+), 33 deletions(-) create mode 100644 redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ComponentRowsReportService.java diff --git a/redaction-report-service-v1/pom.xml b/redaction-report-service-v1/pom.xml index 41f2822..64b5469 100644 --- a/redaction-report-service-v1/pom.xml +++ b/redaction-report-service-v1/pom.xml @@ -24,7 +24,7 @@ - 2.79.0 + 2.197.0 5.2.3 diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/pom.xml b/redaction-report-service-v1/redaction-report-service-server-v1/pom.xml index d0bf47f..b6c2571 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/pom.xml +++ b/redaction-report-service-v1/redaction-report-service-server-v1/pom.xml @@ -83,7 +83,11 @@ - + + com.iqser.red.service + persistence-service-external-api-v2 + ${persistence-service.version} + com.iqser.red.commons test-commons diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ComponentRowsReportService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ComponentRowsReportService.java new file mode 100644 index 0000000..afcd2ec --- /dev/null +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ComponentRowsReportService.java @@ -0,0 +1,90 @@ +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.Sheet; +import org.springframework.stereotype.Service; + +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.persistence.service.v2.api.external.model.FileComponents; +import com.iqser.red.service.persistence.service.v2.api.external.resource.ComponentResource; +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 { + + ComponentResource componentResource; + FileAttributesConfigClient fileAttributesClient; + + static int FILENAME_COL = 0; + static int COMPONENT_NAME_COL = 1; + static int COMPONENT_VALUE_COL = 2; + + + public void addComponentRows(Sheet sheet, FileModel fileModel, ExcelModel excelModel) { + + FileComponents fileComponents = componentResource.getComponents(fileModel.getDossierTemplateId(), fileModel.getDossierId(), fileModel.getId(), false); + + AtomicInteger rowIndex = new AtomicInteger(excelModel.getRedactionPlaceholderRow()); + + String oecd = getOecdNumber(fileModel); + int fileNameRow = rowIndex.getAndIncrement(); + sheet.createRow(fileNameRow); + excelModel.getWrittenRows().add(fileNameRow); + Cell fileNameCell = sheet.getRow(fileNameRow).createCell(FILENAME_COL); + fileNameCell.setCellValue(fileComponents.getFilename()); + + fileComponents.getComponents().forEach((componentName, values) -> { + + if (values.isEmpty()) { + return; + } + int componentNameRow = rowIndex.getAndIncrement(); + sheet.createRow(componentNameRow); + excelModel.getWrittenRows().add(componentNameRow); + + Cell componentNameCell = sheet.getRow(componentNameRow).createCell(COMPONENT_NAME_COL); + componentNameCell.setCellValue(oecd + "-" + componentName.replaceAll("_", " ")); + + Cell valueCell = sheet.getRow(componentNameRow).createCell(COMPONENT_VALUE_COL); + valueCell.setCellValue(values.get(0)); + + for (String value : values.subList(1, values.size())) { + int additionalValueRow = rowIndex.getAndIncrement(); + Cell additionalValueCell = sheet.createRow(additionalValueRow).createCell(COMPONENT_VALUE_COL); + excelModel.getWrittenRows().add(additionalValueRow); + additionalValueCell.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); + + } + +} diff --git a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelReportGenerationService.java b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelReportGenerationService.java index c978cff..11c1026 100644 --- a/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelReportGenerationService.java +++ b/redaction-report-service-v1/redaction-report-service-server-v1/src/main/java/com/iqser/red/service/redaction/report/v1/server/service/ExcelReportGenerationService.java @@ -59,7 +59,6 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook; import org.springframework.stereotype.Service; import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.dossier.file.FileModel; -import com.iqser.red.service.redaction.report.v1.api.model.rss.SCMComponent; import com.iqser.red.service.redaction.report.v1.server.model.CellIdentifier; import com.iqser.red.service.redaction.report.v1.server.model.ExcelModel; import com.iqser.red.service.redaction.report.v1.server.model.ImagePlaceholder; @@ -94,7 +93,8 @@ public class ExcelReportGenerationService { REDACTION_ENTITY_DISPLAY_NAME_PLACEHOLDER, SCM_FUNCTION_PLACEHOLDER, SKIPPED_PLACEHOLDER); - private final RSSPoc2Service rSSPoc2Service; + private final ComponentRowsReportService componentRowsReportService; + @Timed("redactmanager_generateExcelReport") @@ -142,7 +142,7 @@ public class ExcelReportGenerationService { } if (excelModel.isScmFunctionPlaceholderPresent()) { - addSCMEntryRows(sheet, fileModel, excelModel); + componentRowsReportService.addComponentRows(sheet, fileModel, excelModel); } if (isLastFile) { @@ -239,35 +239,7 @@ public class ExcelReportGenerationService { } - 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 = rSSPoc2Service.getOecdNumber(fileModel); - - for (Map.Entry entry : scmResultMap.entrySet()) { - - sheet.createRow(rowIndex.get()); - excelModel.getWrittenRows().add(rowIndex.get()); - - Cell keyCell = sheet.getRow(rowIndex.get()).createCell(0); - keyCell.setCellValue(oecd + "-" + entry.getKey().replaceAll("_", " ")); - - Cell valueCell = sheet.getRow(rowIndex.get()).createCell(1); - valueCell.setCellValue(entry.getValue().getValue() != null ? entry.getValue().getValue() : entry.getValue().getOriginalValue()); - - rowIndex.getAndIncrement(); - } - - sheet.createRow(rowIndex.get()); - excelModel.getWrittenRows().add(rowIndex.get()); - - excelModel.setRedactionPlaceholderRow(rowIndex.getAndIncrement()); - - } private void replacePlaceholders(Cell cell, PlaceholderModel placeholderModel, String dossierName, String filename) {