Commit c70b2d74 authored by Siiri Tann's avatar Siiri Tann
Browse files

TEIS-2220: new ms endpoint for getting classifierItems by definition.

parent f0d4d6dd
......@@ -4,15 +4,17 @@ import ee.sm.ti.teis.ClassifierTestBase;
import ee.sm.ti.teis.classifiers.classifier.item.listener.ClassifierItemsMsListener;
import ee.sm.ti.teis.classifiers.classifier.item.listener.ClassifierItemsMsListener.ClassifierItemsResponseMessage;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.ClassifierItemsByDefinition;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.Test;
import javax.inject.Inject;
import java.util.stream.Collectors;
import static ee.sm.ti.teis.classifiers.classifier.item.listener.ClassifierItemsMsListener.ClassifierItemResponseMessage;
import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.ClassifierItemDomainRequest;
import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.ClassifierItemsDomainRequest;
import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.*;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -107,4 +109,33 @@ class ClassifierItemsMsListenerTest extends ClassifierTestBase {
assertThat(252).isEqualTo(defaultValue.getPayload().size());
}
@Test
void getMsCurrentClassifierItemsByDefinition_idMissing_badRequest() {
ClassifierItemsByDefinition itemPayload = new ClassifierItemsByDefinition();
itemPayload.setDefinitionId(null);
ClassifierItemsByDefinitionDomainRequest domainsRequest = new ClassifierItemsByDefinitionDomainRequest();
domainsRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemsMsListener.ClassifierItemsByDefinitionResponseMessage response =
classifierItemsMsListener.getMsCurrentClassifierItemsByDefinition(domainsRequest);
assertBadRequest(response.getError());
}
@Test
void getMsCurrentClassifierItemsByDefinition_success() {
ClassifierItemsByDefinition itemPayload = new ClassifierItemsByDefinition();
itemPayload.setDefinitionId("TEST_EDITABLENONHIERARCHICAL");
ClassifierItemsByDefinitionDomainRequest domainsRequest = new ClassifierItemsByDefinitionDomainRequest();
domainsRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemsMsListener.ClassifierItemsByDefinitionResponseMessage response =
classifierItemsMsListener.getMsCurrentClassifierItemsByDefinition(domainsRequest);
assertThat(response.getPayload()).size().isGreaterThanOrEqualTo(2);
assertThat(response.getPayload().stream().map(ClassifierItem::getId).collect(Collectors.toList()))
.contains("TEST_EDITABLENONHIERARCHICAL__TEST001", "TEST_EDITABLENONHIERARCHICAL__TEST003")
.doesNotContain("TEST_EDITABLENONHIERARCHICAL__TEST002");
}
}
......@@ -39,6 +39,15 @@ public class ClassifierItemsMsListener {
return resultDTO;
}
@RabbitListener(queues = {MS_CLASSIFIER_ITEMS_BY_DEFINITION_QUEUE})
public ClassifierItemsByDefinitionResponseMessage getMsCurrentClassifierItemsByDefinition(ClassifierItemsByDefinitionDomainRequest requestDTO) {
List<ClassifierItem> classifierItems =
classifierItemBusinessService.getListByDefinition(requestDTO.getPayload().getDefinitionId());
ClassifierItemsByDefinitionResponseMessage resultDTO = new ClassifierItemsByDefinitionResponseMessage();
resultDTO.setPayload(classifierItems, requestDTO.getRequestMetaDTO());
return resultDTO;
}
private ClassifierItemSearchFilterDto composeSearchFilterDto(ClassifierItem payload) {
ClassifierItemSearchFilterDto search = new ClassifierItemSearchFilterDto();
if (payload.getAttributes() != null) {
......@@ -57,4 +66,7 @@ public class ClassifierItemsMsListener {
public static class ClassifierItemsResponseMessage extends DomainQueryResponseDto<List<ClassifierItem>, ErrorDTO> {
}
public static class ClassifierItemsByDefinitionResponseMessage extends DomainQueryResponseDto<List<ClassifierItem>, ErrorDTO> {
}
}
......@@ -30,6 +30,7 @@ import org.springframework.validation.annotation.Validated;
import javax.transaction.Transactional;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Optional;
import java.util.regex.Matcher;
......@@ -202,12 +203,16 @@ public class ClassifierItemBusinessService {
return classifierItemMapper.toDomainDto(classifierItemEntity);
}
public List<ClassifierItemDto> getList(
@Valid @ValidClassifierSearchFilter ClassifierItemSearchFilterDto search) {
public List<ClassifierItemDto> getList(@Valid @ValidClassifierSearchFilter ClassifierItemSearchFilterDto search) {
List<ClassifierItemEntity> classifierItems = classifierItemDataService.getFilteredClassifierItems(search);
return classifierItemMapper.toDtoList(classifierItems);
}
public List<ClassifierItem> getListByDefinition(@NotBlank String definitionId) {
List<ClassifierItemEntity> classifierItems = classifierItemDataService.getCurrentClassifierItemsByDefinitionId(definitionId);
return classifierItemMapper.toDomainList(classifierItems);
}
public ClassifierItemDto geByDefinitionAndCode(String classifierDefinitionId, String code) {
ClassifierItemEntity classifierItemEntity = classifierItemDataService.getClassifierItemByDefinitionAndCode(
classifierDefinitionId, code);
......
......@@ -10,6 +10,7 @@ import ee.sm.ti.teis.configuration.QueueList;
import ee.sm.ti.teis.configuration.TeisQueue;
import ee.sm.ti.teis.domain.ClassifierDefinition;
import ee.sm.ti.teis.domain.ClassifierItem;
import ee.sm.ti.teis.domain.ClassifierItemsByDefinition;
import ee.sm.ti.teis.domainrequest.DomainQueryDTO;
import ee.sm.ti.teis.domainrequest.DomainRequestDTO;
import ee.sm.ti.teis.servicecommon.util.TestDataImportService;
......@@ -22,6 +23,7 @@ public class QueueConfig implements QueueList {
public static final String GW_CLASSIFIER_DEFINITION_DEFAULT_VALUE_QUEUE = "classifier-service.gw.classifierDefinitionDefaultValueRequests";
public static final String MS_CLASSIFIER_ITEM_QUEUE = "classifier-service.ms.classifierItemRequests";
public static final String MS_CLASSIFIER_ITEMS_QUEUE = "classifier-service.ms.classifierItemsRequests";
public static final String MS_CLASSIFIER_ITEMS_BY_DEFINITION_QUEUE = "classifier-service.ms.classifierItemsByDefinitionRequests";
public static final String MS_CLASSIFIER_DEFINITION_QUEUE = "classifier-service.ms.classifierDefinitionRequests";
public static final String CS_CLASSIFIER_ITEM_QUEUE = "classifier-service.cs.classifierItemsCacheRequests";
public static final String CS_CLASSIFIER_DEFINITION_QUEUE = "classifier-service.cs.classifierDefinitionsCacheRequests";
......@@ -33,6 +35,7 @@ public class QueueConfig implements QueueList {
addGwQueue(queues, "gwClassifierItemsQueue", ClassifierItemsRequest.ROUTING_KEY, GW_CLASSIFIER_ITEMS_QUEUE);
addMsQueue(queues, "msClassifierItemsQueue", new ClassifierItemsDomainRequest().routingKey(), MS_CLASSIFIER_ITEMS_QUEUE);
addMsQueue(queues, "msClassifierItemsByDefinitionQueue", new ClassifierItemsByDefinitionDomainRequest().routingKey(), MS_CLASSIFIER_ITEMS_BY_DEFINITION_QUEUE);
addGwQueue(queues, "gwClassifierItemQueue", ClassifierItemRequest.ROUTING_KEY, GW_CLASSIFIER_ITEM_QUEUE);
addMsQueue(queues, "msClassifierItemQueue", new ClassifierItemDomainRequest().routingKey(), MS_CLASSIFIER_ITEM_QUEUE);
addGwQueue(queues, "gwClassifierDefinitionDefaultValueQueue", ClassifierDefinitionRequest.ROUTING_KEY, GW_CLASSIFIER_DEFINITION_DEFAULT_VALUE_QUEUE);
......@@ -53,6 +56,9 @@ public class QueueConfig implements QueueList {
public static class ClassifierItemsDomainRequest extends DomainQueryDTO<ClassifierItem, ErrorDTO> {
}
public static class ClassifierItemsByDefinitionDomainRequest extends DomainQueryDTO<ClassifierItemsByDefinition, ErrorDTO> {
}
public static class ClassifierDefinitionDomainRequest extends DomainRequestDTO<ClassifierDefinition, ErrorDTO> {
}
}
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