Commit cbe3c86f authored by Hando Lukats's avatar Hando Lukats
Browse files

Merge branch 'TEIS-219' of...

Merge branch 'TEIS-219' of https://gitlab.sotsiaalministeerium.ee/teis/proceedings-service into TEIS-222

# Conflicts:
#	service/src/main/java/ee/sm/ti/teis/proceedings/official/user/OfficialUserCacheRepository.java
#	service/src/main/resources/import.sql
parent 490f30d5
......@@ -90,9 +90,19 @@ allprojects {
compile "ee.sm.ti.teis:office-api-gateway-lib:${officeApiGatewayVersion}"
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:domain-request-lib:${commonsVersion}"
compile("com.querydsl:querydsl-core:${querydslVersion}")
compile("com.querydsl:querydsl-jpa:${querydslVersion}")
// Annotation processors
annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
annotationProcessor (
"org.mapstruct:mapstruct-processor:${mapstructVersion}",
"com.querydsl:querydsl-apt:${querydslVersion}:jpa",
"org.hibernate.javax.persistence:hibernate-jpa-2.1-api:1.0.2.Final",
"javax.annotation:javax.annotation-api:1.3.2",
"org.projectlombok:lombok:${lombokVersion}"
)
// Tests
testAnnotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
testImplementation "org.junit.jupiter:junit-jupiter:${junitVersion}"
......
theGroup=ee.sm.ti.teis
theVersion=0.1.0-SNAPSHOT
commonsVersion=0.12.0-SNAPSHOT
commonsVersion=0.12.2-SNAPSHOT
officeApiGatewayVersion=0.1.14-SNAPSHOT
pluginVersion=0.0.10-SNAPSHOT
mapstructVersion=1.3.0.Final
lombokVersion=1.18.2
junitVersion=5.4.2
querydslVersion=4.1.3
package ee.sm.ti.teis.officials;
import ee.sm.ti.teis.OfficialsServiceApp;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.util.TestPropertyValues;
......
/*
* This Java source file was generated by the Gradle 'init' task.
*/
package ee.sm.ti.teis.officials;
package ee.sm.ti.teis;
import ee.sm.ti.teis.aspects.RabbitListenerAspect;
import ee.sm.ti.teis.configuration.ExchangeConfig;
......
......@@ -59,7 +59,7 @@ public class QueueConfig extends QueueList {
public static class OfficialUsersDomainRequest extends DomainQueryDTO<OfficialUser, ErrorDTO> {
}
public static class CreateOfficialUserDomainRequest extends DomainCreateDTO<OfficialUser, ErrorDTO> {
}
......
......@@ -2,13 +2,14 @@ package ee.sm.ti.teis.officials.group;
import ee.sm.ti.teis.domain.enums.ObjectStatus;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface OfficialsGroupRepository extends CrudRepository<OfficialsGroupEntity, UUID> {
public interface OfficialsGroupRepository extends CrudRepository<OfficialsGroupEntity, UUID>, QuerydslPredicateExecutor<OfficialsGroupEntity> {
List<OfficialsGroupEntity> findByObjectStatus(ObjectStatus status);
......
@QueryEntities({AuditedEntity.class})
package ee.sm.ti.teis.officials.group;
import com.querydsl.core.annotations.QueryEntities;
import ee.sm.ti.teis.servicecommon.common.AuditedEntity;
......@@ -17,6 +17,7 @@ public interface OfficalUserMapper {
OfficialUserDto toDto(OfficialUserEntity entity);
@Mapping(target = "officialsGroupId", source = "officialsGroup.id")
OfficialUser toDomainDto(OfficialUserEntity entity);
}
package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.officegateway.official.CreateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.CreateOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.DeleteOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.OfficialUserDto;
import ee.sm.ti.teis.officegateway.official.OfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.OfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.OfficialUsersRequest;
import ee.sm.ti.teis.officegateway.official.OfficialUsersResponse;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialUserRequest;
import ee.sm.ti.teis.officegateway.official.UpdateOfficialUserResponse;
import ee.sm.ti.teis.officegateway.official.*;
import ee.sm.ti.teis.officials.config.QueueConfig;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
......@@ -47,7 +37,7 @@ public class OfficialGwListener {
@RabbitListener(queues = {QueueConfig.GW_OFFICIAL_USERS_QUEUE})
public OfficialUsersResponse findOfficialUsers(OfficialUsersRequest request) {
UUID groupId = request.getPayload().getGroupId() == null ? null : UUID.fromString(request.getPayload().getGroupId());
List<OfficialUserEntity> entityList = service.findUsers(request.getPayload().getIdCode(), groupId);
List<OfficialUserEntity> entityList = service.findUsers(request.getPayload().getIdCode(), groupId, false);
OfficialUsersResponse response = new OfficialUsersResponse();
response.setPayload(service.composeDtoFromEntityList(entityList), request.getRequestMetaDTO());
return response;
......
......@@ -21,12 +21,14 @@ public class OfficialMsListener {
@RabbitListener(queues = {QueueConfig.MS_OFFICIAL_USERS_QUEUE})
public OfficialUsersMsResponse findOfficialUsers(QueueConfig.OfficialUsersDomainRequest request) {
List<OfficialUserEntity> entityList = service.findUsers(request.getPayload().getIdCode(), null);
OfficialUser officialUser = request.getPayload();
List<OfficialUserEntity> entityList = service.findUsers(officialUser.getIdCode(), officialUser.getOfficialsGroupId(), officialUser.isOfficialsGroupManager());
OfficialUsersMsResponse response = new OfficialUsersMsResponse();
response.setPayload(service.composeDomainDtoFromEntityList(entityList), request.getRequestMetaDTO());
return response;
}
@RabbitListener(queues = {QueueConfig.MS_OFFICIAL_USER_QUEUE})
public OfficialUserMsResponse findOfficialUser(QueueConfig.OfficialUserDomainRequest request) {
OfficialUserEntity entity = service.findUserById(request.getPayload().getId());
......@@ -61,6 +63,7 @@ public class OfficialMsListener {
public static class OfficialUserMsResponse extends DomainResponseDTO<OfficialUser, ErrorDTO> {
}
public static class DeleteOfficialUserMsResponse extends DomainResponseDTO<OfficialUser, ErrorDTO> {
}
......
package ee.sm.ti.teis.officials.official;
import com.querydsl.core.BooleanBuilder;
import ee.sm.ti.teis.domain.enums.ObjectStatus;
import ee.sm.ti.teis.domain.officials.OfficialUser;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
......@@ -67,15 +68,20 @@ public class OfficialService {
return repository.findById(id).orElseThrow(() -> new TeisResourceNotFoundException("Official user not found.", List.of(id)));
}
List<OfficialUserEntity> findUsers(String idCode, UUID groupId) {
if (isNotBlank(idCode) && groupId != null) {
return repository.findByIdCodeAndOfficialsGroupIdAndObjectStatus(idCode, groupId, ObjectStatus.CURRENT);
} else if (isNotBlank(idCode)) {
return repository.findByIdCodeAndObjectStatus(idCode, ObjectStatus.CURRENT);
} else if (groupId != null) {
return repository.findByOfficialsGroupIdAndObjectStatus(groupId, ObjectStatus.CURRENT);
List<OfficialUserEntity> findUsers(String idCode, UUID groupId, Boolean isGroupManager) {
BooleanBuilder where = new BooleanBuilder();
QOfficialUserEntity officialUserEntity = QOfficialUserEntity.officialUserEntity;
where.and(officialUserEntity.objectStatus.eq(ObjectStatus.CURRENT));
if (isNotBlank(idCode)) {
where.and(officialUserEntity.idCode.eq(idCode));
}
return repository.findByObjectStatus(ObjectStatus.CURRENT);
if (groupId != null) {
where.and(officialUserEntity.officialsGroup.id.eq(groupId));
}
if (isGroupManager) {
where.and(officialUserEntity.officialsGroupManager.eq(isGroupManager));
}
return (List<OfficialUserEntity>) repository.findAll(where);
}
List<OfficialUserDto> composeDtoFromEntityList(List<OfficialUserEntity> entityList) {
......
package ee.sm.ti.teis.officials.official;
import ee.sm.ti.teis.domain.enums.ObjectStatus;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface OfficialUserRepository extends CrudRepository<OfficialUserEntity, UUID> {
public interface OfficialUserRepository extends CrudRepository<OfficialUserEntity, UUID>, QuerydslPredicateExecutor<OfficialUserEntity> {
OfficialUserEntity findByIdCode(String idCode);
......
@QueryEntities({AuditedEntity.class})
package ee.sm.ti.teis.officials.official;
import com.querydsl.core.annotations.QueryEntities;
import ee.sm.ti.teis.servicecommon.common.AuditedEntity;
package ee.sm.ti.teis.officials.official;
import com.querydsl.core.BooleanBuilder;
import ee.sm.ti.teis.exceptions.TeisResourceNotFoundException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
......@@ -7,17 +8,12 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.*;
@ExtendWith(MockitoExtension.class)
class OfficialServiceTest {
......@@ -41,30 +37,30 @@ class OfficialServiceTest {
@Test
void findUsers_should_return_all_users_if_no_ids() {
officialService.findUsers(null, null);
officialService.findUsers(null, null, false);
verify(repository, times(1)).findByObjectStatus(any());
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
}
@Test
void findUsers_should_search_by_user_idCode() {
officialService.findUsers("id", null);
officialService.findUsers("id", null, false);
verify(repository, times(1)).findByIdCodeAndObjectStatus(any(), any());
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
}
@Test
void findUsers_should_search_by_groupId() {
officialService.findUsers(null, UUID.randomUUID());
officialService.findUsers(null, UUID.randomUUID(), false);
verify(repository, times(1)).findByOfficialsGroupIdAndObjectStatus(any(), any());
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
}
@Test
void findUsers_should_return_user_with_idCode_and_in_group_if_both_ids_are_present() {
officialService.findUsers("111", UUID.randomUUID());
officialService.findUsers("111", UUID.randomUUID(), false);
verify(repository, times(1)).findByIdCodeAndOfficialsGroupIdAndObjectStatus(any(), any(), any());
verify(repository, times(1)).findAll(any(BooleanBuilder.class));
}
}
Supports Markdown
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