RED-1098: Moved cleanup behavior to the correct location (after receiving the pdftron-results)
This commit is contained in:
parent
30561e5601
commit
80621cfab2
@ -2,6 +2,7 @@ package com.iqser.red.service.peristence.v1.server.service.download;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -58,12 +59,14 @@ public class DownloadPreparationService {
|
||||
ObjectMapper objectMapper;
|
||||
StorageService storageService;
|
||||
|
||||
DownloadReportCleanupService downloadReportCleanupService;
|
||||
|
||||
|
||||
@Transactional
|
||||
public void createDownload(ReportResultMessage reportResultMessage) throws JsonProcessingException {
|
||||
|
||||
DownloadStatusEntity downloadStatus = downloadStatusPersistenceService.getStatus(reportResultMessage.getDownloadId());
|
||||
downloadStatus.setGeneratedReportsInformation(downloadStatus.getGeneratedReportsInformation());
|
||||
downloadStatus.setGeneratedReportsInformation(new HashSet<>(reportResultMessage.getStoredFileInformation()));
|
||||
downloadStatusPersistenceService.updateStatusEntity(downloadStatus);
|
||||
|
||||
DossierEntity dossier = downloadStatus.getDossier();
|
||||
@ -75,6 +78,7 @@ public class DownloadPreparationService {
|
||||
.fileIds(downloadStatus.getFiles().stream().map(FileEntity::getId).collect(Collectors.toList()))
|
||||
.build();
|
||||
|
||||
log.info("Sending redaction request for downloadId:{} to pdfton-redaction-queue", message.getDownloadId());
|
||||
rabbitTemplate.convertAndSend(MessagingConfiguration.PDFTRON_QUEUE, objectMapper.writeValueAsString(message));
|
||||
}
|
||||
|
||||
@ -125,6 +129,8 @@ public class DownloadPreparationService {
|
||||
"downloadId", downloadStatus.getStatus()))
|
||||
.build());
|
||||
}
|
||||
|
||||
downloadReportCleanupService.deleteTmpReportFiles(downloadStatus.getGeneratedReportsInformation());
|
||||
}
|
||||
|
||||
|
||||
@ -172,9 +178,7 @@ public class DownloadPreparationService {
|
||||
|
||||
private byte[] getStoredFileBytes(String fileId, List<RedactionResultDetail> redactionResultDetails, RedactionType redactionType) {
|
||||
|
||||
var redactionResultDetail = redactionResultDetails.stream()
|
||||
.filter(rrd -> Objects.equals(fileId, rrd.getFileId()) && rrd.getRedactionType() == redactionType)
|
||||
.findFirst();
|
||||
var redactionResultDetail = redactionResultDetails.stream().filter(rrd -> Objects.equals(fileId, rrd.getFileId()) && rrd.getRedactionType() == redactionType).findFirst();
|
||||
if (redactionResultDetail.isPresent()) {
|
||||
try (var inputStream = storageService.getObject(redactionResultDetail.get().getStorageId()).getInputStream()) {
|
||||
return inputStream.readAllBytes();
|
||||
|
||||
@ -1,13 +1,16 @@
|
||||
package com.iqser.red.service.peristence.v1.server.service.download;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportResultMessage;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.iqser.red.service.peristence.v1.server.service.FileManagementStorageService;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.StoredFileInformation;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@ -16,9 +19,9 @@ public class DownloadReportCleanupService {
|
||||
private final FileManagementStorageService fileManagementStorageService;
|
||||
|
||||
@Async
|
||||
public void deleteTmpReportFiles(ReportResultMessage reportResultMessage) {
|
||||
public void deleteTmpReportFiles(Collection<StoredFileInformation> fileInformationList) {
|
||||
|
||||
for (StoredFileInformation storedFileInformation : reportResultMessage.getStoredFileInformation()) {
|
||||
for (StoredFileInformation storedFileInformation : fileInformationList) {
|
||||
fileManagementStorageService.deleteObject(storedFileInformation.getStorageId());
|
||||
log.info("Deleted tmp report file {}", storedFileInformation.getStorageId());
|
||||
}
|
||||
|
||||
@ -1,33 +1,38 @@
|
||||
package com.iqser.red.service.peristence.v1.server.service.download;
|
||||
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfiguration;
|
||||
import com.iqser.red.service.redaction.report.v1.api.model.ReportResultMessage;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
|
||||
import org.springframework.amqp.rabbit.annotation.RabbitListener;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
@RabbitListener(queues = MessagingConfiguration.REPORT_RESULT_QUEUE)
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
|
||||
public class DownloadReportMessageReceiver {
|
||||
|
||||
private final ObjectMapper objectMapper;
|
||||
private final DownloadPreparationService downloadPreparationService;
|
||||
private final DownloadReportCleanupService downloadReportCleanupService;
|
||||
ObjectMapper objectMapper;
|
||||
DownloadPreparationService downloadPreparationService;
|
||||
|
||||
|
||||
@RabbitHandler
|
||||
public void receive(String in) throws JsonProcessingException {
|
||||
|
||||
ReportResultMessage reportResultMessage = objectMapper.readValue(in, ReportResultMessage.class);
|
||||
|
||||
log.info("Received request for userId:{} downloadId:{}", reportResultMessage.getUserId(), reportResultMessage.getDownloadId());
|
||||
|
||||
downloadPreparationService.createDownload(reportResultMessage);
|
||||
downloadReportCleanupService.deleteTmpReportFiles(reportResultMessage);
|
||||
log.info("Successfully prepared download {}", reportResultMessage.getDownloadId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -20,14 +20,19 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true)
|
||||
@RabbitListener(queues = MessagingConfiguration.REPORT_RESULT_QUEUE)
|
||||
public class RedactionResultMessageReceiver {
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
ObjectMapper objectMapper;
|
||||
DownloadPreparationService downloadPreparationService;
|
||||
|
||||
|
||||
@RabbitHandler
|
||||
public void receive(String in) throws JsonProcessingException {
|
||||
|
||||
RedactionResultMessage redactionResultMessage = objectMapper.readValue(in, RedactionResultMessage.class);
|
||||
|
||||
log.info("Received redaction results for downloadId:{}", redactionResultMessage.getDownloadId());
|
||||
|
||||
downloadPreparationService.createDownload(redactionResultMessage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user