From 338b06079b1d6ae928466293d0ac00632c16f3c1 Mon Sep 17 00:00:00 2001 From: Viktor Seifert Date: Thu, 30 Mar 2023 17:30:16 +0200 Subject: [PATCH] RED-6497: Fixed issue where the file-size of download was saved incorrectly. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Changed the update to the DownloadStatusEntity to use the entity object instead of using a query on JPA-repo.  This prevents values from the object being incorrectly inserted otherwise. * Extended the DownloadPreparationTest to check the resulting download state and file size. --- .../download/DownloadPreparationService.java | 5 +---- .../export/DossierTemplateExportService.java | 2 +- .../DownloadStatusPersistenceService.java | 6 ++++-- .../repository/DownloadStatusRepository.java | 7 +------ .../integration/tests/DownloadPreparationTest.java | 13 ++++++++++--- 5 files changed, 17 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 d5b62aa22..aa9444050 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 @@ -166,10 +166,7 @@ public class DownloadPreparationService { private void updateStatusToReady(DownloadStatusEntity downloadStatus, FileSystemBackedArchiver fileSystemBackedArchiver) { - downloadStatusPersistenceService.updateStatus(downloadStatus.getStorageId(), DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength()); - if (!Objects.equals(downloadStatus.getStatus(), DownloadStatusValue.READY)) { - downloadStatus.setStatus(DownloadStatusValue.READY); - } + downloadStatusPersistenceService.updateStatus(downloadStatus, DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength()); } diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/export/DossierTemplateExportService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/export/DossierTemplateExportService.java index ab897652c..c5f57e614 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/export/DossierTemplateExportService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/export/DossierTemplateExportService.java @@ -221,7 +221,7 @@ public class DossierTemplateExportService { } storeZipFile(downloadStatus.getStorageId(), fileSystemBackedArchiver); - downloadStatusPersistenceService.updateStatus(downloadStatus.getStorageId(), DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength()); + downloadStatusPersistenceService.updateStatus(downloadStatus, DownloadStatusValue.READY, fileSystemBackedArchiver.getContentLength()); } catch (JsonProcessingException e) { log.debug("fail ", e); diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/DownloadStatusPersistenceService.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/DownloadStatusPersistenceService.java index 6b461488b..538960fa3 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/DownloadStatusPersistenceService.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/DownloadStatusPersistenceService.java @@ -73,9 +73,11 @@ public class DownloadStatusPersistenceService { @Transactional - public void updateStatus(String storageId, DownloadStatusValue status, long fileSize) { + public void updateStatus(DownloadStatusEntity entity, DownloadStatusValue statusValue, long fileSize) { - downloadStatusRepository.updateStatus(storageId, status, fileSize); + entity.setStatus(statusValue); + entity.setFileSize(fileSize); + downloadStatusRepository.save(entity); } diff --git a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/DownloadStatusRepository.java b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/DownloadStatusRepository.java index 385575f15..30a9352f1 100644 --- a/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/DownloadStatusRepository.java +++ b/persistence-service-v1/persistence-service-processor-v1/src/main/java/com/iqser/red/service/persistence/management/v1/processor/service/persistence/repository/DownloadStatusRepository.java @@ -18,12 +18,7 @@ public interface DownloadStatusRepository extends JpaRepository downloadStatuses = downloadClient.getDownloadStatus().getDownloadStatus(); + assertThat(downloadStatuses).hasSize(1); - DownloadStatus firstDownloadStatus = statuses.getDownloadStatus().iterator().next(); + DownloadStatus firstDownloadStatus = downloadStatuses.get(0); assertThat(firstDownloadStatus.getLastDownload()).isNull(); String downloadId = firstDownloadStatus.getStorageId(); @@ -134,6 +135,12 @@ public class DownloadPreparationTest extends AbstractPersistenceServerServiceTes .redactionResultDetails(Collections.emptyList()) .build()); + List finalDownloadStatuses = downloadClient.getDownloadStatus().getDownloadStatus(); + assertThat(finalDownloadStatuses).hasSize(1); + DownloadStatus finalDownloadStatus = finalDownloadStatuses.get(0); + assertThat(finalDownloadStatus.getStatus()).isEqualTo(DownloadStatusValue.READY); + assertThat(finalDownloadStatus.getFileSize()).isGreaterThan(0); + clearTenantContext(); }