From 3b9eff798a08ad42af2730a73f95e4816730a868 Mon Sep 17 00:00:00 2001 From: Andrei Isvoran Date: Fri, 24 May 2024 14:13:21 +0200 Subject: [PATCH] RED-9205 - Fix download job failing --- .../download/DownloadPreparationService.java | 48 ++++++++++++++----- .../service/job/DownloadReadyJob.java | 2 +- .../RemoveRedactionRepository.java | 5 +- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/download/DownloadPreparationService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/download/DownloadPreparationService.java index cc08cba8c..daed2b61b 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/download/DownloadPreparationService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/download/DownloadPreparationService.java @@ -37,6 +37,7 @@ import lombok.SneakyThrows; import lombok.experimental.FieldDefaults; import lombok.extern.slf4j.Slf4j; import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.io.IOException; @@ -46,21 +47,24 @@ import java.util.stream.Collectors; @Slf4j @Service @RequiredArgsConstructor -@FieldDefaults(level = AccessLevel.PRIVATE, makeFinal = true) public class DownloadPreparationService { - DownloadStatusPersistenceService downloadStatusPersistenceService; - FileManagementStorageService fileManagementStorageService; - ReportTemplatePersistenceService reportTemplatePersistenceService; - NotificationPersistenceService notificationPersistenceService; - RabbitTemplate rabbitTemplate; - ObjectMapper objectMapper; - DownloadReportCleanupService downloadReportCleanupService; - ColorsService colorsService; - FileManagementServiceSettings settings; - DossierTemplatePersistenceService dossierTemplatePersistenceService; - DownloadRedactionFileStatusRepository downloadRedactionFileStatusRepository; + private final DownloadStatusPersistenceService downloadStatusPersistenceService; + private final FileManagementStorageService fileManagementStorageService; + private final ReportTemplatePersistenceService reportTemplatePersistenceService; + private final NotificationPersistenceService notificationPersistenceService; + private final RabbitTemplate rabbitTemplate; + private final ObjectMapper objectMapper; + private final DownloadReportCleanupService downloadReportCleanupService; + private final ColorsService colorsService; + private final FileManagementServiceSettings settings; + private final DossierTemplatePersistenceService dossierTemplatePersistenceService; + private final DownloadRedactionFileStatusRepository downloadRedactionFileStatusRepository; + @Value("${storage.backend}") + private String storageBackend; + + private static final String REPORT_INFO = "/REPORT_INFO.json"; @Transactional public void createDownload(ReportResultMessage reportResultMessage) { @@ -321,13 +325,31 @@ public class DownloadPreparationService { @SneakyThrows private List getStoredFileInformation(String downloadId) { - var storageId = downloadId.substring(0, downloadId.length() - 3) + "/REPORT_INFO.json"; + String storageId; + if (storageBackend.equals("s3")) { + storageId = generateReportJsonStorageIdForS3(downloadId); + } else { + storageId = generateReportJsonStorageIdForAzure(downloadId); + } return objectMapper.readValue(fileManagementStorageService.getStoredObjectBytes(storageId), new TypeReference<>() { }); } + + private String generateReportJsonStorageIdForS3(String storageId) { + + return storageId.substring(0, storageId.length() - 3) + REPORT_INFO; + } + + + private String generateReportJsonStorageIdForAzure(String storageId) { + + return storageId.substring(0, storageId.length() - 4) + REPORT_INFO; + } + + private String createFileName(FileEntity fileStatus, ReportTemplateEntity reportTemplate) { if (fileStatus != null) { diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/job/DownloadReadyJob.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/job/DownloadReadyJob.java index 71927f25a..2c4f3fcf1 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/job/DownloadReadyJob.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/job/DownloadReadyJob.java @@ -41,7 +41,7 @@ public class DownloadReadyJob implements Job { int numberOfFiles = download.getFiles().size(); var downloadRedactionFileStatus = downloadRedactionFileStatusRepository.findAllByDownloadStorageId(download.getStorageId()); - if (downloadRedactionFileStatus.size() == numberOfFiles) { + if (downloadRedactionFileStatus.size() >= numberOfFiles) { downloadPreparationService.createDownload(downloadRedactionFileStatus, download.getStorageId()); downloadPreparationService.clearRedactionStatusEntries(download.getStorageId()); } diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/annotationentity/RemoveRedactionRepository.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/annotationentity/RemoveRedactionRepository.java index 6c315db31..80592cb24 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/annotationentity/RemoveRedactionRepository.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/annotationentity/RemoveRedactionRepository.java @@ -10,7 +10,6 @@ import org.springframework.data.jpa.repository.Query; import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId; import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.IdRemovalEntity; -import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRedactionEntryEntity; import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AnnotationStatus; public interface RemoveRedactionRepository extends JpaRepository, AnnotationEntityRepository { @@ -24,13 +23,15 @@ public interface RemoveRedactionRepository extends JpaRepository findByIdAndNotSoftDeleted(AnnotationEntityId annotationEntityId); - @Query("select idr from IdRemovalEntity idr where idr.id.fileId = :fileId and (:includeDeletions = true or idr.softDeletedTime is null)") + @Query("select idr from IdRemovalEntity idr left join fetch idr.typeIdsOfModifiedDictionaries where idr.id.fileId = :fileId and (:includeDeletions = true or idr.softDeletedTime is null)") List findByFileIdIncludeDeletions(String fileId, boolean includeDeletions); + @Query("select idr from IdRemovalEntity idr where idr.id.fileId = :fileId and idr.processedDate is null") List findByFileIdAndUnprocessed(String fileId);