Pull request #312: RED-3628 Bugfix for downloading archived dossiers
Merge in RED/persistence-service from RED-3628 to master * commit 'fcdab28921277270fd11070e2857274650f97f30': RED-3628 Bugfix for downloading archived dossiers
This commit is contained in:
commit
723a02dffc
@ -1,13 +1,18 @@
|
|||||||
package com.iqser.red.service.persistence.service.v1.api.resources;
|
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.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.DownloadRequest;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatus;
|
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)
|
@ResponseStatus(value = HttpStatus.OK)
|
||||||
public interface DownloadResource {
|
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)
|
@PostMapping(value = REST_PATH + "/prepare", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
||||||
JSONPrimitive<String> prepareDownload(@RequestBody DownloadRequest request);
|
JSONPrimitive<String> prepareDownload(@RequestBody DownloadRequest request);
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = REST_PATH + "/status/{" + USER_ID + "}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
|
@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);
|
List<DownloadStatus> getDownloadStatus(@PathVariable(USER_ID) String userId);
|
||||||
|
|
||||||
|
|||||||
@ -90,6 +90,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) {
|
public DossierEntity getAndValidateDossier(String dossierId) {
|
||||||
// check whether the dossierId exists and is not deleted
|
// check whether the dossierId exists and is not deleted
|
||||||
var dossier = findByDossierId(dossierId);
|
var dossier = findByDossierId(dossierId);
|
||||||
|
|||||||
@ -1,5 +1,16 @@
|
|||||||
package com.iqser.red.service.peristence.v1.server.controller;
|
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.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.iqser.red.service.peristence.v1.server.configuration.MessagingConfiguration;
|
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.DownloadRequest;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatus;
|
import com.iqser.red.service.persistence.service.v1.api.model.download.DownloadStatus;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.resources.DownloadResource;
|
import com.iqser.red.service.persistence.service.v1.api.resources.DownloadResource;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
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;
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class DownloadController implements DownloadResource {
|
public class DownloadController implements DownloadResource {
|
||||||
@ -42,15 +46,11 @@ public class DownloadController implements DownloadResource {
|
|||||||
var mimeType = "application/zip";
|
var mimeType = "application/zip";
|
||||||
|
|
||||||
var existingFileStatuses = fileStatusPersistenceService.getStatusesForDossier(request.getDossierId());
|
var existingFileStatuses = fileStatusPersistenceService.getStatusesForDossier(request.getDossierId());
|
||||||
|
|
||||||
String downloadFilename = buildName(request.getDossierId(), request.getFileIds(), request.getUserId(), mimeType, existingFileStatuses);
|
String downloadFilename = buildName(request.getDossierId(), request.getFileIds(), request.getUserId(), mimeType, existingFileStatuses);
|
||||||
|
|
||||||
String storageId = StorageIdUtils.getStorageId(request.getUserId(), request.getDossierId(), downloadFilename);
|
String storageId = StorageIdUtils.getStorageId(request.getUserId(), request.getDossierId(), downloadFilename);
|
||||||
|
var dossier = dossierPersistenceService.getActiveOrArchivedDossier(request.getDossierId());
|
||||||
var dossier = dossierPersistenceService.getAndValidateDossier(request.getDossierId());
|
|
||||||
|
|
||||||
downloadStatusPersistenceService.createStatus(request.getUserId(), storageId, dossier, downloadFilename, mimeType, request.getFileIds(), dossier.getDownloadFileTypes());
|
downloadStatusPersistenceService.createStatus(request.getUserId(), storageId, dossier, downloadFilename, mimeType, request.getFileIds(), dossier.getDownloadFileTypes());
|
||||||
|
|
||||||
addToDownloadQueue(DownloadJob.builder().storageId(storageId).userId(request.getUserId()).build(), 1);
|
addToDownloadQueue(DownloadJob.builder().storageId(storageId).userId(request.getUserId()).build(), 1);
|
||||||
|
|
||||||
return new JSONPrimitive<>(storageId);
|
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,
|
private String buildName(String dossierId, List<String> fileIds, String userId, String mimeType,
|
||||||
List<FileEntity> existingFileStatuses) {
|
List<FileEntity> existingFileStatuses) {
|
||||||
|
|
||||||
var dossier = dossierPersistenceService.getAndValidateDossier(dossierId);
|
var dossier = dossierPersistenceService.getActiveOrArchivedDossier(dossierId);
|
||||||
|
|
||||||
Set<String> existingFilenames = downloadStatusPersistenceService.getStatusesByUser(userId)
|
Set<String> existingFilenames = downloadStatusPersistenceService.getStatusesByUser(userId)
|
||||||
.stream()
|
.stream()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user