Commit 71af657e authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/classifiers-service!69
parents 33e8f929 7884aa6d
theGroup=ee.sm.ti.teis
theVersion=1.14.0
theVersion=1.15.0
commonsVersion=1.14.0
officeApiGatewayVersion=1.14.0
schedulerVersion=1.12.0
......
......@@ -9,9 +9,11 @@ import org.junit.jupiter.api.Test;
import javax.inject.Inject;
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.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -34,12 +36,65 @@ class ClassifierItemsMsListenerTest extends ClassifierTestBase {
ClassifierItemDomainRequest domainRequest = new ClassifierItemDomainRequest();
domainRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemsMsListener.ClassifierItemResponseMessage defaultValue =
classifierItemsMsListener.getMsClassifierItem(domainRequest);
ClassifierItemResponseMessage defaultValue = classifierItemsMsListener.getMsClassifierItem(domainRequest);
assertThat("Afganistan").isEqualTo(defaultValue.getPayload().getName());
}
@Test
void getMsClassifierItem_byIdAndLevel_success() {
ClassifierItem itemPayload = new ClassifierItem();
itemPayload.setId("INSPECTION_TOPIC__RA_OT_MOOTMINE");
itemPayload.setLevel(2);
ClassifierItemDomainRequest domainRequest = new ClassifierItemDomainRequest();
domainRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemResponseMessage response = classifierItemsMsListener.getMsClassifierItem(domainRequest);
assertThat("1.5. Ohutegurite mõõtmine").isEqualTo(response.getPayload().getName());
}
@Test
void getMsClassifierItem_byIdAndLevel_notFound() {
ClassifierItem itemPayload = new ClassifierItem();
itemPayload.setId("INSPECTION_TOPIC__RA_OT_MOOTMINE");
itemPayload.setLevel(3);
ClassifierItemDomainRequest domainRequest = new ClassifierItemDomainRequest();
domainRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemResponseMessage response = classifierItemsMsListener.getMsClassifierItem(domainRequest);
assertResponseNotFound(response.getError());
}
@Test
void getMsClassifierItem_byDefinitionIdAndCodeAndLevel_success() {
ClassifierItem itemPayload = new ClassifierItem();
itemPayload.setClassifierDefinitionId("INSPECTION_TOPIC");
itemPayload.setCode("RA_OT_MOOTMINE");
itemPayload.setLevel(2);
ClassifierItemDomainRequest domainRequest = new ClassifierItemDomainRequest();
domainRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemResponseMessage response = classifierItemsMsListener.getMsClassifierItem(domainRequest);
assertThat("1.5. Ohutegurite mõõtmine").isEqualTo(response.getPayload().getName());
}
@Test
void getMsClassifierItem_byDefinitionIdAndCodeAndLevel_notFound() {
ClassifierItem itemPayload = new ClassifierItem();
itemPayload.setClassifierDefinitionId("INSPECTION_TOPIC");
itemPayload.setCode("RA_OT_MOOTMINE");
itemPayload.setLevel(3);
ClassifierItemDomainRequest domainRequest = new ClassifierItemDomainRequest();
domainRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemResponseMessage response = classifierItemsMsListener.getMsClassifierItem(domainRequest);
assertResponseNotFound(response.getError());
}
@Test
void getMsClassifierItems_returns_items() {
ClassifierItem itemPayload = new ClassifierItem();
......@@ -47,8 +102,7 @@ class ClassifierItemsMsListenerTest extends ClassifierTestBase {
ClassifierItemsDomainRequest domainsRequest = new ClassifierItemsDomainRequest();
domainsRequest.setPayload(itemPayload, REQUEST_META_DTO);
ClassifierItemsResponseMessage defaultValue =
classifierItemsMsListener.getMsClassifierItems(domainsRequest);
ClassifierItemsResponseMessage defaultValue = classifierItemsMsListener.getMsClassifierItems(domainsRequest);
assertThat(252).isEqualTo(defaultValue.getPayload().size());
}
......
......@@ -68,6 +68,12 @@ public interface ClassifierItemRepository extends JpaRepository<ClassifierItemEn
Optional<ClassifierItemEntity> findByIdIgnoreCase(String id);
@Query("SELECT classifier " +
"FROM ClassifierItemEntity classifier " +
"WHERE lower(id) = lower(:id) and " +
"(coalesce(:level) is null or classifier.level = :level)")
Optional<ClassifierItemEntity> findByIdAndLevel(String id, Integer level);
Optional<ClassifierItemEntity> findByIdIgnoreCaseAndObjectStatus(String id, ObjectStatus objectStatus);
@Query("SELECT coalesce(max(classifier.seqNo), 0) FROM ClassifierItemEntity classifier WHERE classifier.classifierDefinition.id = :id")
......@@ -79,8 +85,8 @@ public interface ClassifierItemRepository extends JpaRepository<ClassifierItemEn
"classifier.upperClassifierItem.id = :parentId and " +
"classifier.level = :level")
Long findSeqNumberByClassifierDefinitionLevelAndUpperClassifier(@Param("definitionId") String definitionId,
@Param("parentId") String parentId,
@Param("level") Integer level);
@Param("parentId") String parentId,
@Param("level") Integer level);
@Query("SELECT COUNT(classifier) " +
"FROM ClassifierItemEntity classifier " +
......@@ -89,4 +95,12 @@ public interface ClassifierItemRepository extends JpaRepository<ClassifierItemEn
Long findSeqNumberByClassifierDefinitionAndLevel(@Param("definitionId") String definitionId, @Param("level") Integer level);
Optional<ClassifierItemEntity> findByClassifierDefinitionIdAndCodeIgnoreCaseAndObjectStatus(String classifierDefinition, String code, ObjectStatus objectStatus);
@Query("SELECT classifier " +
"FROM ClassifierItemEntity classifier " +
"WHERE classifier.classifierDefinition.id = :definitionId and " +
"lower(classifier.code) = lower(:code) and " +
"(coalesce(:level) is null or classifier.level = :level) and " +
"classifier.objectStatus = 'CURRENT'")
Optional<ClassifierItemEntity> findByClassifierDefinitionIdAndCodeAndLevel(String definitionId, String code, Integer level);
}
......@@ -2,7 +2,6 @@ package ee.sm.ti.teis.classifiers.classifier.item.listener;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.classifiers.classifier.item.service.ClassifierItemBusinessService;
import ee.sm.ti.teis.classifiers.rabbit.QueueConfig;
import ee.sm.ti.teis.commongateway.classifier.search.ClassifierItemSearchFilterDto;
import ee.sm.ti.teis.domain.ClassifierAttributeLight;
import ee.sm.ti.teis.domain.ClassifierItem;
......@@ -14,28 +13,28 @@ import org.springframework.stereotype.Component;
import java.util.List;
import static ee.sm.ti.teis.classifiers.rabbit.QueueConfig.*;
@Component
@RequiredArgsConstructor
public class ClassifierItemsMsListener {
private final ClassifierItemBusinessService classifierItemBusinessService;
@RabbitListener(queues = {QueueConfig.MS_CLASSIFIER_ITEM_QUEUE})
public ClassifierItemResponseMessage getMsClassifierItem(QueueConfig.ClassifierItemDomainRequest request) {
@RabbitListener(queues = {MS_CLASSIFIER_ITEM_QUEUE})
public ClassifierItemResponseMessage getMsClassifierItem(ClassifierItemDomainRequest request) {
ClassifierItemResponseMessage response = new ClassifierItemResponseMessage();
ClassifierItem payload = request.getPayload();
ClassifierItem classifierItem =
classifierItemBusinessService.getMsClassifiers(payload);
ClassifierItem classifierItem = classifierItemBusinessService.getMsClassifiers(payload);
response.setPayload(classifierItem, request.getRequestMetaDTO());
return response;
}
@RabbitListener(queues = {QueueConfig.MS_CLASSIFIER_ITEMS_QUEUE})
public ClassifierItemsResponseMessage getMsClassifierItems(QueueConfig.ClassifierItemsDomainRequest requestDTO) {
@RabbitListener(queues = {MS_CLASSIFIER_ITEMS_QUEUE})
public ClassifierItemsResponseMessage getMsClassifierItems(ClassifierItemsDomainRequest requestDTO) {
ClassifierItemsResponseMessage resultDTO = new ClassifierItemsResponseMessage();
ClassifierItemSearchFilterDto search = composeSearchFilterDto(requestDTO.getPayload());
List<ClassifierItem> classifierItems =
classifierItemBusinessService.getFiltered(search);
List<ClassifierItem> classifierItems = classifierItemBusinessService.getFiltered(search);
resultDTO.setPayload(classifierItems, requestDTO.getRequestMetaDTO());
return resultDTO;
}
......
......@@ -194,10 +194,10 @@ public class ClassifierItemBusinessService {
public ClassifierItem getMsClassifiers(ClassifierItem classifierItem) {
ClassifierItemEntity classifierItemEntity;
if (classifierItem.getId() != null) {
classifierItemEntity = classifierItemDataService.getById(classifierItem.getId());
classifierItemEntity = classifierItemDataService.getByIdAndLevel(classifierItem.getId(), classifierItem.getLevel());
} else {
classifierItemEntity = classifierItemDataService.getClassifierItemByDefinitionAndCode(
classifierItem.getClassifierDefinitionId(), classifierItem.getCode());
classifierItemEntity = classifierItemDataService.getByDefinitionIdAndCodeAndLevel(
classifierItem.getClassifierDefinitionId(), classifierItem.getCode(), classifierItem.getLevel());
}
return classifierItemMapper.toDomainDto(classifierItemEntity);
}
......
......@@ -96,11 +96,21 @@ public class ClassifierItemDataService {
.orElseThrow(() -> new TeisResourceNotFoundException(id));
}
public ClassifierItemEntity getByIdAndLevel(String id, Integer level) {
return classifierItemRepository.findByIdAndLevel(id, level)
.orElseThrow(() -> new TeisResourceNotFoundException(id));
}
ClassifierItemEntity getClassifierItemByDefinitionAndCode(String classifierDefinitionId, String code) {
return classifierItemRepository.findByClassifierDefinitionIdAndCodeIgnoreCaseAndObjectStatus(classifierDefinitionId, code, CURRENT)
.orElseThrow(() -> new TeisResourceNotFoundException(CLASSIFIER_ITEM_NOT_FOUND, List.of(code)));
}
ClassifierItemEntity getByDefinitionIdAndCodeAndLevel(String classifierDefinitionId, String code, Integer level) {
return classifierItemRepository.findByClassifierDefinitionIdAndCodeAndLevel(classifierDefinitionId, code, level)
.orElseThrow(() -> new TeisResourceNotFoundException(CLASSIFIER_ITEM_NOT_FOUND, List.of(code)));
}
public List<ClassifierItemEntity> getFilteredClassifierItems(ClassifierItemSearchFilterDto search) {
QClassifierItemEntity qClassifierItemEntity = QClassifierItemEntity.classifierItemEntity;
......
......@@ -7,6 +7,7 @@
DELETE FROM classifier_attribute_value WHERE value LIKE 'TEIS-TEST%' OR classifier_item_id LIKE 'TEST_%';
DELETE FROM classifier_item_link WHERE source_classifier_item_id LIKE 'TEST_%';
DELETE FROM classifier_item_link WHERE target_classifier_item_id LIKE 'TEST_%';
DELETE FROM classifier_item_link WHERE object_status = 'DELETED';
DELETE FROM classifier_item WHERE (classifier_definition_id != 'EMTAK' AND seq_no >= 10000000)
OR classifier_definition_id LIKE 'TEST_%' OR code LIKE 'PLACEHOLDER_FOR_TESTING%';
DELETE FROM classifier_item WHERE name LIKE 'TEST%';
......@@ -97,9 +98,10 @@ VALUES
('TEST_RISK_FACTOR_CATEGORY__GENERAL', 'TEST_RISK_FACTOR_CATEGORY', 'GENERAL', FALSE, 'Kõik', 'CURRENT', 100000001, null,now(),null, null),
('TEST_RISK_FACTOR_CATEGORY__ABSORB', 'TEST_RISK_FACTOR_CATEGORY', 'ABSORB', FALSE, 'Imavuse tähtis mõõdik', 'CURRENT', 100000002, null,now(),null, null),
('RISK_BUSINESS_TYPE_CATEGORY__PLACEHOLDER_FOR_TESTING', 'RISK_BUSINESS_TYPE_CATEGORY', 'PLACEHOLDER_FOR_TESTING', TRUE, 'Ajutine klassifikaator testimiseks', 'CURRENT', 100000004, null, now(), null, null),
('RISK_BUSINESS_TYPE_CATEGORY__PLACEHOLDER_FOR_TESTING2', 'RISK_BUSINESS_TYPE_CATEGORY', 'PLACEHOLDER_FOR_TESTING2', TRUE, 'Ajutine klassifikaator 2 testimiseks', 'DELETED', 100000005, null, now(), null, null),
('RISK_BUSINESS_TYPE_CATEGORY__PLACEHOLDER_FOR_TESTING2', 'RISK_BUSINESS_TYPE_CATEGORY', 'PLACEHOLDER_FOR_TESTING2', TRUE, 'Ajutine klassifikaator 2 testimiseks, deleted', 'DELETED', 100000005, null, now(), null, null),
('RISK_BUSINESS_TYPE_CATEGORY__PLACEHOLDER_FOR_TESTING3', 'RISK_BUSINESS_TYPE_CATEGORY', 'PLACEHOLDER_FOR_TESTING3', TRUE, 'Ajutine klassifikaator 3 testimiseks', 'CURRENT', 100000006, null, now(), null, null),
('RISK_FACTOR_CATEGORY__PLACEHOLDER_FOR_TESTING', 'RISK_FACTOR_CATEGORY', 'PLACEHOLDER_FOR_TESTING', FALSE, 'Placeholder for testing risk factor category', 'CURRENT', 100000005, null, now(),null,null);
('RISK_FACTOR_CATEGORY__PLACEHOLDER_FOR_TESTING', 'RISK_FACTOR_CATEGORY', 'PLACEHOLDER_FOR_TESTING', FALSE, 'Placeholder for testing risk factor category', 'CURRENT', 100000005, null, now(),null,null),
('RISK_FACTOR_CATEGORY__PLACEHOLDER_FOR_TESTING2', 'RISK_FACTOR_CATEGORY', 'PLACEHOLDER_FOR_TESTING2', FALSE, 'Placeholder for testing risk factor category, deleted', 'DELETED', 100000006, null, now(),null,null);
/*ATTRIBUTE VALUES*/
INSERT INTO classifier_attribute_value (id, object_status, classifier_item_id, classifier_attribute_definition_id, value)
......
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