Pull request #153: RED-4527: Store information of generated reports in storage

Merge in RED/redaction-report-service from RED-4527 to master

* commit '9bbd3d11c9ff0a6d16d0d65e47f5f0b5417545b5':
  RED-4527: Store information of generated reports in storage
This commit is contained in:
Dominique Eiflaender 2022-07-07 09:57:33 +02:00
commit 69eebd2947
4 changed files with 25 additions and 7 deletions

View File

@ -16,6 +16,6 @@ public class ReportResultMessage {
private String userId;
private String downloadId;
private List<StoredFileInformation> storedFileInformation = new ArrayList<>();
private String reportFileInformationStorageId;
}

View File

@ -59,7 +59,7 @@ public class ReportGenerationService {
@SneakyThrows
@Timed("redactmanager_generateReports")
public List<StoredFileInformation> generateReports(ReportRequestMessage reportMessage) {
public String generateReports(ReportRequestMessage reportMessage) {
List<StoredFileInformation> storedFileInformation = Collections.synchronizedList(new ArrayList<>());
@ -153,7 +153,9 @@ public class ReportGenerationService {
storedFileInformation.add(new StoredFileInformation(null, storageId, ReportType.WORD_TEMPLATE_MULTI_FILE, multiFileDocument.getTemplateId()));
}
return storedFileInformation;
String reportFileInformationStorageId = reportStorageService.storeReportInformation(reportMessage.getDownloadId(), storedFileInformation);
return reportFileInformationStorageId;
}

View File

@ -36,8 +36,8 @@ public class ReportMessageReceiver {
long start = System.currentTimeMillis();
log.info("Start generating reports for downloadId {}", reportMessage.getDownloadId());
List<StoredFileInformation> storedFileInformation = reportGenerationService.generateReports(reportMessage);
addToReportResultQueue(reportMessage.getUserId(), reportMessage.getDownloadId(), storedFileInformation, 1);
var reportFileInformationStorageId = reportGenerationService.generateReports(reportMessage);
addToReportResultQueue(reportMessage.getUserId(), reportMessage.getDownloadId(), reportFileInformationStorageId, 1);
long end = System.currentTimeMillis();
log.info("Successfully generated reports for downloadId {}, took {}", reportMessage.getDownloadId(), end - start);
@ -45,10 +45,10 @@ public class ReportMessageReceiver {
private void addToReportResultQueue(String userId, String downloadId,
List<StoredFileInformation> storedFileInformation, int priority) {
String reportFileInformationStorageId, int priority) {
try {
rabbitTemplate.convertAndSend(REPORT_RESULT_QUEUE, objectMapper.writeValueAsString(new ReportResultMessage(userId, downloadId, storedFileInformation)), message -> {
rabbitTemplate.convertAndSend(REPORT_RESULT_QUEUE, objectMapper.writeValueAsString(new ReportResultMessage(userId, downloadId, reportFileInformationStorageId)), message -> {
message.getMessageProperties().setPriority(priority);
return message;
});

View File

@ -1,11 +1,16 @@
package com.iqser.red.service.redaction.report.v1.server.storage;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
import com.iqser.red.storage.commons.service.StorageService;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import org.apache.commons.io.IOUtils;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
@Service
@ -13,6 +18,7 @@ import java.util.UUID;
public class ReportStorageService {
private final StorageService storageService;
private final ObjectMapper objectMapper;
public String storeObject(String downloadId, byte[] data) {
@ -21,6 +27,16 @@ public class ReportStorageService {
return storageId;
}
@SneakyThrows
public String storeReportInformation(String downloadId, List<StoredFileInformation> storedFileInformations) {
String storageId = StorageIdUtils.getStorageId(downloadId, "REPORT_INFO.json");
storageService.storeObject(storageId, objectMapper.writeValueAsBytes(storedFileInformations));
return storageId;
}
public byte[] getReportTemplate(String storageId) {
try {
return IOUtils.toByteArray(storageService.getObject(storageId).getInputStream());