RED-4036 - improved report service performance, added some logs
This commit is contained in:
parent
8988d3ed49
commit
cb8e044d76
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>com.iqser.red</groupId>
|
||||
<artifactId>platform-docker-dependency</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>1.2.0</version>
|
||||
<relativePath />
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
@ -41,7 +41,7 @@
|
||||
<artifactId>docker-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<dependency>
|
||||
<groupId>com.iqser.red</groupId>
|
||||
<artifactId>platform-commons-dependency</artifactId>
|
||||
<version>1.11.0</version>
|
||||
<version>1.13.0</version>
|
||||
<scope>import</scope>
|
||||
<type>pom</type>
|
||||
</dependency>
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<persistence-service.version>1.160.0</persistence-service.version>
|
||||
<redaction-service.version>3.108.0</redaction-service.version>
|
||||
<persistence-service.version>1.169.0</persistence-service.version>
|
||||
<redaction-service.version>3.109.0</redaction-service.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@ -1,13 +1,8 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@ -15,5 +10,6 @@ public class MultiFileDocument {
|
||||
|
||||
private XWPFDocument document;
|
||||
private String templateId;
|
||||
private String templateName;
|
||||
|
||||
}
|
||||
|
||||
@ -10,5 +10,6 @@ public class MultiFileWorkbook {
|
||||
|
||||
private XSSFWorkbook workbook;
|
||||
private String templateId;
|
||||
private String templateName;
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.model;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlaceholderModel {
|
||||
|
||||
private List<String> placeholders;
|
||||
private List<ImagePlaceholder> imagePlaceholders;
|
||||
private Map<String, String> dossierAttributesPlaceholder;
|
||||
private Map<String, String> fileAttributePlaceHolders;
|
||||
|
||||
|
||||
}
|
||||
@ -37,6 +37,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||
@ -67,94 +68,40 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@RequiredArgsConstructor
|
||||
public class ExcelTemplateReportGenerationService {
|
||||
|
||||
private final DossierAttributesClient dossierAttributesClient;
|
||||
private final DossierAttributesConfigClient dossierAttributesConfigClient;
|
||||
private final FileAttributesConfigClient fileAttributesClient;
|
||||
|
||||
|
||||
public void generateReport(List<ReportRedactionEntry> reportEntries, String dossierTemplateId,
|
||||
public void generateReport(List<ReportRedactionEntry> reportEntries,
|
||||
PlaceholderModel placeholderModel,
|
||||
String reportTemplateName,
|
||||
XSSFWorkbook workbook, FileModel fileStatus, Dossier dossier, boolean isLastFile) {
|
||||
|
||||
List<String> placeholders = getDefaultPlaceholders();
|
||||
List<ImagePlaceholder> imagePlaceholders = new ArrayList<>();
|
||||
|
||||
var dossierAttributes = dossierAttributesClient.getDossierAttributes(dossier.getId());
|
||||
var dossierAttributesConfig = dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId);
|
||||
|
||||
Map<String, String> dossierAttributesPlaceholder = new HashMap<>(); //KEY:placeholder, VALUE:value
|
||||
|
||||
for (DossierAttributeConfig attributeConfig : dossierAttributesConfig) {
|
||||
for (DossierAttribute dossierAttribute : dossierAttributes) {
|
||||
if (dossierAttribute.getDossierAttributeConfigId().equals(attributeConfig.getId())) {
|
||||
if (attributeConfig.getType().equals(DossierAttributeType.IMAGE)) {
|
||||
|
||||
if (dossierAttribute.getValue() != null) {
|
||||
if (dossierAttribute.getValue().startsWith("data:")) {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder()
|
||||
.decode(dossierAttribute.getValue().split(",")[1])));
|
||||
} else {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder()
|
||||
.decode(dossierAttribute.getValue())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (dossierAttribute.getValue() == null) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
} else {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), dossierAttribute.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dossierAttributesPlaceholder.containsKey(attributeConfig.getPlaceholder())) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> fileAttributePlaceholders = getFileAttributePlaceholders(dossierTemplateId);
|
||||
placeholders.addAll(fileAttributePlaceholders.keySet());
|
||||
placeholders.addAll(dossierAttributesPlaceholder.keySet());
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
for (Sheet sheet : workbook) {
|
||||
addEntryRows(sheet, reportEntries, fileStatus.getFilename(), isLastFile);
|
||||
|
||||
for (ImagePlaceholder imagePlaceholder : imagePlaceholders) {
|
||||
for (ImagePlaceholder imagePlaceholder : placeholderModel.getImagePlaceholders()){
|
||||
replacePlaceholdersForImagePlaceholder(workbook, sheet, imagePlaceholder);
|
||||
}
|
||||
for (String placeholder : placeholders) {
|
||||
String placeholderValue = getPlaceholderValue(placeholder, dossier, fileStatus, fileAttributePlaceholders, dossierAttributesPlaceholder);
|
||||
for (String placeholder : placeholderModel.getPlaceholders()) {
|
||||
String placeholderValue = getPlaceholderValue(placeholder, dossier, fileStatus, placeholderModel.getFileAttributePlaceHolders(), placeholderModel.getDossierAttributesPlaceholder());
|
||||
if (placeholderValue != null) {
|
||||
replacePlaceholdersForTextPlaceholder(sheet, placeholder, placeholderValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}", end - start,
|
||||
fileStatus.getId(), fileStatus.getNumberOfPages(), reportEntries.size(), reportTemplateName, getClass().getSimpleName());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<String> getDefaultPlaceholders() {
|
||||
|
||||
List<String> defPlaceholders = new ArrayList<>();
|
||||
defPlaceholders.addAll(Arrays.asList(FILE_NAME_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER));
|
||||
return defPlaceholders;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> getFileAttributePlaceholders(String dossierTemplateId) {
|
||||
|
||||
Map<String, String> fileAttributePlaceholders = new HashMap<>();
|
||||
|
||||
var fileAttributesConfig = fileAttributesClient.getFileAttributeConfigs(dossierTemplateId);
|
||||
fileAttributesConfig.forEach(fileAttributeConfig -> {
|
||||
fileAttributePlaceholders.put(fileAttributeConfig.getPlaceholder(), fileAttributeConfig.getId());
|
||||
});
|
||||
return fileAttributePlaceholders;
|
||||
}
|
||||
|
||||
|
||||
private void addEntryRows(Sheet sheet, List<ReportRedactionEntry> reportEntries, String filename,
|
||||
@ -386,4 +333,5 @@ public class ExcelTemplateReportGenerationService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,95 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.service;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.DossierAttributeConfig;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierAttribute;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierAttributeType;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ImagePlaceholder;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.*;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.DOSSIER_NAME_PLACEHOLDER;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class GeneratePlaceholderService {
|
||||
|
||||
private final FileAttributesConfigClient fileAttributesClient;
|
||||
private final DossierAttributesClient dossierAttributesClient;
|
||||
private final DossierAttributesConfigClient dossierAttributesConfigClient;
|
||||
|
||||
|
||||
public PlaceholderModel buildPlaceholders(Dossier dossier){
|
||||
|
||||
|
||||
var dossierAttributes = dossierAttributesClient.getDossierAttributes(dossier.getId());
|
||||
var dossierAttributesConfig = dossierAttributesConfigClient.getDossierAttributes(dossier.getDossierTemplateId());
|
||||
var fileAttributePlaceHolders = getFileAttributePlaceholders(dossier.getDossierTemplateId());
|
||||
|
||||
List<String> placeholders = getDefaultPlaceholders();
|
||||
List<ImagePlaceholder> imagePlaceholders = new ArrayList<>();
|
||||
|
||||
|
||||
Map<String, String> dossierAttributesPlaceholder = new HashMap<>(); //KEY:placeholder, VALUE:value
|
||||
|
||||
for (DossierAttributeConfig attributeConfig : dossierAttributesConfig) {
|
||||
for (DossierAttribute dossierAttribute : dossierAttributes) {
|
||||
if (dossierAttribute.getDossierAttributeConfigId().equals(attributeConfig.getId())) {
|
||||
if (attributeConfig.getType().equals(DossierAttributeType.IMAGE)) {
|
||||
|
||||
if (dossierAttribute.getValue() != null) {
|
||||
if (dossierAttribute.getValue().startsWith("data:")) {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder()
|
||||
.decode(dossierAttribute.getValue().split(",")[1])));
|
||||
} else {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder().decode(dossierAttribute.getValue())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (dossierAttribute.getValue() == null) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
} else {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), dossierAttribute.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dossierAttributesPlaceholder.containsKey(attributeConfig.getPlaceholder())) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
}
|
||||
}
|
||||
|
||||
placeholders.addAll(fileAttributePlaceHolders.keySet());
|
||||
placeholders.addAll(dossierAttributesPlaceholder.keySet());
|
||||
|
||||
return new PlaceholderModel(placeholders,imagePlaceholders,dossierAttributesPlaceholder,fileAttributePlaceHolders);
|
||||
}
|
||||
|
||||
|
||||
private List<String> getDefaultPlaceholders() {
|
||||
|
||||
List<String> defPlaceholders = new ArrayList<>();
|
||||
defPlaceholders.addAll(Arrays.asList(FILE_NAME_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER));
|
||||
return defPlaceholders;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private Map<String, String> getFileAttributePlaceholders(String dossierTemplateId) {
|
||||
|
||||
Map<String, String> fileAttributePlaceholders = new HashMap<>();
|
||||
|
||||
var fileAttributesConfig = fileAttributesClient.getFileAttributeConfigs(dossierTemplateId);
|
||||
fileAttributesConfig.forEach(fileAttributeConfig -> {
|
||||
fileAttributePlaceholders.put(fileAttributeConfig.getPlaceholder(), fileAttributeConfig.getId());
|
||||
});
|
||||
return fileAttributePlaceholders;
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ package com.iqser.red.service.redaction.report.v1.server.service;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.annotations.AnnotationStatus;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportRequestMessage;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
|
||||
@ -12,6 +13,7 @@ import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClien
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.MultiFileDocument;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.MultiFileWorkbook;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
|
||||
import com.iqser.red.service.redaction.v1.model.ManualChange;
|
||||
@ -22,13 +24,17 @@ import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ -43,13 +49,16 @@ public class ReportGenerationService {
|
||||
private final ReportTemplateClient reportTemplateClient;
|
||||
private final RedactionLogClient redactionLogClient;
|
||||
private final ExcelTemplateReportGenerationService excelTemplateReportGenerationService;
|
||||
private final GeneratePlaceholderService generatePlaceholderService;
|
||||
|
||||
@Value("${redaction-report-service.numberOfReportGenerationThreads:4}")
|
||||
private int numberOfReportGenerationThreads;
|
||||
|
||||
public List<StoredFileInformation> generateReport(ReportRequestMessage reportMessage) {
|
||||
|
||||
List<StoredFileInformation> storedFileInformation = new ArrayList<>();
|
||||
List<StoredFileInformation> storedFileInformation = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
Dossier project = dossierClient.getDossierById(reportMessage.getDossierId(), true,false);
|
||||
Dossier dossier = dossierClient.getDossierById(reportMessage.getDossierId(), true, false);
|
||||
|
||||
List<ReportTemplate> singleFilesTemplates = new ArrayList<>();
|
||||
List<MultiFileWorkbook> multiFileWorkbooks = new ArrayList<>();
|
||||
@ -58,11 +67,11 @@ public class ReportGenerationService {
|
||||
try {
|
||||
ReportTemplate reportTemplate = reportTemplateClient.getReportTemplate(reportMessage.getDossierTemplateId(), templateId);
|
||||
if (reportTemplate.isMultiFileReport()) {
|
||||
if(reportTemplate.getFileName().endsWith(".xlsx")) {
|
||||
if (reportTemplate.getFileName().endsWith(".xlsx")) {
|
||||
byte[] excelTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(excelTemplate)) {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
||||
MultiFileWorkbook multiFileWorkbook = new MultiFileWorkbook(workbook, templateId);
|
||||
MultiFileWorkbook multiFileWorkbook = new MultiFileWorkbook(workbook, templateId, reportTemplate.getFileName());
|
||||
multiFileWorkbooks.add(multiFileWorkbook);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate multifile excel report.");
|
||||
@ -71,7 +80,7 @@ public class ReportGenerationService {
|
||||
byte[] wordTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(wordTemplate)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
MultiFileDocument multiFileDocument = new MultiFileDocument(doc, templateId);
|
||||
MultiFileDocument multiFileDocument = new MultiFileDocument(doc, templateId, reportTemplate.getFileName());
|
||||
multiFileDocuments.add(multiFileDocument);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate multifile word report.");
|
||||
@ -85,6 +94,9 @@ public class ReportGenerationService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var placeholderModel = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
|
||||
int i = 1;
|
||||
for (int j = 0; j < reportMessage.getFileIds().size(); j++) {
|
||||
|
||||
@ -96,41 +108,30 @@ public class ReportGenerationService {
|
||||
List<ReportRedactionEntry> reportEntries = getReportEntries(reportMessage.getDossierId(), reportMessage.getFileIds()
|
||||
.get(j), fileStatus.isExcluded());
|
||||
|
||||
for (MultiFileWorkbook multiFileWorkbook : multiFileWorkbooks) {
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, reportMessage.getDossierTemplateId(), multiFileWorkbook.getWorkbook(), fileStatus, project, j == reportMessage.getFileIds()
|
||||
.size() - 1);
|
||||
}
|
||||
ExecutorService executor = Executors.newFixedThreadPool(numberOfReportGenerationThreads);
|
||||
|
||||
var isLastFile = j == reportMessage.getFileIds()
|
||||
.size() - 1;
|
||||
|
||||
for (MultiFileWorkbook multiFileWorkbook : multiFileWorkbooks)
|
||||
executor.submit(() -> excelTemplateReportGenerationService.generateReport(reportEntries,
|
||||
placeholderModel, multiFileWorkbook.getTemplateName(),
|
||||
multiFileWorkbook.getWorkbook(), fileStatus, dossier, isLastFile));
|
||||
|
||||
for (MultiFileDocument multiFileDocument : multiFileDocuments) {
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_TEMPLATE_MULTI_FILE, reportEntries, reportMessage.getDossierTemplateId(), multiFileDocument.getDocument(), fileStatus, project, j == reportMessage.getFileIds()
|
||||
.size() - 1);
|
||||
executor.submit(() ->
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholderModel, multiFileDocument.getTemplateName(), multiFileDocument.getDocument(), fileStatus, dossier, isLastFile)
|
||||
);
|
||||
}
|
||||
|
||||
for (ReportTemplate reportTemplate : singleFilesTemplates) {
|
||||
if (reportTemplate.getFileName().endsWith(".xlsx")) {
|
||||
byte[] excelTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(excelTemplate)) {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, reportMessage.getDossierTemplateId(), workbook, fileStatus, project, true);
|
||||
byte[] template = excelTemplateReportGenerationService.toByteArray(workbook);
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template);
|
||||
storedFileInformation.add(new StoredFileInformation(reportMessage.getFileIds()
|
||||
.get(j), storageId, ReportType.EXCEL_TEMPLATE_SINGLE_FILE, reportTemplate.getTemplateId()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate singlefile excel report.");
|
||||
}
|
||||
} else {
|
||||
byte[] wordTemplate= reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(wordTemplate)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, reportMessage.getDossierTemplateId(), doc, fileStatus, project, true);
|
||||
byte[] template = wordReportGenerationService.toByteArray(doc);
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template);
|
||||
storedFileInformation.add(new StoredFileInformation(reportMessage.getFileIds().get(j), storageId, ReportType.WORD_SINGLE_FILE, reportTemplate.getTemplateId()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate singlefile word report.");
|
||||
}
|
||||
}
|
||||
executor.submit(() ->
|
||||
storedFileInformation.add(createReportFromTemplate(dossier, fileStatus, placeholderModel, reportTemplate.getFileName(), reportMessage.getDownloadId(), reportEntries, reportTemplate))
|
||||
);
|
||||
}
|
||||
|
||||
executor.shutdown();
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
log.info("Successfully processed {}/{} fileIds for downloadId {}, took {}", i, reportMessage.getFileIds()
|
||||
.size(), reportMessage.getDownloadId(), end - start);
|
||||
@ -146,13 +147,44 @@ public class ReportGenerationService {
|
||||
for (MultiFileDocument multiFileDocument : multiFileDocuments) {
|
||||
byte[] template = wordReportGenerationService.toByteArray(multiFileDocument.getDocument());
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template);
|
||||
storedFileInformation.add(new StoredFileInformation( null, storageId, ReportType.WORD_TEMPLATE_MULTI_FILE, multiFileDocument.getTemplateId()));
|
||||
storedFileInformation.add(new StoredFileInformation(null, storageId, ReportType.WORD_TEMPLATE_MULTI_FILE, multiFileDocument.getTemplateId()));
|
||||
}
|
||||
|
||||
return storedFileInformation;
|
||||
}
|
||||
|
||||
|
||||
private StoredFileInformation createReportFromTemplate(Dossier dossier, FileModel fileStatus,
|
||||
PlaceholderModel placeholderModel,
|
||||
String templateName,
|
||||
String downloadId,
|
||||
List<ReportRedactionEntry> reportEntries, ReportTemplate reportTemplate) {
|
||||
if (reportTemplate.getFileName().endsWith(".xlsx")) {
|
||||
byte[] excelTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(excelTemplate)) {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, placeholderModel, templateName, workbook, fileStatus, dossier, true);
|
||||
byte[] template = excelTemplateReportGenerationService.toByteArray(workbook);
|
||||
String storageId = reportStorageService.storeObject(downloadId, template);
|
||||
return new StoredFileInformation(fileStatus.getId(), storageId, ReportType.EXCEL_TEMPLATE_SINGLE_FILE, reportTemplate.getTemplateId());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate singlefile excel report.");
|
||||
}
|
||||
} else {
|
||||
byte[] wordTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(wordTemplate)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholderModel, templateName, doc, fileStatus, dossier, true);
|
||||
byte[] template = wordReportGenerationService.toByteArray(doc);
|
||||
String storageId = reportStorageService.storeObject(downloadId, template);
|
||||
return new StoredFileInformation(fileStatus.getId(), storageId, ReportType.WORD_SINGLE_FILE, reportTemplate.getTemplateId());
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate singlefile word report.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private List<ReportRedactionEntry> getReportEntries(String dossierId, String fileId, boolean isExcluded) {
|
||||
|
||||
if (isExcluded) {
|
||||
@ -165,10 +197,10 @@ public class ReportGenerationService {
|
||||
|
||||
//filter DECLINED redactions out, they should not be in reports
|
||||
Iterator<RedactionLogEntry> iter = redactionLog.getRedactionLogEntry().iterator();
|
||||
while(iter.hasNext()) {
|
||||
while (iter.hasNext()) {
|
||||
RedactionLogEntry redactionLogEntry = iter.next();
|
||||
for(ManualChange manualChange : redactionLogEntry.getManualChanges()) {
|
||||
if(manualChange.getAnnotationStatus().equals(AnnotationStatus.DECLINED)) {
|
||||
for (ManualChange manualChange : redactionLogEntry.getManualChanges()) {
|
||||
if (manualChange.getAnnotationStatus().equals(AnnotationStatus.DECLINED)) {
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
@ -181,4 +213,5 @@ public class ReportGenerationService {
|
||||
return redactionLogConverterService.convertAndSort(redactionLog, legalBasisMappings);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,157 +1,83 @@
|
||||
package com.iqser.red.service.redaction.report.v1.server.service;
|
||||
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.DOSSIER_NAME_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.EXCERPT_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FILE_NAME_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ENG;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ENG_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_GER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_GER_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ISO;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_DATE_ISO_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.FORMAT_TIME_ISO_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.IUCLID_FUNCTION_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_LEGAL_BASIS_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PARAGRAPH_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_REASON_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.JUSTIFICATION_TEXT_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PAGE_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.PARAGRAPH_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.SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ColoredText;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ImagePlaceholder;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.PlaceholderModel;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.util.Dimension2DDouble;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
||||
import org.apache.poi.util.Dimension2DDouble;
|
||||
import org.apache.poi.util.Units;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFRun;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTable;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableCell;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFTableRow;
|
||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.DossierAttributeConfig;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.ReportTemplate;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.Dossier;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierAttribute;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierAttributeType;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ColoredText;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ImagePlaceholder;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import static com.iqser.red.service.redaction.report.v1.server.service.PlaceholderService.*;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class WordReportGenerationService {
|
||||
|
||||
private final FileAttributesConfigClient fileAttributesClient;
|
||||
private final DossierAttributesClient dossierAttributesClient;
|
||||
private final DossierAttributesConfigClient dossierAttributesConfigClient;
|
||||
|
||||
private final IuclidFunctionService iuclidFunctionService;
|
||||
|
||||
|
||||
public XWPFDocument generateReport(ReportType reportType, List<ReportRedactionEntry> reportEntries, String dossierTemplateId, XWPFDocument doc, FileModel fileStatus,
|
||||
Dossier dossier, boolean isLastFile) {
|
||||
|
||||
List<String> placeholders = getDefaultPlaceholders();
|
||||
List<ImagePlaceholder> imagePlaceholders = new ArrayList<>();
|
||||
|
||||
var dossierAttributes = dossierAttributesClient.getDossierAttributes(dossier.getId());
|
||||
var dossierAttributesConfig = dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId);
|
||||
|
||||
Map<String, String> dossierAttributesPlaceholder = new HashMap<>(); //KEY:placeholder, VALUE:value
|
||||
|
||||
for (DossierAttributeConfig attributeConfig : dossierAttributesConfig) {
|
||||
for (DossierAttribute dossierAttribute : dossierAttributes) {
|
||||
if (dossierAttribute.getDossierAttributeConfigId().equals(attributeConfig.getId())) {
|
||||
if (attributeConfig.getType().equals(DossierAttributeType.IMAGE)) {
|
||||
|
||||
if (dossierAttribute.getValue() != null) {
|
||||
if (dossierAttribute.getValue().startsWith("data:")) {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder()
|
||||
.decode(dossierAttribute.getValue().split(",")[1])));
|
||||
} else {
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder().decode(dossierAttribute.getValue())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (dossierAttribute.getValue() == null) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
} else {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), dossierAttribute.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!dossierAttributesPlaceholder.containsKey(attributeConfig.getPlaceholder())) {
|
||||
dossierAttributesPlaceholder.put(attributeConfig.getPlaceholder(), "");
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> fileAttributePlaceholders = getFileAttributePlaceholders(dossierTemplateId);
|
||||
placeholders.addAll(fileAttributePlaceholders.keySet());
|
||||
placeholders.addAll(dossierAttributesPlaceholder.keySet());
|
||||
public XWPFDocument generateReport(List<ReportRedactionEntry> reportEntries,
|
||||
PlaceholderModel placeholderModel,
|
||||
String reportTemplateName,
|
||||
XWPFDocument doc, FileModel fileStatus,
|
||||
Dossier dossier, boolean isLastFile) {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
|
||||
try {
|
||||
|
||||
for (ImagePlaceholder imagePlaceholder : imagePlaceholders) {
|
||||
for (ImagePlaceholder imagePlaceholder : placeholderModel.getImagePlaceholders()) {
|
||||
replaceImagePlaceholders(doc, imagePlaceholder);
|
||||
}
|
||||
XWPFTable table = getRedactionTable(doc);
|
||||
Map<Integer, String> placeholderCellPos = computePlaceholderPos(table);
|
||||
addTableRows(table, reportEntries, fileStatus.getFilename(), fileStatus, fileAttributePlaceholders, placeholderCellPos);
|
||||
for (String placeholder : placeholders) {
|
||||
String placeholderValue = getPlaceholderValue(placeholder, dossier, fileStatus, fileAttributePlaceholders, dossierAttributesPlaceholder, reportEntries);
|
||||
addTableRows(table, reportEntries, fileStatus.getFilename(), fileStatus, placeholderModel.getFileAttributePlaceHolders(), placeholderCellPos);
|
||||
for (String placeholder : placeholderModel.getPlaceholders()) {
|
||||
String placeholderValue = getPlaceholderValue(placeholder, dossier, fileStatus, placeholderModel.getFileAttributePlaceHolders(), placeholderModel.getDossierAttributesPlaceholder(), reportEntries);
|
||||
if (placeholderValue != null) {
|
||||
replaceTextPlaceholders(doc, placeholder, placeholderValue);
|
||||
}
|
||||
}
|
||||
if(!isLastFile) {
|
||||
if (!isLastFile) {
|
||||
readdPlaceholders(table, placeholderCellPos);
|
||||
}
|
||||
|
||||
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
log.info("Report Generation took: {} for file with id {}, pageCount: {}, redactionLogEntryCount: {}, reportName: {}, className: {}", end - start,
|
||||
fileStatus.getId(), fileStatus.getNumberOfPages(), reportEntries.size(), reportTemplateName, getClass().getSimpleName());
|
||||
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage() + " in file: " + fileStatus.getFilename());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -168,26 +94,6 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private List<String> getDefaultPlaceholders() {
|
||||
|
||||
List<String> defPlaceholders = new ArrayList<>();
|
||||
defPlaceholders.addAll(Arrays.asList(FILE_NAME_PLACEHOLDER, FORMAT_DATE_ISO_PLACEHOLDER, FORMAT_DATE_GER_PLACEHOLDER, FORMAT_DATE_ENG_PLACEHOLDER, FORMAT_TIME_ISO_PLACEHOLDER, DOSSIER_NAME_PLACEHOLDER, IUCLID_FUNCTION_PLACEHOLDER, SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER, SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER));
|
||||
return defPlaceholders;
|
||||
}
|
||||
|
||||
|
||||
private Map<String, String> getFileAttributePlaceholders(String dossierTemplateId) {
|
||||
|
||||
Map<String, String> fileAttributePlaceholders = new HashMap<>();
|
||||
|
||||
var fileAttributesConfig = fileAttributesClient.getFileAttributeConfigs(dossierTemplateId);
|
||||
fileAttributesConfig.forEach(fileAttributeConfig -> {
|
||||
fileAttributePlaceholders.put(fileAttributeConfig.getPlaceholder(), fileAttributeConfig.getId());
|
||||
});
|
||||
return fileAttributePlaceholders;
|
||||
}
|
||||
|
||||
|
||||
private String getPlaceholderValue(String placeholder, Dossier project, FileModel fileStatus, Map<String, String> fileAttributePlaceholders,
|
||||
Map<String, String> dossierAttributesPlaceholders, List<ReportRedactionEntry> reportRedactionEntries) {
|
||||
|
||||
@ -326,7 +232,7 @@ public class WordReportGenerationService {
|
||||
private Map<Integer, String> computePlaceholderPos(XWPFTable table) {
|
||||
Map<Integer, String> placeholderCellPos = new HashMap<>();
|
||||
|
||||
if(table != null) {
|
||||
if (table != null) {
|
||||
int placeholderRow = -1;
|
||||
for (int j = 0; j < table.getRows().size(); j++) {
|
||||
for (int i = 0; i < table.getRows().get(j).getTableCells().size(); i++) {
|
||||
@ -378,7 +284,7 @@ public class WordReportGenerationService {
|
||||
|
||||
private void readdPlaceholders(XWPFTable table, Map<Integer, String> placeholderCellPos) {
|
||||
XWPFTableRow newRow = table.createRow();
|
||||
for(int i = 0; i < table.getRow(0).getTableCells().size(); i++) {
|
||||
for (int i = 0; i < table.getRow(0).getTableCells().size(); i++) {
|
||||
String placeholder = placeholderCellPos.get(i);
|
||||
setText(newRow.getCell(i), placeholder);
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.do
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileAttributeType;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.file.FileModel;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.legalbasis.LegalBasis;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportType;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.DossierAttributesConfigClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.FileAttributesConfigClient;
|
||||
@ -20,6 +19,7 @@ import com.iqser.red.service.redaction.report.v1.server.client.ReportTemplateCli
|
||||
import com.iqser.red.service.redaction.report.v1.server.configuration.MessagingConfiguration;
|
||||
import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.service.ExcelTemplateReportGenerationService;
|
||||
import com.iqser.red.service.redaction.report.v1.server.service.GeneratePlaceholderService;
|
||||
import com.iqser.red.service.redaction.report.v1.server.service.RedactionLogConverterService;
|
||||
import com.iqser.red.service.redaction.report.v1.server.service.WordReportGenerationService;
|
||||
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
|
||||
@ -86,6 +86,9 @@ public class RedactionReportIntegrationTest {
|
||||
@Autowired
|
||||
private ExcelTemplateReportGenerationService excelTemplateReportGenerationService;
|
||||
|
||||
@Autowired
|
||||
private GeneratePlaceholderService generatePlaceholderService;
|
||||
|
||||
@Test
|
||||
public void testWordReportGeneration() throws IOException {
|
||||
|
||||
@ -159,7 +162,7 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
FileModel fileStatus = FileModel.builder().filename("FileABCD").fileAttributes(Map.of("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test")).build();
|
||||
|
||||
Dossier project = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
String templateId = "templateId";
|
||||
String storageId = "storageId";
|
||||
@ -170,8 +173,9 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds - New Justification Form.docx");
|
||||
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileStatus, project, true);
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholders, "test", doc, fileStatus, dossier, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template_wrg.docx")) {
|
||||
@ -226,8 +230,10 @@ public class RedactionReportIntegrationTest {
|
||||
.storageId(storageId)
|
||||
.build());
|
||||
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, placeholders, "test", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, placeholders, "test", workbook, fileModel2, dossier, true);
|
||||
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/test_report_excel_template.xlsx")) {
|
||||
@ -281,7 +287,7 @@ public class RedactionReportIntegrationTest {
|
||||
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(attributeIdToValue).build();
|
||||
FileModel fileModel2 = FileModel.builder().filename("other file").fileAttributes(attributeIdToValue).build();
|
||||
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
|
||||
.dossierTemplateId(dossierTemplateId)
|
||||
@ -290,15 +296,17 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
ClassPathResource wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
|
||||
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileModel, dossier, true);
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true);
|
||||
byte[] wordReport = wordReportGenerationService.toByteArray(doc);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template1.docx")) {
|
||||
fileOutputStream.write(wordReport);
|
||||
}
|
||||
|
||||
doc = new XWPFDocument(wordTemplateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries2, dossierTemplateId, doc, fileModel2, dossier, true);
|
||||
wordReportGenerationService.generateReport(reportEntries2, placeholders, "test", doc, fileModel2, dossier, true);
|
||||
byte[] wordReport2 = wordReportGenerationService.toByteArray(doc);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template2.docx")) {
|
||||
fileOutputStream.write(wordReport2);
|
||||
@ -306,20 +314,20 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
ClassPathResource excelTemplateResource = new ClassPathResource("templates/Excel Report.xlsx");
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(excelTemplateResource.getInputStream());
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, placeholders, "test", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, placeholders, "test", workbook, fileModel2, dossier, true);
|
||||
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/report_excel_template.xlsx")) {
|
||||
fileOutputStream.write(excelTemplateReport);
|
||||
}
|
||||
XSSFWorkbook workbook2 = new XSSFWorkbook(excelTemplateResource.getInputStream());
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, "dossierTemplateId", workbook2, fileModel, dossier, true);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, placeholders, "test", workbook2, fileModel, dossier, true);
|
||||
byte[] excelTemplateReport2 = excelTemplateReportGenerationService.toByteArray(workbook2);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/report_excel_template2.xlsx")) {
|
||||
fileOutputStream.write(excelTemplateReport2);
|
||||
}
|
||||
XSSFWorkbook workbook3 = new XSSFWorkbook(excelTemplateResource.getInputStream());
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook3, fileModel2, dossier, true);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, placeholders, "test", workbook3, fileModel2, dossier, true);
|
||||
byte[] excelTemplateReport3 = excelTemplateReportGenerationService.toByteArray(workbook3);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/report_excel_template3.xlsx")) {
|
||||
fileOutputStream.write(excelTemplateReport3);
|
||||
@ -368,7 +376,7 @@ public class RedactionReportIntegrationTest {
|
||||
attributeIdToValue.put("3e9b9569-5d2e-4619-848b-dd0a3e96527f", "Test");
|
||||
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(attributeIdToValue).build();
|
||||
|
||||
Dossier project = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
String templateId = "templateId";
|
||||
String storageId = "storageId";
|
||||
@ -378,9 +386,9 @@ public class RedactionReportIntegrationTest {
|
||||
.build());
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx");
|
||||
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileModel, project, true);
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholders, "test", doc, fileModel, dossier, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template13.docx")) {
|
||||
@ -416,7 +424,7 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
FileModel fileStatus = FileModel.builder().filename("VV123456").build();
|
||||
|
||||
Dossier project = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
String templateId = "templateId";
|
||||
String storageId = "storageId";
|
||||
@ -434,9 +442,9 @@ public class RedactionReportIntegrationTest {
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileStatus, project, true);
|
||||
wordReportGenerationService.generateReport(reportEntries, placeholders, "test", doc, fileStatus, dossier, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/iuclid_report_2.docx")) {
|
||||
@ -490,7 +498,7 @@ public class RedactionReportIntegrationTest {
|
||||
FileModel fileModel = FileModel.builder().filename("filename").fileAttributes(attributeIdToValue).build();
|
||||
FileModel fileModel2 = FileModel.builder().filename("other file").fileAttributes(attributeIdToValue).build();
|
||||
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
when(reportTemplateClient.getReportTemplate(dossierTemplateId, templateId)).thenReturn(ReportTemplate.builder()
|
||||
.dossierTemplateId(dossierTemplateId)
|
||||
@ -499,8 +507,9 @@ public class RedactionReportIntegrationTest {
|
||||
|
||||
ClassPathResource excelTemplateResource = new ClassPathResource("templates/Excel Report.xlsx");
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(excelTemplateResource.getInputStream());
|
||||
excelTemplateReportGenerationService.generateReport(emptyReportEntries, "dossierTemplateId", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, "dossierTemplateId", workbook, fileModel2, dossier, true);
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
excelTemplateReportGenerationService.generateReport(emptyReportEntries, placeholders, "test", workbook, fileModel, dossier, false);
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries2, placeholders, "test", workbook, fileModel2, dossier, true);
|
||||
byte[] excelTemplateReport = excelTemplateReportGenerationService.toByteArray(workbook);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/report_excel_templateAAA.xlsx")) {
|
||||
fileOutputStream.write(excelTemplateReport);
|
||||
@ -533,7 +542,7 @@ public class RedactionReportIntegrationTest {
|
||||
FileModel fileStatus = FileModel.builder().filename("VV123456").build();
|
||||
FileModel fileStatus2 = FileModel.builder().filename("second file").build();
|
||||
|
||||
Dossier project = Dossier.builder().id("dossierId").dossierName("projectName").build();
|
||||
Dossier dossier = Dossier.builder().id("dossierId").dossierName("dossierName").build();
|
||||
|
||||
String templateId = "templateId";
|
||||
String storageId = "storageId";
|
||||
@ -545,8 +554,10 @@ public class RedactionReportIntegrationTest {
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds-NewJustificationForm.docx");
|
||||
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
doc = wordReportGenerationService.generateReport(ReportType.WORD_TEMPLATE_MULTI_FILE, reportEntries, dossierTemplateId, doc, fileStatus, project, false);
|
||||
doc = wordReportGenerationService.generateReport(ReportType.WORD_TEMPLATE_MULTI_FILE, reportEntries2, dossierTemplateId, doc, fileStatus2, project, true);
|
||||
var placeholders = generatePlaceholderService.buildPlaceholders(dossier);
|
||||
|
||||
doc = wordReportGenerationService.generateReport(reportEntries, placeholders, "test", doc, fileStatus, dossier, false);
|
||||
doc = wordReportGenerationService.generateReport(reportEntries2, placeholders, "test", doc, fileStatus2, dossier, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/seedsReport.docx")) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user