Commit 425beb1c authored by Kristel Meikas's avatar Kristel Meikas
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Kristel Meikas

See merge request teis/common-api-gateway!199
parents 705744ec c3294cc5
...@@ -16,6 +16,7 @@ variables: ...@@ -16,6 +16,7 @@ variables:
API_CONTEXT_PATH: "/api-common" API_CONTEXT_PATH: "/api-common"
API: "common" API: "common"
API_TESTS_ROOT: "api-tests/" API_TESTS_ROOT: "api-tests/"
USE_METRICS: "true"
include: include:
- project: "teis/dev-ops" - project: "teis/dev-ops"
......
# Changelog # Changelog
## [1.22.0] - 2021-03-22
* TEIS-2063: added functionality for accepting GET tasks/count requests
* TEIS-2041: added missing USE_METRICS: "true" configuration parameter for services and gateways, which use Prometheus
monitoring
* TEIS-2041: started using MockMvcUtil to make gateway controller tests more useful
* TEIS-2072: Functionality update for POST/PUT tasks/action-plans request parameter deadline data type
* TEIS-2072: GET tasks/action-plans request parameters deadlineFrom, deadlineUntil, completedAtFrom and completedAtUntil
are now Date instead of DateTime format
* Fixed FileReferenceAccessController String parameter mappings (refactored to UUID)
## [1.21.0] - 2021-03-08 ## [1.21.0] - 2021-03-08
* TEIS-1961: new endpoint for getting authority permissions by grantor. * TEIS-1961: new endpoint for getting authority permissions by grantor.
* TEIS-1959: new endpoint for validating authority's licences. * TEIS-1959: new endpoint for validating authority's licences.
* Updated Minio client dependency to latest version; Code refactor due to MinioClient SDK breaking changes * Updated Minio client dependency to latest version; Code refactor due to MinioClient SDK breaking changes
......
...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO; ...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto; import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.hasText;
public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> { public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.CreateFileReferenceRequest"; public static final String ROUTING_KEY = "api.CreateFileReferenceRequest";
...@@ -20,7 +20,7 @@ public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, Er ...@@ -20,7 +20,7 @@ public class CreateFileReferenceRequest extends AbstractDTO<FileReferenceDto, Er
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
...@@ -6,9 +6,12 @@ import lombok.AllArgsConstructor; ...@@ -6,9 +6,12 @@ import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import static org.springframework.util.StringUtils.isEmpty; import java.util.UUID;
public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters, ErrorDTO> { import static ee.sm.ti.teis.commongateway.file.request.DeleteFileRequest.Parameters;
import static org.springframework.util.StringUtils.hasText;
public class DeleteFileRequest extends AbstractDTO<Parameters, ErrorDTO> {
public static final String ROUTING_KEY = "api.DeleteFileRequest"; public static final String ROUTING_KEY = "api.DeleteFileRequest";
...@@ -23,7 +26,7 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters, ...@@ -23,7 +26,7 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters,
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
...@@ -33,8 +36,8 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters, ...@@ -33,8 +36,8 @@ public class DeleteFileRequest extends AbstractDTO<DeleteFileRequest.Parameters,
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public static class Parameters { public static class Parameters {
private String objectId; private UUID objectId;
private String fileId; private UUID fileId;
private boolean hard; private boolean hard;
} }
......
...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO; ...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileReferenceDto; import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.hasText;
public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> { public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileReferenceDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.FileReferenceContextUpdatePublicRequest"; public static final String ROUTING_KEY = "api.FileReferenceContextUpdatePublicRequest";
...@@ -20,7 +20,7 @@ public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileRef ...@@ -20,7 +20,7 @@ public class FileReferenceContextUpdatePublicRequest extends AbstractDTO<FileRef
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO; ...@@ -4,7 +4,7 @@ import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.file.FileMetadataDto; import ee.sm.ti.teis.commongateway.file.FileMetadataDto;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.hasText;
public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> { public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.FileRequest"; public static final String ROUTING_KEY = "api.FileRequest";
...@@ -20,7 +20,7 @@ public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> { ...@@ -20,7 +20,7 @@ public class FileRequest extends AbstractDTO<FileMetadataDto, ErrorDTO> {
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request; ...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.hasText;
public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> { public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> {
public static final String ROUTING_KEY = "api.FilesMetadataRequest"; public static final String ROUTING_KEY = "api.FilesMetadataRequest";
...@@ -19,7 +19,7 @@ public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> { ...@@ -19,7 +19,7 @@ public class FilesMetadataRequest extends AbstractDTO<String, ErrorDTO> {
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request; ...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.file.request;
import ee.sm.ti.teis.AbstractDTO; import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO; import ee.sm.ti.teis.ErrorDTO;
import static org.springframework.util.StringUtils.isEmpty; import static org.springframework.util.StringUtils.hasText;
public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> { public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> {
public static final String ROUTING_KEY = "api.FilesMetadataTestRequest"; public static final String ROUTING_KEY = "api.FilesMetadataTestRequest";
...@@ -19,7 +19,7 @@ public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> { ...@@ -19,7 +19,7 @@ public class FilesMetadataTestRequest extends AbstractDTO<String, ErrorDTO> {
@Override @Override
public String routingKey() { public String routingKey() {
if (isEmpty(objectType)) { if (!hasText(objectType)) {
return ROUTING_KEY; return ROUTING_KEY;
} }
return ROUTING_KEY.concat(".").concat(objectType.toLowerCase()); return ROUTING_KEY.concat(".").concat(objectType.toLowerCase());
......
...@@ -7,7 +7,7 @@ import lombok.Builder; ...@@ -7,7 +7,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.time.LocalDateTime; import java.time.LocalDate;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
...@@ -15,11 +15,11 @@ import java.time.LocalDateTime; ...@@ -15,11 +15,11 @@ import java.time.LocalDateTime;
@Builder @Builder
public class GetTaskActionPlansDto extends AbstractPagingDto { public class GetTaskActionPlansDto extends AbstractPagingDto {
private LocalDateTime deadlineFrom; private LocalDate deadlineFrom;
private LocalDateTime deadlineUntil; private LocalDate deadlineUntil;
private TaskStatusType status; private TaskStatusType status;
private String description; private String description;
private String responsiblePerson; private String responsiblePerson;
private LocalDateTime completedAtFrom; private LocalDate completedAtFrom;
private LocalDateTime completedAtUntil; private LocalDate completedAtUntil;
} }
...@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor; ...@@ -7,7 +7,7 @@ import lombok.NoArgsConstructor;
import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDate;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
...@@ -16,7 +16,7 @@ import java.time.LocalDateTime; ...@@ -16,7 +16,7 @@ import java.time.LocalDateTime;
public class TaskActionPlanDto { public class TaskActionPlanDto {
@NotNull @NotNull
private LocalDateTime deadline; private LocalDate deadline;
private String reference; private String reference;
@NotBlank @NotBlank
private String description; private String description;
......
...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.tasks.task.actionplan.dto; ...@@ -3,7 +3,7 @@ package ee.sm.ti.teis.commongateway.tasks.task.actionplan.dto;
import lombok.*; import lombok.*;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import java.time.LocalDateTime; import java.time.LocalDate;
import java.util.UUID; import java.util.UUID;
@Data @Data
...@@ -16,7 +16,7 @@ public class UpdateTaskActionPlanDto extends TaskActionPlanDto { ...@@ -16,7 +16,7 @@ public class UpdateTaskActionPlanDto extends TaskActionPlanDto {
private UUID id; private UUID id;
@Builder(builderMethodName = "updateTaskActionPlanDtoBuilder") @Builder(builderMethodName = "updateTaskActionPlanDtoBuilder")
public UpdateTaskActionPlanDto(LocalDateTime deadline, String reference, String description, public UpdateTaskActionPlanDto(LocalDate deadline, String reference, String description,
String responsiblePerson, Boolean highPriority, UUID id) { String responsiblePerson, Boolean highPriority, UUID id) {
super(deadline, reference, description, responsiblePerson, highPriority); super(deadline, reference, description, responsiblePerson, highPriority);
this.id = id; this.id = id;
......
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.validation.constraints.NotNull;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class GetTasksCountDto {
@NotNull
private UUID employerId;
private String taskDefinitionCode;
private String tag;
private Integer nextDays;
}
package ee.sm.ti.teis.commongateway.tasks.task.dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TasksCountDto {
private long totalTasksCount;
private long overdueTasksCount;
private long tagTasksCount;
private long nextDaysTasksCount;
}
package ee.sm.ti.teis.commongateway.tasks.task.request;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.tasks.task.dto.GetTasksCountDto;
public class TasksCountRequest extends AbstractDTO<GetTasksCountDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.TasksCountRequest";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
package ee.sm.ti.teis.commongateway.tasks.task.response;
import ee.sm.ti.teis.AbstractDTO;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.commongateway.tasks.task.dto.TasksCountDto;
public class TasksCountResponse extends AbstractDTO<TasksCountDto, ErrorDTO> {
public static final String ROUTING_KEY = "api.TasksCountResponse";
@Override
public String routingKey() {
return ROUTING_KEY;
}
}
...@@ -11,12 +11,17 @@ apply from: this.getClass().getClassLoader().getResource('teis.microservice.grad ...@@ -11,12 +11,17 @@ apply from: this.getClass().getClassLoader().getResource('teis.microservice.grad
dependencies { dependencies {
implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1' implementation 'javax.ws.rs:javax.ws.rs-api:2.1.1'
compile "ee.sm.ti.teis:files-client-lib:${commonsVersion}" implementation "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}" implementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}" implementation "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
implementation "io.micrometer:micrometer-registry-prometheus" implementation "io.micrometer:micrometer-registry-prometheus"
integTestImplementation "ee.sm.ti.teis:files-client-lib:${commonsVersion}"
integTestImplementation "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
integTestImplementation "ee.sm.ti.teis:gateway-common-lib:${commonsVersion}"
integTestImplementation 'org.springframework.security:spring-security-test:5.4.1'
compile project(':common-api-gateway-lib') compile project(':common-api-gateway-lib')
} }
......
package ee.sm.ti.teis.commongateway; package ee.sm.ti.teis.commongateway;
import ee.sm.ti.teis.CommonApiGateway; import ee.sm.ti.teis.CommonApiGateway;
import ee.sm.ti.teis.gatewaycommon.config.JacksonIntegTestConfig;
import ee.sm.ti.teis.gatewaycommon.rabbit.RequestProcessingService;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.context.ApplicationContextInitializer; import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.LinkedMultiValueMap;
import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.junit.jupiter.Testcontainers;
import static ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase.Initializer;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@SpringBootTest(classes = CommonApiGateway.class) @SpringBootTest(classes = CommonApiGateway.class)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@ActiveProfiles({"mockauth", "integtest", "no_keycloak"}) @ActiveProfiles({"mockauth", "integtest", "no_keycloak"})
@Testcontainers @Testcontainers
@ContextConfiguration(initializers = {CommonApiGatewayTestBase.Initializer.class}) @ContextConfiguration(initializers = {Initializer.class}, classes = JacksonIntegTestConfig.class)
public abstract class CommonApiGatewayTestBase { public abstract class CommonApiGatewayTestBase {
protected LinkedMultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
private static final GenericContainer<?> rabbitMQContainer; private static final GenericContainer<?> rabbitMQContainer;
@MockBean
public RequestProcessingService requestProcessingService;
// to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context // to speed up tests, lets use static container, it is used in all test classes that are executed inside one Spring Context
static { static {
rabbitMQContainer = new GenericContainer<>("rabbitmq:latest").withExposedPorts(5672); rabbitMQContainer = new GenericContainer<>("rabbitmq:latest").withExposedPorts(5672);
......
package ee.sm.ti.teis.commongateway.admin; package ee.sm.ti.teis.commongateway.admin;
import com.fasterxml.jackson.core.type.TypeReference;
import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase; import ee.sm.ti.teis.commongateway.CommonApiGatewayTestBase;
import ee.sm.ti.teis.gatewaycommon.error.NoResponseFromRabbitException; import ee.sm.ti.teis.commongateway.file.FileReferenceDto;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO; import ee.sm.ti.teis.commongateway.messages.message.dto.MessageFileReferenceDto;
import ee.sm.ti.teis.commongateway.messages.message.request.CreateMessageFileReferencesRequest;
import ee.sm.ti.teis.gatewaycommon.MockMvcUtil;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.test.context.support.WithMockUser;
import java.util.List;
import java.util.UUID;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID; 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
public class AdminForTestingControllerTest extends CommonApiGatewayTestBase { public class AdminForTestingControllerTest extends CommonApiGatewayTestBase {
private static final String BASE_URL = "/admin/";
@Autowired @Autowired
AdminForTestingController controller; MockMvcUtil mockMvcUtil;
@Test @Test
void resetMessageEmail_throwsException() { void resetMessageEmail_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(ResetMessageEmailRequest.class)))
controller.resetMessageEmail(randomUUID(), new RequestMetaDTO())); .thenReturn(randomUUID());
mockMvcUtil.testGet(BASE_URL + "reset-message-email/" + randomUUID(), null, new TypeReference<UUID>() {
});
verify(requestProcessingService).sendAndReceive(any(ResetMessageEmailRequest.class));
} }
@Test @Test
void getMessages_throwsException() { void createFileReferences_success() {
assertThrows(NoResponseFromRabbitException.class, () -> when(requestProcessingService.sendAndReceive(any(CreateMessageFileReferencesRequest.class)))
controller.createFileReferences(randomUUID(), emptyList(), new RequestMetaDTO())); .thenReturn(List.of(new FileReferenceDto()));
}
mockMvcUtil.testPost(BASE_URL + "message/" + randomUUID() + "/file-references", List.of(new MessageFileReferenceDto()),
new TypeReference<List<FileReferenceDto>>() {
});
verify(requestProcessingService).sendAndReceive(any(CreateMessageFileReferencesRequest.class));
}
} }