Commit 8c0e676e authored by Siiri Tann's avatar Siiri Tann
Browse files

TEIS-2109: improved tests.

parent 4ca01990
package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileReferenceContextUpdatePublicRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataRequest;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.nio.charset.Charset.defaultCharset;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.testcontainers.shaded.org.apache.commons.io.IOUtils.toInputStream;
@WithMockUser
class FileControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
FileController controller;
@Autowired
MockMvcUtil mockMvcUtil;
@MockBean
FileStorageServiceClient fileStorageServiceClient;
@Test
void getFilesMetadata() {
void upload_throwError() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.getFilesMetadata(VIOLATION, "", new RequestMetaDTO()));
controller.upload(VIOLATION, randomUUID(), new MockHttpServletRequest(), new RequestMetaDTO()));
}
@Test
void delete() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.delete(VIOLATION, randomUUID(), randomUUID(), new RequestMetaDTO()));
void updateContext_success() {
when(requestProcessingService.sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class)))
.thenReturn(new FileReferenceDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID() + "/context", new FileReferenceDto(), new TypeReference<FileReferenceDto>() {
});
verify(requestProcessingService).sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class));
}
@Test
void download_() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO()));
void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(FilesMetadataRequest.class));
}
@Test
void download_success() {
String fileId = randomUUID().toString();
when(requestProcessingService.sendAndReceive(any()))
.thenReturn(FileMetadataDto.builder()
.contentType("application/text")
.size(12439L)
.bucket("test-bucket")
.build());
when(fileStorageServiceClient.getFileStream(anyString(), anyString()))
.thenReturn(toInputStream("test", defaultCharset()));
mockMvcUtil.testGet(BASE_URL + fileId + "/download/test-file",
null, null, true);
verify(fileStorageServiceClient).getFileStream(eq("test-bucket"), eq(fileId));
}
@Test
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
}
}
package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileReferenceContextUpdatePublicRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletRequest;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import static ee.sm.ti.teis.commongateway.file.FileObjectType.VIOLATION;
import static java.util.UUID.randomUUID;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@WithMockUser
class FileTestControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/" + VIOLATION.name() + "/" + randomUUID() + "/files/";
@Autowired
FileController controller;
@Autowired
MockMvcUtil mockMvcUtil;
@Test
void upload_throwError() {
assertThrows(NoResponseFromRabbitException.class, () ->
controller.upload(VIOLATION, randomUUID(), new MockHttpServletRequest(), new RequestMetaDTO()));
}
@Test
void updateContext_success() {
when(requestProcessingService.sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class)))
.thenReturn(new FileReferenceDto());
mockMvcUtil.testPatch(BASE_URL + randomUUID() + "/context", new FileReferenceDto(), new TypeReference<FileReferenceDto>() {
});
verify(requestProcessingService).sendAndReceive(any(FileReferenceContextUpdatePublicRequest.class));
}
@Test
void getFilesMetadata_success() {
when(requestProcessingService.sendAndReceive(any(FilesMetadataRequest.class)))
.thenReturn(List.of(new FileReferenceDto()));
mockMvcUtil.testGet(BASE_URL, null, new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(FilesMetadataRequest.class));
}
@Test
void download_throwError() {
assertThrows(NullPointerException.class, () ->
controller.download(VIOLATION, randomUUID().toString(), randomUUID().toString(), "",
new MockHttpServletResponse(), new RequestMetaDTO()));
}
@Test
void delete_success() {
mockMvcUtil.testDelete(BASE_URL + randomUUID());
verify(requestProcessingService).sendAndReceive(any(DeleteFileRequest.class));
}
}
......@@ -3,9 +3,14 @@ package ee.sm.ti.teis.commongateway.file;
import com.fasterxml.jackson.databind.ObjectMapper;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.file.request.CreateFileReferenceRequest;
import ee.sm.ti.teis.commongateway.file.request.FileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileStorageUploadFailedRequest;
import ee.sm.ti.teis.commongateway.file.request.UpdateFileMetaRequest;
import ee.sm.ti.teis.exceptions.TeisBusinessException;
import ee.sm.ti.teis.exceptions.TeisRestException;
import ee.sm.ti.teis.fileclient.FileStorageServiceClient;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.types.enums.FileParameterType;
import lombok.RequiredArgsConstructor;
......@@ -40,22 +45,15 @@ import static org.springframework.http.HttpStatus.PAYLOAD_TOO_LARGE;
@RequiredArgsConstructor
public class FileContentService {
private final FileMetaProcessingService fileMetaProcessingService;
private final FileProcessingService fileProcessingService;
private final ParameterService parameterService;
private final ThumbnailService thumbnailService;
private final FileStorageServiceClient fileStorageServiceClient;
private final RequestProcessingService service;
@Value("${teis.file.file-reference.update-timeout}")
private int fileReferenceUpdateTimeout;
@Value("${teis.file.upload.max-http-request-header-size}")
private int maxHttpRequestHeaderSize;
public FileReferenceDto updateContext(FileReferenceDto fileReferenceDto, String objectType,
RequestMetaDTO requestMetaDTO) {
return fileProcessingService.updateContext(fileReferenceDto, objectType, requestMetaDTO);
}
public FileReferenceDto saveFileToStorage(HttpServletRequest request, UUID objectId, FileObjectType objectType,
RequestMetaDTO requestMetaDTO) throws Exception {
UUID fileId = UUID.randomUUID();
......@@ -106,12 +104,12 @@ public class FileContentService {
if (item.getFieldName().equals("data")) {
FileReferenceDto fileReference = getFileReferenceDto(stream);
futureFileReferenceDto = CompletableFuture.supplyAsync(() ->
fileProcessingService.save(fileId, objectId, objectType.name(), fileReference, requestMetaDTO));
save(fileId, objectId, objectType.name(), fileReference, requestMetaDTO));
} else if (item.getFieldName().equals("contextType")) {
String contextType = Streams.asString(stream);
FileReferenceDto fileReference = FileReferenceDto.builder().contextType(ClassifierItemLightDto.builder().code(contextType).build()).build();
futureFileReferenceDto = CompletableFuture.supplyAsync(() ->
fileProcessingService.save(fileId, objectId, objectType.name(), fileReference, requestMetaDTO));
save(fileId, objectId, objectType.name(), fileReference, requestMetaDTO));
}
}
}
......@@ -119,7 +117,7 @@ public class FileContentService {
if (futureFileReferenceDto != null) {
fileReferenceDto = futureFileReferenceDto.get(fileReferenceUpdateTimeout, MILLISECONDS);
} else {
fileReferenceDto = fileProcessingService.save(fileId, objectId, objectType.name(), new FileReferenceDto(), requestMetaDTO);
fileReferenceDto = save(fileId, objectId, objectType.name(), new FileReferenceDto(), requestMetaDTO);
}
if (!fileExists) {
......@@ -127,8 +125,10 @@ public class FileContentService {
}
FileMetadataDto fileMetadataDto = composeFileMetaData(fileId, fileName, contentType, bucket);
FileMetadataDto updatedFilesMetadata =
fileMetaProcessingService.updateFileMetadata(fileMetadataDto, objectId, requestMetaDTO);
UpdateFileMetaRequest updateFileMetaRequest = new UpdateFileMetaRequest();
fileMetadataDto.setObjectId(objectId);
updateFileMetaRequest.setPayload(fileMetadataDto, requestMetaDTO);
FileMetadataDto updatedFilesMetadata = (FileMetadataDto) service.sendAndReceive(updateFileMetaRequest);
fileReferenceDto.setFileStatus(updatedFilesMetadata.getFileStatusType());
fileReferenceDto.setFileName(fileName);
......@@ -137,7 +137,9 @@ public class FileContentService {
} catch (Exception e) {
log.error("File upload failed, notifying services..", e);
if (fileReferenceDto != null && fileReferenceDto.getObjectId() != null) {
fileMetaProcessingService.notifyStorageUploadFailed(fileId, objectId, requestMetaDTO);
FileStorageUploadFailedRequest fileStorageUploadFailedRequest = new FileStorageUploadFailedRequest();
fileStorageUploadFailedRequest.setPayload(new FileStorageUploadFailedRequest.Parameters(fileId, objectId), requestMetaDTO);
service.sendAndReceive(fileStorageUploadFailedRequest);
}
if (isTeisException(e)) {
throw e;
......@@ -212,14 +214,18 @@ public class FileContentService {
String objectType, RequestMetaDTO requestMetaDTO) throws IOException {
log.info("File retrieval from storage initiated for file ID: {}", fileId);
FileMetadataDto dto = fileProcessingService.getFile(UUID.fromString(objectId), UUID.fromString(fileId),
objectType, requestMetaDTO);
FileRequest request = new FileRequest(objectType);
FileMetadataDto dto = new FileMetadataDto();
dto.setObjectId(UUID.fromString(objectId));
dto.setFileId(UUID.fromString(fileId));
request.setPayload(dto, requestMetaDTO);
FileMetadataDto fileMetadataDto = (FileMetadataDto) service.sendAndReceive(request);
setDownloadHeaders(fileName, response, dto);
setDownloadHeaders(fileName, response, fileMetadataDto);
fileStorageServiceClient.getFileMetadata(dto.getBucket(), fileId);
fileStorageServiceClient.getFileMetadata(fileMetadataDto.getBucket(), fileId);
IOUtils.copyLarge(fileStorageServiceClient.getFileStream(dto.getBucket(), fileId), response.getOutputStream());
IOUtils.copyLarge(fileStorageServiceClient.getFileStream(fileMetadataDto.getBucket(), fileId), response.getOutputStream());
response.flushBuffer();
}
......@@ -233,9 +239,14 @@ public class FileContentService {
return e instanceof TeisBusinessException || e instanceof TeisRestException;
}
void getThumbnailFileFromStorage(String objectId, String fileId, HttpServletResponse response,
String objectType, RequestMetaDTO requestMetaDTO) throws Exception {
thumbnailService.getThumbnailFileFromStorage(objectId, fileId, response, objectType, requestMetaDTO);
private FileReferenceDto save(UUID fileId, UUID objectId, String objectType, FileReferenceDto dto, RequestMetaDTO requestMetaDTO) {
CreateFileReferenceRequest request = new CreateFileReferenceRequest(objectType);
dto.setFileId(fileId);
dto.setObjectId(objectId);
dto.setObjectType(ClassifierItemLightDto.builder().code(objectType).build());
request.setPayload(dto, requestMetaDTO);
return (FileReferenceDto) service.sendAndReceive(request);
}
}
package ee.sm.ti.teis.commongateway.file;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest;
import ee.sm.ti.teis.commongateway.file.request.FileReferenceContextUpdatePublicRequest;
import ee.sm.ti.teis.commongateway.file.request.FilesMetadataRequest;
import ee.sm.ti.teis.gatewaycommon.controller.TeisBaseController;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
......@@ -17,32 +22,39 @@ import java.util.UUID;
public class FileController extends TeisBaseController {
private final FileContentService fileContentService;
private final FileProcessingService fileProcessingService;
private final RequestProcessingService service;
private final ThumbnailService thumbnailService;
@ApiOperation(value = "${teis.api.messages.proceeding.post-file}")
@PostMapping
public FileReferenceDto upload(@PathVariable("fileReferencePath") FileObjectType fileReferencePath,
@PathVariable UUID id, HttpServletRequest request,
RequestMetaDTO requestMetaDTO) throws Exception {
public FileReferenceDto upload(@PathVariable("fileReferencePath") FileObjectType fileReferencePath, @PathVariable UUID id,
HttpServletRequest request, RequestMetaDTO requestMetaDTO) throws Exception {
return fileContentService.saveFileToStorage(request, id, fileReferencePath, requestMetaDTO);
}
@ApiOperation(value = "${teis.api.messages.proceeding.update-file-context}")
@PatchMapping("{fileId}/context")
public FileReferenceDto updateContext(@PathVariable("fileReferencePath") FileObjectType fileReferencePath,
@PathVariable UUID fileId, @PathVariable UUID id,
@RequestBody FileReferenceDto fileReferenceDto,
@PathVariable UUID fileId, @PathVariable UUID id, @RequestBody FileReferenceDto fileReferenceDto,
RequestMetaDTO requestMetaDTO) {
fileReferenceDto.setFileId(fileId);
fileReferenceDto.setObjectId(id);
return fileContentService.updateContext(fileReferenceDto, fileReferencePath.name(), requestMetaDTO);
FileReferenceContextUpdatePublicRequest request = new FileReferenceContextUpdatePublicRequest(fileReferencePath.name());
fileReferenceDto.setObjectType(ClassifierItemLightDto.builder().code(fileReferencePath.name()).build());
request.setPayload(fileReferenceDto, requestMetaDTO);
return (FileReferenceDto) service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.proceeding.get-files-metadata}")
@GetMapping
public List<FileReferenceDto> getFilesMetadata(@PathVariable("fileReferencePath") FileObjectType objectType,
@PathVariable String id, RequestMetaDTO requestMetaDTO) {
return fileProcessingService.getFilesMetadata(id, objectType.name(), requestMetaDTO);
FilesMetadataRequest request = new FilesMetadataRequest(objectType.name());
request.setPayload(id, requestMetaDTO);
return (List<FileReferenceDto>) service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.proceeding.get-file}")
......@@ -50,6 +62,7 @@ public class FileController extends TeisBaseController {
public void download(@PathVariable("fileReferencePath") FileObjectType fileReferencePath, @PathVariable String id,
@PathVariable String fileId, @PathVariable String fileName, HttpServletResponse response,
RequestMetaDTO requestMetaDTO) throws Exception {
fileContentService.getFileFromStorage(id, fileId, fileName, response, fileReferencePath.name(), requestMetaDTO);
}
......@@ -57,16 +70,18 @@ public class FileController extends TeisBaseController {
@DeleteMapping("{fileId}")
public void delete(@PathVariable("fileReferencePath") FileObjectType fileReferencePath, @PathVariable UUID id,
@PathVariable UUID fileId, RequestMetaDTO requestMetaDTO) {
fileProcessingService.delete(id, fileId, fileReferencePath.name(), requestMetaDTO);
DeleteFileRequest request = new DeleteFileRequest(fileReferencePath.name());
request.setPayload(new DeleteFileRequest.Parameters(id, fileId, false), requestMetaDTO);
service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.proceeding.get-thumbnail-file}")
@GetMapping("{fileId}/thumbnail")
public void downloadThumbnail(@PathVariable("fileReferencePath") FileObjectType fileReferencePath,
@PathVariable String id, @PathVariable String fileId,
HttpServletResponse response,
RequestMetaDTO requestMetaDTO) throws Exception {
fileContentService.getThumbnailFileFromStorage(id, fileId, response, fileReferencePath.name(), requestMetaDTO);
public void downloadThumbnail(@PathVariable("fileReferencePath") FileObjectType fileReferencePath, @PathVariable String id,
@PathVariable String fileId, HttpServletResponse response, RequestMetaDTO requestMetaDTO) throws Exception {
thumbnailService.getThumbnailFileFromStorage(id, fileId, response, fileReferencePath.name(), requestMetaDTO);
}
}
package ee.sm.ti.teis.commongateway.file;
import ee.sm.ti.teis.commongateway.file.request.FileStorageUploadFailedRequest;
import ee.sm.ti.teis.commongateway.file.request.UpdateFileMetaRequest;
import ee.sm.ti.teis.commongateway.file.response.UpdateFileMetaResponse;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import java.util.UUID;
@Service
@RequiredArgsConstructor
public class FileMetaProcessingService {
private final RabbitTemplate gwRabbitTemplate;
FileMetadataDto updateFileMetadata(FileMetadataDto fileMetadata, UUID violationId, RequestMetaDTO requestMetaDTO) {
UpdateFileMetaRequest request = new UpdateFileMetaRequest();
fileMetadata.setObjectId(violationId);
request.setPayload(fileMetadata, requestMetaDTO);
UpdateFileMetaResponse response =
(UpdateFileMetaResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
void notifyStorageUploadFailed(UUID fileId, UUID violationId, RequestMetaDTO requestMetaDTO) {
FileStorageUploadFailedRequest request = new FileStorageUploadFailedRequest();
request.setPayload(new FileStorageUploadFailedRequest.Parameters(fileId, violationId), requestMetaDTO);
gwRabbitTemplate.convertAndSend(request.routingKey(), request);
}
}
package ee.sm.ti.teis.commongateway.file;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import ee.sm.ti.teis.commongateway.file.request.*;
import ee.sm.ti.teis.commongateway.file.response.*;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.UUID;
@Service
@RequiredArgsConstructor
public class FileProcessingService {
private final RabbitTemplate gwRabbitTemplate;
FileReferenceDto save(UUID fileId, UUID objectId, String objectType, FileReferenceDto dto, RequestMetaDTO requestMetaDTO) {
CreateFileReferenceRequest request = new CreateFileReferenceRequest(objectType);
dto.setFileId(fileId);
dto.setObjectId(objectId);
dto.setObjectType(ClassifierItemLightDto.builder().code(objectType).build());
request.setPayload(dto, requestMetaDTO);
CreateFileReferenceResponse response =
(CreateFileReferenceResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
FileReferenceDto updateContext(FileReferenceDto dto, String objectType, RequestMetaDTO requestMetaDTO) {
FileReferenceContextUpdatePublicRequest request = new FileReferenceContextUpdatePublicRequest(objectType);
dto.setObjectType(ClassifierItemLightDto.builder().code(objectType).build());
request.setPayload(dto, requestMetaDTO);
FileReferenceContextUpdatePublicResponse response =
(FileReferenceContextUpdatePublicResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
List<FileReferenceDto> getFilesMetadata(String id, String objectType, RequestMetaDTO requestMetaDTO) {
FilesMetadataRequest request = new FilesMetadataRequest(objectType);
request.setPayload(id, requestMetaDTO);
FilesMetadataResponse response =
(FilesMetadataResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
List<FileReferenceDto> getFilesTestMetadata(String id, String objectType, RequestMetaDTO requestMetaDTO) {
FilesMetadataTestRequest request = new FilesMetadataTestRequest(objectType);
request.setPayload(id, requestMetaDTO);
FilesMetadataTestResponse response =
(FilesMetadataTestResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
FileMetadataDto getFile(UUID objectId, UUID fileId, String objectType, RequestMetaDTO requestMetaDTO) {
FileRequest request = new FileRequest(objectType);
FileMetadataDto dto = new FileMetadataDto();
dto.setObjectId(objectId);
dto.setFileId(fileId);
request.setPayload(dto, requestMetaDTO);
FileResponse response =
(FileResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
return response.processResponse();
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
public void delete(UUID id, UUID fileId, String objectType, RequestMetaDTO requestMetaDTO) {
DeleteFileRequest request = new DeleteFileRequest(objectType);
request.setPayload(new DeleteFileRequest.Parameters(id, fileId, false), requestMetaDTO);
DeleteFileResponse response =
(DeleteFileResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
response.processResponse();
return;
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}