Merge branch 'DM-285' into 'master'

Resolve DM-285

Closes DM-285

See merge request redactmanager/redaction-report-service!10
This commit is contained in:
Kilian Schüttler 2023-10-04 17:23:50 +02:00
commit 777aa4a32b
7 changed files with 128 additions and 33 deletions

27
publish-custom-docker-img.sh Executable file
View File

@ -0,0 +1,27 @@
#!/bin/bash
# This script compiles the project, builds a docker image with the tag <BranchName>-<CommitHash> and pushes it to our nexus.
# Set the Nexus repository URL
NEXUS_REPO="nexus.knecon.com:5001"
# Set the image name
IMAGE_NAME="red/redaction-report-service-server-v1"
# path to image repo
IMAGE_REPO="redaction-report-service-image-v1"
echo "Running build"
mvn clean install -Pquickbuild
# Get the current Git branch
GIT_BRANCH=$(git symbolic-ref --short HEAD)
# Get the first 5 characters of the commit hash
GIT_COMMIT_HASH=$(git rev-parse --short=5 HEAD)
# Create the image tag by combining branch and commit hash
IMAGE_TAG="${GIT_BRANCH}-${GIT_COMMIT_HASH}"
IMAGE_NAME="$NEXUS_REPO/$IMAGE_NAME:$IMAGE_TAG"
echo "Building docker image: {$IMAGE_NAME}"
# Build the Docker image with the specified name and tag and push to nexus
mvn -f $IMAGE_REPO docker:build docker:push -Ddocker.image.version=$IMAGE_TAG
echo "Docker image '$IMAGE_NAME' has been built and pushed to Nexus."

View File

@ -24,7 +24,7 @@
<properties>
<persistence-service.version>2.79.0</persistence-service.version>
<persistence-service.version>2.198.0</persistence-service.version>
<apache-poi.version>5.2.3</apache-poi.version>
</properties>

View File

@ -84,6 +84,11 @@
</exclusions>
</dependency>
<dependency>
<groupId>com.iqser.red.service</groupId>
<artifactId>persistence-service-internal-api-v1</artifactId>
<version>${persistence-service.version}</version>
</dependency>
<dependency>
<groupId>com.iqser.red.commons</groupId>
<artifactId>test-commons</artifactId>

View File

@ -0,0 +1,10 @@
package com.iqser.red.service.redaction.report.v1.server.client;
import org.springframework.cloud.openfeign.FeignClient;
import com.iqser.red.service.persistence.service.v1.api.internal.resources.InternalComponentResource;
@FeignClient(name = "InternalComponentResource", url = "${persistence-service.url}")
public interface ComponentClient extends InternalComponentResource {
}

View File

@ -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);
}
}

View File

@ -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<String, SCMComponent> 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) {

View File

@ -44,7 +44,7 @@ public class StatusReportGenerationServiceTest {
String dossierId = "dossierId";
Dossier dossier = Dossier.builder().dossierName("dossierName").id(dossierId).build();
Dossier dossier = Dossier.builder().name("dossierName").id(dossierId).build();
when(dossierClient.getDossierById(dossierId, true, false)).thenReturn(dossier);
FileModel fileStatus1 = FileModel.builder()