RED-3628 Bugfix for downloading archived dossiers

This commit is contained in:
Philipp Schramm 2022-03-21 09:21:08 +01:00
parent 9345f88bee
commit 274f7da04a
3 changed files with 56 additions and 35 deletions

View File

@ -1,13 +1,18 @@
package com.iqser.red.service.persistence.service.v1.api.resources;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimitive;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadRequest;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatus;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ResponseStatus(value = HttpStatus.OK)
public interface DownloadResource {
@ -19,7 +24,6 @@ public interface DownloadResource {
@PostMapping(value = REST_PATH + "/prepare", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
JSONPrimitive<String> prepareDownload(@RequestBody DownloadRequest request);
@GetMapping(value = REST_PATH + "/status/{" + USER_ID + "}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
List<DownloadStatus> getDownloadStatus(@PathVariable(USER_ID) String userId);

View File

@ -1,5 +1,20 @@
package com.iqser.red.service.persistence.management.v1.processor.service.persistence;
import static com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException.DOSSIER_NOT_FOUND_MESSAGE;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import javax.transaction.Transactional;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
import com.iqser.red.service.persistence.management.v1.processor.exception.BadRequestException;
import com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException;
@ -10,21 +25,11 @@ import com.iqser.red.service.persistence.management.v1.processor.service.persist
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.CreateOrUpdateDossierRequest;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierChange;
import com.iqser.red.service.persistence.service.v1.api.model.dossiertemplate.dossier.DossierStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import javax.transaction.Transactional;
import java.time.OffsetDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
import static com.iqser.red.service.persistence.management.v1.processor.exception.DossierNotFoundException.DOSSIER_NOT_FOUND_MESSAGE;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@RequiredArgsConstructor
public class DossierPersistenceService {
@ -92,6 +97,18 @@ public class DossierPersistenceService {
}
public DossierEntity getActiveOrArchivedDossier(String dossierId) {
var dossier = findByDossierId(dossierId);
if (dossier == null || dossier.getHardDeletedTime() != null || dossier.getSoftDeletedTime() != null) {
throw new DossierNotFoundException(String.format(DOSSIER_NOT_FOUND_MESSAGE, dossierId));
}
return dossier;
}
public DossierEntity getAndValidateDossier(String dossierId) {
// check whether the dossierId exists and is not deleted
var dossier = findByDossierId(dossierId);

View File

@ -1,5 +1,16 @@
package com.iqser.red.service.peristence.v1.server.controller;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfiguration;
@ -14,18 +25,11 @@ import com.iqser.red.service.persistence.service.v1.api.model.common.JSONPrimiti
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadRequest;
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatus;
import com.iqser.red.service.persistence.service.v1.api.resources.DownloadResource;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import static com.iqser.red.service.persistence.management.v1.processor.utils.MagicConverter.convert;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@RestController
@RequiredArgsConstructor
public class DownloadController implements DownloadResource {
@ -42,15 +46,11 @@ public class DownloadController implements DownloadResource {
var mimeType = "application/zip";
var existingFileStatuses = fileStatusPersistenceService.getStatusesForDossier(request.getDossierId());
String downloadFilename = buildName(request.getDossierId(), request.getFileIds(), request.getUserId(), mimeType, existingFileStatuses);
String storageId = StorageIdUtils.getStorageId(request.getUserId(), request.getDossierId(), downloadFilename);
var dossier = dossierPersistenceService.getAndValidateDossier(request.getDossierId());
var dossier = dossierPersistenceService.getActiveOrArchivedDossier(request.getDossierId());
downloadStatusPersistenceService.createStatus(request.getUserId(), storageId, dossier, downloadFilename, mimeType, request.getFileIds(), dossier.getDownloadFileTypes());
addToDownloadQueue(DownloadJob.builder().storageId(storageId).userId(request.getUserId()).build(), 1);
return new JSONPrimitive<>(storageId);
@ -92,7 +92,7 @@ public class DownloadController implements DownloadResource {
private String buildName(String dossierId, List<String> fileIds, String userId, String mimeType,
List<FileEntity> existingFileStatuses) {
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
var dossier = dossierPersistenceService.getActiveOrArchivedDossier(dossierId);
Set<String> existingFilenames = downloadStatusPersistenceService.getStatusesByUser(userId)
.stream()