Commit bf470433 authored by Enriko Käsper's avatar Enriko Käsper

Merge branch 'develop' into 'master'

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

See merge request teis/officials-service!33
parents 61855675 cf87c820
theGroup=ee.sm.ti.teis
theVersion=1.0.0
commonsVersion=1.1.0
officeApiGatewayVersion=1.0.0
theVersion=1.1.0
commonsVersion=1.3.0
officeApiGatewayVersion=1.3.0
pluginVersion=1.0.0
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
......@@ -26,6 +26,10 @@ class OfficialsMsListenerTest extends OfficialsAppTestBase {
private static final String DELETED_USER_IDCODE = "48606111928";
private static final String ACTIVE_USER_IDCODE = "38909120274";
private static final RequestMetaDTO REQUEST_META_DTO = RequestMetaDTO.builder().requestId(UUID.randomUUID().toString()).build();
private static final String ORDER_GROUP_ID = "88b1aa9c-5326-4683-bdd5-020fd1cd2148";
private static final String ORDER_USER_FIRST_ID = "9b346fe1-84a7-42d4-8658-00d155c88bc3";
private static final String ORDER_USER_SECOND_ID = "50d9b9a6-93d9-469b-9d53-7063a7467d7f";
private static final String ORDER_USER_THIRD_ID = "398791ea-2a12-4329-9969-ad7e0a71c4e9";
@Autowired
OfficialMsListener officialListener;
......@@ -82,6 +86,16 @@ class OfficialsMsListenerTest extends OfficialsAppTestBase {
assertThat(response.getPayload().get(0).getIdCode()).isEqualTo(ACTIVE_USER_IDCODE);
}
@Test
void findOfficialUsers_ordered_by_firstName_and_lastName() {
OfficialMsListener.OfficialUsersMsResponse response = officialListener.findOfficialUsers(composeOfficialUsersByGroupIdRequest(ORDER_GROUP_ID));
assertThat(response.getPayload()).isNotEmpty();
assertThat(response.getPayload().get(0).getId()).isEqualTo(UUID.fromString(ORDER_USER_FIRST_ID));
assertThat(response.getPayload().get(1).getId()).isEqualTo(UUID.fromString(ORDER_USER_SECOND_ID));
assertThat(response.getPayload().get(2).getId()).isEqualTo(UUID.fromString(ORDER_USER_THIRD_ID));
}
@Test
void deleteOfficialUser_test() {
UUID userId = UUID.fromString("e24fa6e8-777e-4262-bd9e-fca35252122d");
......@@ -150,6 +164,14 @@ class OfficialsMsListenerTest extends OfficialsAppTestBase {
return request;
}
@NotNull
private QueueConfig.OfficialUsersDomainRequest composeOfficialUsersByGroupIdRequest(String officialsGroupId) {
QueueConfig.OfficialUsersDomainRequest request = new QueueConfig.OfficialUsersDomainRequest();
OfficialUser user = OfficialUser.builder().officialsGroupId(UUID.fromString(officialsGroupId)).build();
request.setPayload(user, REQUEST_META_DTO);
return request;
}
@NotNull
private QueueConfig.DeleteOfficialUserDomainRequest composeDeleteRequest(String userId) {
QueueConfig.DeleteOfficialUserDomainRequest request = new QueueConfig.DeleteOfficialUserDomainRequest();
......
......@@ -14,5 +14,7 @@ VALUES
insert into official_user (id, id_code, first_name, last_name, officials_group_id, object_status)
VALUES
('50d9b9a6-93d9-469b-9d53-7063a7467d7f', '38909120274', 'Esimene', 'Test-manager-1', '88b1aa9c-5326-4683-bdd5-020fd1cd2148', 'CURRENT'),
('e24fa6e8-777e-4262-bd9e-fca35252122d', '38909120282', 'Teine', 'Test-manager-2', '0503dab2-46c3-4d75-9b70-20296736bf3a', 'CURRENT');
('50d9b9a6-93d9-469b-9d53-7063a7467d7f', '38909120274', 'Esimene', 'TeST-manager-1', '88b1aa9c-5326-4683-bdd5-020fd1cd2148', 'CURRENT'),
('e24fa6e8-777e-4262-bd9e-fca35252122d', '38909120282', 'Teine', 'Test-manager-2', '0503dab2-46c3-4d75-9b70-20296736bf3a', 'CURRENT'),
('398791ea-2a12-4329-9969-ad7e0a71c4e9', '48909120275', 'Teine', 'Test-kasutaja-2', '88b1aa9c-5326-4683-bdd5-020fd1cd2148', 'CURRENT'),
('9b346fe1-84a7-42d4-8658-00d155c88bc3', '38909120296', 'Esimene', 'Test-kasutaja-1', '88b1aa9c-5326-4683-bdd5-020fd1cd2148', 'CURRENT');
package ee.sm.ti.teis.officials.official;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.exceptions.TeisIllegalArgumentException;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
......@@ -119,7 +121,9 @@ public class OfficialService {
if (groupId != null) {
where.and(officialUserEntity.officialsGroup.id.eq(groupId));
}
return (List<OfficialUserEntity>) repository.findAll(where);
OrderSpecifier<?> orderSpecFirstName = new OrderSpecifier<>(Order.ASC, officialUserEntity.firstName.toUpperCase());
OrderSpecifier<?> orderSpecLastName = new OrderSpecifier<>(Order.ASC, officialUserEntity.lastName.toUpperCase());
return (List<OfficialUserEntity>) repository.findAll(where, orderSpecFirstName, orderSpecLastName);
}
List<OfficialUserDto> composeDtoFromEntityList(List<OfficialUserEntity> entityList) {
......
......@@ -72,4 +72,5 @@ teis:
ms-exchange-name: ms_exchange
ms-exchange-reply-timeout: ${RABBIT_TEMPLATE_MS_EXCHANGE_REPLY_TIMEOUT:5000}
cs-exchange-name: cache_exchange
od-exchange-name: od-disabled
cache: classifierItems, classifierDefinitions
......@@ -70,3 +70,7 @@ ALTER TABLE officials_group_emtak
REFERENCES officials_group (id)
ON UPDATE NO ACTION
ON DELETE NO ACTION;
--changeset kristel:2020-04-22.create_indexes_for_searching_officials
CREATE index official_user_first_name_upper_idx ON official_user (UPPER(first_name));
CREATE index official_user_last_name_upper_idx ON official_user (UPPER(last_name));
package ee.sm.ti.teis.officials.official;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.types.OrderSpecifier;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -39,28 +40,28 @@ class OfficialServiceTest {
void findUsers_should_return_all_users_if_no_ids() {
officialService.findUsers(null, null, null);
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
verify(repository, times(1)).findAll(any(BooleanBuilder.class), any(OrderSpecifier.class), any(OrderSpecifier.class));
}
@Test
void findUsers_should_search_by_user_idCode() {
officialService.findUsers("id", null, null);
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
verify(repository, times(1)).findAll(any(BooleanBuilder.class), any(OrderSpecifier.class), any(OrderSpecifier.class));
}
@Test
void findUsers_should_search_by_groupId() {
officialService.findUsers(null, UUID.randomUUID(), null);
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
verify(repository, times(1)).findAll(any(BooleanBuilder.class), any(OrderSpecifier.class), any(OrderSpecifier.class));
}
@Test
void findUsers_should_return_user_with_idCode_and_in_group_if_both_ids_are_present() {
officialService.findUsers("111", UUID.randomUUID(), null);
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
verify(repository, times(1)).findAll(any(BooleanBuilder.class), any(OrderSpecifier.class), any(OrderSpecifier.class));
}
}
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