Commit 28edf059 authored by Siiri Tann's avatar Siiri Tann
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Siiri Tann

See merge request teis/common-api-gateway!203
parents 425beb1c 7bd2a292
# Changelog
## [1.23.0] - 2021-04-12
* TEIS-2086: functionality for accepting GET extract to file requests for proceeding messages
* TEIS-2041: removed deprecated ClassifierItemCodeDto and replaced current usages with standardized
ClassifierItemLightDto
## [1.22.0] - 2021-03-22
* TEIS-2063: added functionality for accepting GET tasks/count requests
......
package ee.sm.ti.teis.commongateway.classifier;
package ee.sm.ti.teis.commongateway.docgen.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ClassifierItemCodeDto {
private String code;
public class GeneratedDocumentDto {
private String templateId;
private String docName;
private String contentType;
private byte[] content;
}
package ee.sm.ti.teis.commongateway.person.search;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemCodeDto;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
......@@ -17,5 +17,5 @@ public class IndividualPersonSearchFilterDto {
private String firstName;
private String lastName;
private LocalDate dateOfBirth;
private ClassifierItemCodeDto country;
private ClassifierItemLightDto country;
}
package ee.sm.ti.teis.commongateway.person.search;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemCodeDto;
import ee.sm.ti.teis.commongateway.classifier.ClassifierItemLightDto;
import lombok.Data;
@Data
public class LegalPersonSearchFilterDto {
private String regCode;
private String name;
private ClassifierItemCodeDto country;
private ClassifierItemLightDto country;
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.dto;
import lombok.*;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ProceedingMessageExtractedDto {
private String sentBy;
private String sentAt;
private String readAt;
private String content;
private Boolean removed;
private List<String> attachments;
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.dto;
import lombok.*;
import java.util.List;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ProceedingMessagesExtractedDto {
private String extractionTime;
private String employerName;
private String employerRegCode;
private String proceedingNumber;
private List<ProceedingMessageExtractedDto> messages;
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import java.util.UUID;
public class ProceedingExtractToFileRequest extends AbstractDTO<UUID, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingExtractToFileRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.docgen.dto.GeneratedDocumentDto;
public class ProceedingExtractToFileResponse extends AbstractDTO<GeneratedDocumentDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.ProceedingExtractToFileResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
......@@ -2,22 +2,34 @@ package ee.sm.ti.teis.commongateway.proceedings.proceeding;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.commongateway.docgen.dto.GeneratedDocumentDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.dto.MessagePermissionDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.dto.ProceedingPublicDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.MessagePermissionRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingExtractToFileRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingPublicRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingsPublicRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.response.ProceedingExtractToFileResponse;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.security.test.context.support.WithMockUser;
import java.io.UnsupportedEncodingException;
import java.util.List;
import static java.nio.charset.StandardCharsets.UTF_8;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.util.MimeTypeUtils.APPLICATION_XML_VALUE;
@WithMockUser
public class ProceedingControllerTest extends CommonApiGatewayTestBase {
......@@ -27,6 +39,13 @@ public class ProceedingControllerTest extends CommonApiGatewayTestBase {
@Autowired
MockMvcUtil mockMvcUtil;
@Autowired
ProceedingController proceedingController;
@Autowired
ProceedingProcessingService proceedingProcessingService;
@MockBean
RabbitTemplate gwRabbitTemplate;
@Test
void getProceeding_success() {
when(requestProcessingService.sendAndReceive(any(ProceedingPublicRequest.class)))
......@@ -50,7 +69,6 @@ public class ProceedingControllerTest extends CommonApiGatewayTestBase {
verify(requestProcessingService).sendAndReceive(any(ProceedingsPublicRequest.class));
}
@Test
void getMessagePermission_success() {
when(requestProcessingService.sendAndReceive(any(MessagePermissionRequest.class)))
......@@ -62,4 +80,24 @@ public class ProceedingControllerTest extends CommonApiGatewayTestBase {
verify(requestProcessingService).sendAndReceive(any(MessagePermissionRequest.class));
}
@Test
void extractToFile_success() throws UnsupportedEncodingException {
ProceedingExtractToFileResponse response = new ProceedingExtractToFileResponse();
String content = "test-content";
GeneratedDocumentDto payload = GeneratedDocumentDto.builder()
.docName("proceeding-document")
.contentType(APPLICATION_XML_VALUE)
.content(content.getBytes(UTF_8))
.build();
response.setPayload(payload, new RequestMetaDTO());
when(gwRabbitTemplate.convertSendAndReceive(anyString(), any(ProceedingExtractToFileRequest.class))).thenReturn(response);
MockHttpServletResponse httpResponse = new MockHttpServletResponse();
proceedingController.extractToFile(randomUUID(), new RequestMetaDTO(), httpResponse);
assertThat(httpResponse.getContentAsString()).isEqualTo(content);
}
}
......@@ -3,6 +3,7 @@ package ee.sm.ti.teis.commongateway.proceedings.proceeding;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.dto.MessagePermissionDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.dto.ProceedingPublicDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.MessagePermissionRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingExtractToFileRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingPublicRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingsPublicRequest;
import ee.sm.ti.teis.gatewaycommon.controller.TeisBaseController;
......@@ -14,7 +15,9 @@ import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.UUID;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
......@@ -24,6 +27,7 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
public class ProceedingController extends TeisBaseController {
private final RequestProcessingService service;
private final ProceedingProcessingService processingService;
@ApiOperation(value = "${teis.api.messages.proceeding.get-proceeding}", response = ProceedingPublicDto.class)
@ApiImplicitParams(@ApiImplicitParam(name = "id", value = "${teis.api.messages.proceeding.get-proceeding-id}"))
......@@ -54,4 +58,14 @@ public class ProceedingController extends TeisBaseController {
return (List<MessagePermissionDto>) service.sendAndReceive(request);
}
@ApiOperation(value = "${teis.api.messages.proceeding.extract-to-file}")
@GetMapping("{id}/extract-to-file")
public void extractToFile(@PathVariable UUID id, RequestMetaDTO requestMetaDTO, HttpServletResponse response) {
ProceedingExtractToFileRequest request = new ProceedingExtractToFileRequest();
request.setPayload(id, requestMetaDTO);
processingService.extractToFile(request, response);
}
}
package ee.sm.ti.teis.commongateway.proceedings.proceeding;
import ee.sm.ti.teis.commongateway.docgen.dto.GeneratedDocumentDto;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.request.ProceedingExtractToFileRequest;
import ee.sm.ti.teis.commongateway.proceedings.proceeding.response.ProceedingExtractToFileResponse;
import ee.sm.ti.teis.exceptions.TeisBusinessException;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException;
import lombok.RequiredArgsConstructor;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import static ee.sm.ti.teis.errors.CommonErrorCode.BAD_REQUEST;
@Service
@RequiredArgsConstructor
public class ProceedingProcessingService {
public static final String CONTENT_DISPOSITION = "Content-disposition";
public static final String ATTACHMENT_FILENAME = "attachment;filename=";
private final RabbitTemplate gwRabbitTemplate;
public void extractToFile(ProceedingExtractToFileRequest request, HttpServletResponse httpServletResponse) {
ProceedingExtractToFileResponse response =
(ProceedingExtractToFileResponse) gwRabbitTemplate.convertSendAndReceive(request.routingKey(), request);
if (response != null) {
GeneratedDocumentDto generatedDocument = response.processResponse();
if (generatedDocument != null) {
httpServletResponse.addHeader(CONTENT_DISPOSITION, ATTACHMENT_FILENAME + generatedDocument.getDocName());
httpServletResponse.setContentType(generatedDocument.getContentType());
try (ByteArrayInputStream docStream = new ByteArrayInputStream(generatedDocument.getContent())) {
IOUtils.copy(docStream, httpServletResponse.getOutputStream());
httpServletResponse.flushBuffer();
} catch (IOException e) {
throw new TeisBusinessException(BAD_REQUEST, "Document template processing failed.");
}
}
return;
}
throw new NoResponseFromRabbitException(request.getRequestMetaDTO().getRequestId());
}
}
......@@ -83,6 +83,7 @@ teis.api.messages.proceeding.create-proceeding-inspection-document-weblinks: API
teis.api.messages.proceeding.delete-proceeding-inspection-document-weblinks: API kustutab menetluse dokumendile veeblingi
teis.api.messages.proceeding.get-proceeding-inspection-document-weblinks: API tagastab menetluse dokumendile veeblingid
teis.api.messages.proceeding.get-message-permissions: API abil on võimalik kontrollida, kas TI teenistuja või tööandja saab vaadata või muuta sõnumi andmeid.
teis.api.messages.proceeding.extract-to-file: Teenust kasutatakse menetluse sõnumite andmete eksportimiseks faili.
teis.api.messages.task.post-task: Teenus salvestab uue ülesande.
teis.api.messages.task.get-tasks: Teenus väljastab ülesande andmeobjektid. Teenust kasutatakse ülesannete kuvamiseks.
......
theGroup=ee.sm.ti.teis
theVersion=1.22.0
commonsVersion=1.22.0
theVersion=1.23.0
commonsVersion=1.23.0
pluginVersion=1.3.0
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment