Pull request #146: RED-3748: Update justification form for Seeds and make it a multi-file-report
Merge in RED/redaction-report-service from RED-3748-rrs2 to master * commit '62c9c4d8b3d7cf4b4b79f57b88918e3cacaf85be': RED-3748: Update justification form for Seeds and make it a multi-file-report
This commit is contained in:
commit
8988d3ed49
@ -1,5 +1,5 @@
|
||||
package com.iqser.red.service.redaction.report.v1.api.model;
|
||||
|
||||
public enum ReportType {
|
||||
WORD_SINGLE_FILE, EXCEL_TEMPLATE_SINGLE_FILE, EXCEL_TEMPLATE_MULTI_FILE
|
||||
WORD_SINGLE_FILE, WORD_TEMPLATE_MULTI_FILE, EXCEL_TEMPLATE_SINGLE_FILE, EXCEL_TEMPLATE_MULTI_FILE
|
||||
}
|
||||
|
||||
@ -14,8 +14,8 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<persistence-service.version>1.98.0</persistence-service.version>
|
||||
<redaction-service.version>3.86.0</redaction-service.version>
|
||||
<persistence-service.version>1.160.0</persistence-service.version>
|
||||
<redaction-service.version>3.108.0</redaction-service.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
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;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class MultiFileDocument {
|
||||
|
||||
private XWPFDocument document;
|
||||
private String templateId;
|
||||
|
||||
}
|
||||
@ -10,6 +10,7 @@ import com.iqser.red.service.redaction.report.v1.server.client.DossierClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.FileStatusClient;
|
||||
import com.iqser.red.service.redaction.report.v1.server.client.RedactionLogClient;
|
||||
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.ReportRedactionEntry;
|
||||
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
|
||||
@ -20,6 +21,7 @@ import com.iqser.red.storage.commons.exception.StorageObjectDoesNotExist;
|
||||
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.stereotype.Service;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -51,17 +53,29 @@ public class ReportGenerationService {
|
||||
|
||||
List<ReportTemplate> singleFilesTemplates = new ArrayList<>();
|
||||
List<MultiFileWorkbook> multiFileWorkbooks = new ArrayList<>();
|
||||
List<MultiFileDocument> multiFileDocuments = new ArrayList<>();
|
||||
for (String templateId : reportMessage.getTemplateIds()) {
|
||||
try {
|
||||
ReportTemplate reportTemplate = reportTemplateClient.getReportTemplate(reportMessage.getDossierTemplateId(), templateId);
|
||||
if (reportTemplate.isMultiFileReport()) {
|
||||
byte[] excelTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(excelTemplate)) {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook(is);
|
||||
MultiFileWorkbook multiFileWorkbook = new MultiFileWorkbook(workbook, templateId);
|
||||
multiFileWorkbooks.add(multiFileWorkbook);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate multifile excel report.");
|
||||
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);
|
||||
multiFileWorkbooks.add(multiFileWorkbook);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate multifile excel report.");
|
||||
}
|
||||
} else {
|
||||
byte[] wordTemplate = reportStorageService.getReportTemplate(reportTemplate.getStorageId());
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(wordTemplate)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
MultiFileDocument multiFileDocument = new MultiFileDocument(doc, templateId);
|
||||
multiFileDocuments.add(multiFileDocument);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Could not generate multifile word report.");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
singleFilesTemplates.add(reportTemplate);
|
||||
@ -86,9 +100,12 @@ public class ReportGenerationService {
|
||||
excelTemplateReportGenerationService.generateReport(reportEntries, reportMessage.getDossierTemplateId(), multiFileWorkbook.getWorkbook(), fileStatus, project, j == reportMessage.getFileIds()
|
||||
.size() - 1);
|
||||
}
|
||||
for (MultiFileDocument multiFileDocument : multiFileDocuments) {
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_TEMPLATE_MULTI_FILE, reportEntries, reportMessage.getDossierTemplateId(), multiFileDocument.getDocument(), fileStatus, project, j == reportMessage.getFileIds()
|
||||
.size() - 1);
|
||||
}
|
||||
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);
|
||||
@ -101,10 +118,16 @@ public class ReportGenerationService {
|
||||
throw new RuntimeException("Could not generate singlefile excel report.");
|
||||
}
|
||||
} else {
|
||||
byte[] template = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, reportMessage.getDossierTemplateId(), reportTemplate, fileStatus, project);
|
||||
String storageId = reportStorageService.storeObject(reportMessage.getDownloadId(), template);
|
||||
storedFileInformation.add(new StoredFileInformation(reportMessage.getFileIds()
|
||||
.get(j), storageId, ReportType.WORD_SINGLE_FILE, reportTemplate.getTemplateId()));
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,6 +143,12 @@ public class ReportGenerationService {
|
||||
storedFileInformation.add(new StoredFileInformation(null, storageId, ReportType.EXCEL_TEMPLATE_MULTI_FILE, multiFileWorkbook.getTemplateId()));
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
|
||||
return storedFileInformation;
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,9 @@ 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.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
@ -51,6 +54,7 @@ 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;
|
||||
@ -69,6 +73,7 @@ import com.iqser.red.service.redaction.report.v1.server.model.ReportRedactionEnt
|
||||
import com.iqser.red.service.redaction.report.v1.server.storage.ReportStorageService;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ -77,15 +82,13 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class WordReportGenerationService {
|
||||
|
||||
private final FileAttributesConfigClient fileAttributesClient;
|
||||
private final ReportStorageService reportStorageService;
|
||||
private final DossierAttributesClient dossierAttributesClient;
|
||||
private final DossierAttributesConfigClient dossierAttributesConfigClient;
|
||||
private final IuclidFunctionService iuclidFunctionService;
|
||||
|
||||
|
||||
public byte[] generateReport(ReportType reportType, List<ReportRedactionEntry> reportEntries,
|
||||
String dossierTemplateId, ReportTemplate reportTemplate, FileModel fileStatus,
|
||||
Dossier dossier) {
|
||||
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<>();
|
||||
@ -105,8 +108,7 @@ public class WordReportGenerationService {
|
||||
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())));
|
||||
imagePlaceholders.add(new ImagePlaceholder(attributeConfig.getPlaceholder(), Base64.getDecoder().decode(dossierAttribute.getValue())));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -127,25 +129,25 @@ public class WordReportGenerationService {
|
||||
placeholders.addAll(fileAttributePlaceholders.keySet());
|
||||
placeholders.addAll(dossierAttributesPlaceholder.keySet());
|
||||
|
||||
byte[] template;
|
||||
String storageId = reportTemplate.getStorageId();
|
||||
template = reportStorageService.getReportTemplate(storageId);
|
||||
|
||||
try (ByteArrayInputStream is = new ByteArrayInputStream(template)) {
|
||||
XWPFDocument doc = new XWPFDocument(is);
|
||||
try {
|
||||
|
||||
for (ImagePlaceholder imagePlaceholder : imagePlaceholders) {
|
||||
replaceImagePlaceholders(doc, imagePlaceholder);
|
||||
}
|
||||
addTableRows(doc, reportEntries, fileStatus.getFilename(), fileStatus, fileAttributePlaceholders);
|
||||
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);
|
||||
if (placeholderValue != null) {
|
||||
replaceTextPlaceholders(doc, placeholder, placeholderValue);
|
||||
}
|
||||
}
|
||||
return toByteArray(doc);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
if(!isLastFile) {
|
||||
readdPlaceholders(table, placeholderCellPos);
|
||||
}
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage() + " in file: " + fileStatus.getFilename());
|
||||
throw new RuntimeException(e);
|
||||
@ -186,10 +188,8 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private String getPlaceholderValue(String placeholder, Dossier project, FileModel fileStatus,
|
||||
Map<String, String> fileAttributePlaceholders,
|
||||
Map<String, String> dossierAttributesPlaceholders,
|
||||
List<ReportRedactionEntry> reportRedactionEntries) {
|
||||
private String getPlaceholderValue(String placeholder, Dossier project, FileModel fileStatus, Map<String, String> fileAttributePlaceholders,
|
||||
Map<String, String> dossierAttributesPlaceholders, List<ReportRedactionEntry> reportRedactionEntries) {
|
||||
|
||||
if (placeholder.equals(FORMAT_DATE_ISO_PLACEHOLDER)) {
|
||||
return OffsetDateTime.now().format(FORMAT_DATE_ISO);
|
||||
@ -228,8 +228,7 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private void replaceParagraphForImagePlaceholder(List<XWPFParagraph> paragraphs,
|
||||
ImagePlaceholder imagePlaceholder) {
|
||||
private void replaceParagraphForImagePlaceholder(List<XWPFParagraph> paragraphs, ImagePlaceholder imagePlaceholder) {
|
||||
|
||||
for (XWPFParagraph p : paragraphs) {
|
||||
String paragraphText = p.getText();
|
||||
@ -324,30 +323,33 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private void addTableRows(XWPFDocument doc, List<ReportRedactionEntry> reportEntries, String filename,
|
||||
FileModel fileStatus, Map<String, String> fileAttributePlaceholders) {
|
||||
private Map<Integer, String> computePlaceholderPos(XWPFTable table) {
|
||||
Map<Integer, String> placeholderCellPos = new HashMap<>();
|
||||
|
||||
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++) {
|
||||
XWPFTableCell cell = table.getRows().get(j).getTableCells().get(i);
|
||||
if (containsRedactionPlaceholder(cell.getText())) {
|
||||
placeholderCellPos.put(i, cell.getText());
|
||||
placeholderRow = j;
|
||||
} else if (cell.getText().isEmpty()) {
|
||||
placeholderCellPos.put(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
table.removeRow(placeholderRow);
|
||||
}
|
||||
return placeholderCellPos;
|
||||
}
|
||||
|
||||
private void addTableRows(XWPFTable table, List<ReportRedactionEntry> reportEntries, String filename, FileModel fileStatus, Map<String, String> fileAttributePlaceholders, Map<Integer, String> placeholderCellPos) {
|
||||
|
||||
XWPFTable table = getRedactionTable(doc);
|
||||
if (table == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, String> placeholderCellPos = new HashMap<>();
|
||||
|
||||
int placeholderRow = -1;
|
||||
for (int j = 0; j < table.getRows().size(); j++) {
|
||||
for (int i = 0; i < table.getRows().get(j).getTableCells().size(); i++) {
|
||||
XWPFTableCell cell = table.getRows().get(j).getTableCells().get(i);
|
||||
if (containsRedactionPlaceholder(cell.getText())) {
|
||||
placeholderCellPos.put(i, cell.getText());
|
||||
placeholderRow = j;
|
||||
} else if (cell.getText().isEmpty()) {
|
||||
placeholderCellPos.put(i, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
table.removeRow(placeholderRow);
|
||||
|
||||
if (placeholderCellPos.containsValue(SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER)) {
|
||||
var redactionsPerJustification = getRedactionsPerJustification(reportEntries);
|
||||
for (Map.Entry<String, List<ReportRedactionEntry>> entry : redactionsPerJustification.entrySet()) {
|
||||
@ -374,6 +376,14 @@ 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++) {
|
||||
String placeholder = placeholderCellPos.get(i);
|
||||
setText(newRow.getCell(i), placeholder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String replaceTextPlaceholderWithEntries(ReportRedactionEntry entry, String filename, String placeholder) {
|
||||
|
||||
@ -411,17 +421,13 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private String replaceSeedsPlaceholder(Map.Entry<String, List<ReportRedactionEntry>> entry, String filename,
|
||||
String placeholder, FileModel fileStatus,
|
||||
private String replaceSeedsPlaceholder(Map.Entry<String, List<ReportRedactionEntry>> entry, String filename, String placeholder, FileModel fileStatus,
|
||||
Map<String, String> fileAttributePlaceholders) {
|
||||
|
||||
if (placeholder.equals(SEEDS_FUNCTION_REDACTION_GROUPED_BY_JUSTIFICATION_PAGES_PLACEHOLDER)) {
|
||||
return entry.getValue()
|
||||
.stream()
|
||||
.map(ReportRedactionEntry::getPage)
|
||||
.distinct()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.joining(", "));
|
||||
var pages = entry.getValue().stream().map(ReportRedactionEntry::getPage).collect(Collectors.toSet());
|
||||
return computePageRanges(pages);
|
||||
|
||||
}
|
||||
if (placeholder.equals(SEEDS_FUNCTION_JUSTIFICATION_PLACEHOLDER)) {
|
||||
return entry.getKey();
|
||||
@ -442,6 +448,49 @@ public class WordReportGenerationService {
|
||||
}
|
||||
|
||||
|
||||
private String computePageRanges(Set<Integer> pages) {
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
SortedSet<Integer> numbers = new TreeSet<Integer>(pages);
|
||||
|
||||
Integer start = null;
|
||||
Integer end = null;
|
||||
|
||||
for (Integer num : numbers) {
|
||||
//initialize
|
||||
if (start == null || end == null) {
|
||||
start = num;
|
||||
end = num;
|
||||
}
|
||||
//next number in range
|
||||
else if (end.equals(num - 1)) {
|
||||
end = num;
|
||||
}
|
||||
//there's a gap
|
||||
else {
|
||||
//range length 1
|
||||
if (start.equals(end)) {
|
||||
result.append(start).append(",");
|
||||
}
|
||||
//range lenth 2 and more
|
||||
else {
|
||||
result.append(start).append("-").append(end).append(",");
|
||||
}
|
||||
|
||||
start = num;
|
||||
end = num;
|
||||
}
|
||||
}
|
||||
if (start.equals(end)) {
|
||||
result.append(start);
|
||||
} else {
|
||||
result.append(start).append("-").append(end);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
private Dimension2DDouble getImageDimension(ByteArrayInputStream bais) throws IOException {
|
||||
|
||||
BufferedImage bufImg = ImageIO.read(bais);
|
||||
@ -474,12 +523,15 @@ public class WordReportGenerationService {
|
||||
return new ColoredText(textForLine, null);
|
||||
}
|
||||
|
||||
|
||||
private Map<String, List<ReportRedactionEntry>> getRedactionsPerJustification(List<ReportRedactionEntry> reportRedactionEntryList) {
|
||||
|
||||
return reportRedactionEntryList.stream().sorted(Comparator.comparing(ReportRedactionEntry::getPage)).collect(Collectors.groupingBy(ReportRedactionEntry::getJustification));
|
||||
}
|
||||
|
||||
|
||||
private byte[] toByteArray(XWPFDocument doc) throws IOException {
|
||||
@SneakyThrows
|
||||
public byte[] toByteArray(XWPFDocument doc) {
|
||||
|
||||
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
|
||||
doc.write(byteArrayOutputStream);
|
||||
|
||||
@ -28,6 +28,7 @@ import com.iqser.red.storage.commons.service.StorageService;
|
||||
import lombok.SneakyThrows;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -168,15 +169,10 @@ public class RedactionReportIntegrationTest {
|
||||
.build());
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds - New Justification Form.docx");
|
||||
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
|
||||
ReportTemplate reportTemplate = ReportTemplate.builder()
|
||||
.dossierTemplateId("dossierTemplateId")
|
||||
.templateId("templateId")
|
||||
.fileName("fileName")
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileStatus, project);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileStatus, project, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template_wrg.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
@ -207,7 +203,7 @@ public class RedactionReportIntegrationTest {
|
||||
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
|
||||
List<ReportRedactionEntry> reportEntries2 = redactionLogConverterService.convertAndSort(redactionLog2, legalBasisMapping);
|
||||
|
||||
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "label", true, "{{dossier.attribute.name}}", DossierAttributeType.TEXT, dossierTemplateId);//
|
||||
DossierAttributeConfig dossierAttributeConfig = new DossierAttributeConfig("id", "label", true, "{{dossier.attribute.name}}", DossierAttributeType.TEXT, dossierTemplateId);
|
||||
DossierAttributeConfig dossierAttributeConfig2 = new DossierAttributeConfig("id2", "label2", false, "{{dossier.attribute.Signature}}", DossierAttributeType.IMAGE, dossierTemplateId);
|
||||
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(List.of(dossierAttributeConfig, dossierAttributeConfig2));
|
||||
|
||||
@ -293,27 +289,17 @@ public class RedactionReportIntegrationTest {
|
||||
.build());
|
||||
|
||||
ClassPathResource wordTemplateResource = new ClassPathResource("templates/Justification Appendix A1.docx");
|
||||
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(wordTemplateResource.getInputStream()));
|
||||
ReportTemplate reportTemplate = ReportTemplate.builder()
|
||||
.dossierTemplateId("dossierTemplateId")
|
||||
.templateId("templateId")
|
||||
.fileName("fileName")
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] wordReport = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileModel, dossier);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(wordTemplateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileModel, dossier, true);
|
||||
byte[] wordReport = wordReportGenerationService.toByteArray(doc);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template1.docx")) {
|
||||
fileOutputStream.write(wordReport);
|
||||
}
|
||||
|
||||
ReportTemplate reportTemplate2 = ReportTemplate.builder()
|
||||
.dossierTemplateId("dossierTemplateId")
|
||||
.templateId("templateId")
|
||||
.fileName("fileNameReportTemplate2")
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] wordReport2 = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries2, dossierTemplateId, reportTemplate2, fileModel2, dossier);
|
||||
doc = new XWPFDocument(wordTemplateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries2, dossierTemplateId, doc, fileModel2, dossier, true);
|
||||
byte[] wordReport2 = wordReportGenerationService.toByteArray(doc);
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template2.docx")) {
|
||||
fileOutputStream.write(wordReport2);
|
||||
}
|
||||
@ -392,15 +378,10 @@ public class RedactionReportIntegrationTest {
|
||||
.build());
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/6464 appendix_b EFSA dRAR justification.docx");
|
||||
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
|
||||
ReportTemplate reportTemplate = ReportTemplate.builder()
|
||||
.dossierTemplateId("dossierTemplateId")
|
||||
.templateId("templateId")
|
||||
.fileName("filename")
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileModel, project);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileModel, project, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/efsa_template13.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
@ -453,7 +434,10 @@ public class RedactionReportIntegrationTest {
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileStatus, project);
|
||||
|
||||
XWPFDocument doc = new XWPFDocument(templateResource.getInputStream());
|
||||
wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, doc, fileStatus, project, true);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/iuclid_report_2.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
@ -530,13 +514,16 @@ public class RedactionReportIntegrationTest {
|
||||
String dossierTemplateId = "dossierTemplateId";
|
||||
|
||||
ClassPathResource redactionLogResource = new ClassPathResource("files/redactionLog2817.json");
|
||||
ClassPathResource redactionLogResource2 = new ClassPathResource("files/redactionLog.json");
|
||||
RedactionLog redactionLog = objectMapper.readValue(redactionLogResource.getInputStream(), RedactionLog.class);
|
||||
RedactionLog redactionLog2 = objectMapper.readValue(redactionLogResource2.getInputStream(), RedactionLog.class);
|
||||
|
||||
ClassPathResource legalBasisMappingResource = new ClassPathResource("files/legalBasisMappingNew.json");
|
||||
List<LegalBasis> legalBasisMapping = objectMapper.readValue(legalBasisMappingResource.getInputStream(), new TypeReference<>() {
|
||||
});
|
||||
|
||||
List<ReportRedactionEntry> reportEntries = redactionLogConverterService.convertAndSort(redactionLog, legalBasisMapping);
|
||||
List<ReportRedactionEntry> reportEntries2 = redactionLogConverterService.convertAndSort(redactionLog2, legalBasisMapping);
|
||||
|
||||
when(dossierAttributesConfigClient.getDossierAttributes(dossierTemplateId)).thenReturn(new ArrayList<>());
|
||||
when(dossierAttributesClient.getDossierAttributes("dossierId")).thenReturn(new ArrayList<>());
|
||||
@ -544,6 +531,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();
|
||||
|
||||
@ -554,16 +542,12 @@ public class RedactionReportIntegrationTest {
|
||||
.storageId(storageId)
|
||||
.build());
|
||||
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds - New Justification Form.docx");
|
||||
ClassPathResource templateResource = new ClassPathResource("templates/Seeds-NewJustificationForm.docx");
|
||||
when(reportStorageService.getReportTemplate(storageId)).thenReturn(IOUtils.toByteArray(templateResource.getInputStream()));
|
||||
ReportTemplate reportTemplate = ReportTemplate.builder()
|
||||
.dossierTemplateId("dossierTemplateId")
|
||||
.templateId("templateId")
|
||||
.fileName("fileName")
|
||||
.storageId("storageId")
|
||||
.uploadDate(OffsetDateTime.now())
|
||||
.build();
|
||||
byte[] report = wordReportGenerationService.generateReport(ReportType.WORD_SINGLE_FILE, reportEntries, dossierTemplateId, reportTemplate, fileStatus, project);
|
||||
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);
|
||||
byte[] report = wordReportGenerationService.toByteArray(doc);
|
||||
|
||||
try (FileOutputStream fileOutputStream = new FileOutputStream(getTemporaryDirectory() + "/seedsReport.docx")) {
|
||||
fileOutputStream.write(report);
|
||||
|
||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user