Commit 9ce4c7e6 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/officials-service!61
parents af241f06 70c9c0d9
# Changelog
## [1.12.0] - 2021-09-27
* Added OfficeService to take use of database cached offices; refactored code (moved office related cache classes to separate office package)
* TEIS-2202: updated OfficialUser deletion: official in sequence is deleted and officialSequence lastSelectedOfficialId is removed
* TEIS-2198: new logic patching official in sequence, created separate folder for official in sequence files
* TEIS-2197: new logic for deleting official in sequence
* TEIS-2196: new logic for getting one OfficialsSequence
* TEIS-2195: new logic for getting officialsSequences
## [1.11.0] - 2021-06-14
* TEIS-2199: refactored Response classes from listeners to QueueConfig. new ms endpoint for getting official from sequence. new listener for testing getting officials from sequence
......
theGroup=ee.sm.ti.teis
theVersion=1.11.0
commonsVersion=1.26.0
officeApiGatewayVersion=1.26.0
theVersion=1.12.0
commonsVersion=1.27.0
officeApiGatewayVersion=1.27.0
pluginVersion=1.3.0
......@@ -8,6 +8,10 @@ import ee.sm.ti.teis.officegateway.official.response.*;
import ee.sm.ti.teis.officials.group.OfficialsGroupRepository;
import ee.sm.ti.teis.officials.official.OfficialUserEntity;
import ee.sm.ti.teis.officials.official.OfficialUserRepository;
import ee.sm.ti.teis.officials.officialinsequence.OfficialInSequenceEntity;
import ee.sm.ti.teis.officials.officialinsequence.OfficialInSequenceRepository;
import ee.sm.ti.teis.officials.officialssequence.OfficialsSequenceEntity;
import ee.sm.ti.teis.officials.officialssequence.OfficialsSequenceRepository;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import ee.sm.ti.teis.servicerequest.UserType;
import org.jetbrains.annotations.NotNull;
......@@ -15,6 +19,7 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.transaction.Transactional;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
......@@ -44,6 +49,10 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
OfficialsGroupRepository repository;
@Autowired
OfficialUserRepository officialUserRepository;
@Autowired
OfficialInSequenceRepository officialInSequenceRepository;
@Autowired
OfficialsSequenceRepository officialsSequenceRepository;
@Test
void createOfficialUser_test() {
......@@ -130,6 +139,15 @@ class OfficialsListenerTest extends OfficialsAppTestBase {
.orElse(new OfficialUserEntity());
assertThat(deletedOfficialUser.getObjectStatus()).isEqualTo(DELETED);
List<OfficialInSequenceEntity> officialInSequenceEntities = officialInSequenceRepository.findByOfficialUserId(ADMIN_USER_ID);
assertThat(officialInSequenceEntities.stream().allMatch(e -> e.getObjectStatus() == DELETED)).isTrue();
List<OfficialsSequenceEntity> officialsSequenceEntities = officialsSequenceRepository.findByLastSelectedOfficialId(ADMIN_USER_ID);
assertThat(officialsSequenceEntities.stream().allMatch(e -> e.getLastSelectedOfficialId() == null)).isTrue();
OfficialsSequenceEntity officialsSequenceEntity = officialsSequenceRepository.findById(UUID.fromString("4b60bfe3-83a5-4ba0-9495-22beb9f4abbf")).orElse(null);
assertThat(officialsSequenceEntity.getLastSelectedOfficialId().equals(UUID.fromString("3dac227f-a8af-4771-8d8b-01409ac7fef0"))).isTrue();
}
@Test
......
package ee.sm.ti.teis.officials.officialinsequence;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.request.DeleteOfficialInSequenceRequest;
import ee.sm.ti.teis.officegateway.official.response.DeleteOfficialInSequenceResponse;
import ee.sm.ti.teis.officials.officialinsequence.listener.OfficialInSequenceGwListener;
import ee.sm.ti.teis.officials.officialinsequence.service.OfficialInSequenceDataService;
import ee.sm.ti.teis.officials.officialssequence.OfficialsSequenceEntity;
import ee.sm.ti.teis.officials.officialssequence.service.OfficialsSequenceDataService;
import ee.sm.ti.teis.servicecommon.test.ListenerDeleteRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_OFFICIALS_SEQUENCES;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
class DeleteOfficialInSequenceGwListenerTest extends OfficialsAppTestBase implements ListenerDeleteRequestTestBase {
public static final UUID CURRENT_OFFICIAL_IN_SEQUENCE_ID_1 = UUID.fromString("ef7182c6-6036-4e0d-aba5-56dd78e45ee2");
public static final UUID CURRENT_OFFICIAL_IN_SEQUENCE_ID_2 = UUID.fromString("c6125977-5c82-4068-adf4-5e9d6158ea15");
public static final UUID OFFICIAL_IN_SEQUENCE_ID_DELETED_SEQUENCE = UUID.fromString("d1348a8b-1258-40f8-8c13-6089e1b9bfb1");
public static final UUID DELETED_OFFICIAL_IN_SEQUENCE_ID = UUID.fromString("8b004a26-4c5e-455c-8cdc-ee775583c13c");
DeleteOfficialInSequenceRequest request;
RequestMetaDTO requestMetaDTO;
@Autowired
private OfficialInSequenceGwListener listener;
@Autowired
private OfficialInSequenceDataService dataService;
@Autowired
private OfficialsSequenceDataService officialsSequenceDataService;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_OFFICIALS_SEQUENCES.name()));
request = new DeleteOfficialInSequenceRequest();
request.setPayload(null, requestMetaDTO);
}
@Override
@Test
public void delete_idNotExists_notFound() {
request.setPayload(randomUUID(), requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertResponseNotFound(response.getError());
}
@Test
public void delete_idMissing_badRequest() {
request.setPayload(null, requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertBadRequest(response.getError());
}
@Override
@Test
public void delete_objectStatusDeleted_success() {
request.setPayload(DELETED_OFFICIAL_IN_SEQUENCE_ID, requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertThat(response.getError()).isNull();
OfficialInSequenceEntity officialInSequence = dataService.getById(DELETED_OFFICIAL_IN_SEQUENCE_ID);
OfficialsSequenceEntity sequence = officialsSequenceDataService.getById(officialInSequence.getOfficialsSequenceId());
assertThat(officialInSequence.getObjectStatus()).isEqualTo(DELETED);
assertThat(sequence.getLastSelectedOfficialId()).isNull();
}
@Test
public void delete_sequenceDeleted_success() {
request.setPayload(OFFICIAL_IN_SEQUENCE_ID_DELETED_SEQUENCE, requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertThat(response.getError()).isNull();
OfficialInSequenceEntity officialInSequence = dataService.getById(OFFICIAL_IN_SEQUENCE_ID_DELETED_SEQUENCE);
OfficialsSequenceEntity sequence = officialsSequenceDataService.getById(officialInSequence.getOfficialsSequenceId());
assertThat(officialInSequence.getObjectStatus()).isEqualTo(DELETED);
assertThat(sequence.getLastSelectedOfficialId()).isNull();
}
@Override
@Test
public void delete_verifyObjectStatusDeletedInDatabase_success() {
request.setPayload(CURRENT_OFFICIAL_IN_SEQUENCE_ID_1, requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertThat(response.getError()).isNull();
OfficialInSequenceEntity officialInSequence = dataService.getById(CURRENT_OFFICIAL_IN_SEQUENCE_ID_1);
OfficialsSequenceEntity sequence = officialsSequenceDataService.getById(officialInSequence.getOfficialsSequenceId());
assertThat(officialInSequence.getObjectStatus()).isEqualTo(DELETED);
assertThat(sequence.getLastSelectedOfficialId()).isNull();
}
@Test
public void delete_objectStatusDeleted_lastOfficialIsNotNulled_success() {
request.setPayload(CURRENT_OFFICIAL_IN_SEQUENCE_ID_2, requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertThat(response.getError()).isNull();
OfficialInSequenceEntity officialInSequence = dataService.getById(CURRENT_OFFICIAL_IN_SEQUENCE_ID_2);
OfficialsSequenceEntity sequence = officialsSequenceDataService.getById(officialInSequence.getOfficialsSequenceId());
assertThat(officialInSequence.getObjectStatus()).isEqualTo(DELETED);
assertThat(sequence.getLastSelectedOfficialId()).isEqualTo(UUID.fromString("3dac227f-a8af-4771-8d8b-01409ac7fef0"));
}
@Override
@Test
public void missingPrivilege_forbidden() {
requestMetaDTO.setPrivileges(emptyList());
request.setPayload(randomUUID(), requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertResponseForbidden(response.getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
request.setPayload(randomUUID(), requestMetaDTO);
DeleteOfficialInSequenceResponse response = listener.delete(request);
assertResponseForbidden(response.getError());
}
}
package ee.sm.ti.teis.officials.officialinsequence;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.dto.UpdateOfficialInSequenceDto;
import ee.sm.ti.teis.officegateway.official.request.UpdateOfficialInSequenceRequest;
import ee.sm.ti.teis.officegateway.official.response.UpdateOfficialInSequenceResponse;
import ee.sm.ti.teis.officials.officialinsequence.listener.OfficialInSequenceGwListener;
import ee.sm.ti.teis.officials.officialinsequence.service.OfficialInSequenceDataService;
import ee.sm.ti.teis.servicecommon.test.ListenerUpdateRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_OFFICIALS_SEQUENCES;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
class UpdateOfficialInSequenceGwListenerTest extends OfficialsAppTestBase implements ListenerUpdateRequestTestBase {
public static final UUID ACTIVE_OFFICIAL_IN_SEQUENCE_ID_1 = UUID.fromString("3e6b12bd-1d56-4a32-aa78-7fa82568ed30");
public static final UUID ACTIVE_OFFICIAL_IN_SEQUENCE_ID_2 = UUID.fromString("724bcfca-cb71-4a9c-ae94-c111a4565610");
public static final UUID INACTIVE_OFFICIAL_IN_SEQUENCE_ID = UUID.fromString("c080f99e-4f82-4f4b-a414-270e4341a82c");
public static final UUID DELETED_OFFICIAL_IN_SEQUENCE_ID = UUID.fromString("4ce470d6-c23d-4277-819f-07f117307486");
UpdateOfficialInSequenceRequest request;
RequestMetaDTO requestMetaDTO;
@Autowired
private OfficialInSequenceGwListener listener;
@Autowired
private OfficialInSequenceDataService dataService;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_MANAGE_OFFICIALS_SEQUENCES.name()));
request = new UpdateOfficialInSequenceRequest();
request.setPayload(null, requestMetaDTO);
}
@Override
@Test
public void update_idNotExists_notFound() {
request.setPayload(new UpdateOfficialInSequenceDto(randomUUID(), true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertResponseNotFound(response.getError());
}
@Test
public void update_idMissing_badRequest() {
request.setPayload(new UpdateOfficialInSequenceDto(null, true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertBadRequest(response.getError());
}
@Test
public void update_activeMissing_badRequest() {
request.setPayload(new UpdateOfficialInSequenceDto(randomUUID(), null), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertBadRequest(response.getError());
}
@Override
@Test
public void update_objectStatusDeleted_notFound() {
request.setPayload(new UpdateOfficialInSequenceDto(DELETED_OFFICIAL_IN_SEQUENCE_ID, true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertResponseNotFound(response.getError());
}
@Override
@Test
public void update_minimumData_success() {
// not implemented, minimum and full are equal
}
@Override
@Test
public void update_fullData_success() {
// not implemented, implementation is in the following tests
}
@Test
@Transactional
public void update_activeToActive_success() {
request.setPayload(new UpdateOfficialInSequenceDto(ACTIVE_OFFICIAL_IN_SEQUENCE_ID_1, true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertThat(response.getPayload().getActive()).isTrue();
}
@Test
@Transactional
public void update_activeToInactive_success() {
request.setPayload(new UpdateOfficialInSequenceDto(ACTIVE_OFFICIAL_IN_SEQUENCE_ID_1, false), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertThat(response.getPayload().getActive()).isFalse();
}
@Test
@Transactional
public void update_inactiveToInactive_success() {
request.setPayload(new UpdateOfficialInSequenceDto(INACTIVE_OFFICIAL_IN_SEQUENCE_ID, false), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertThat(response.getPayload().getActive()).isFalse();
}
@Test
@Transactional
public void update_inactiveToActive_success() {
request.setPayload(new UpdateOfficialInSequenceDto(INACTIVE_OFFICIAL_IN_SEQUENCE_ID, true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertThat(response.getPayload().getActive()).isTrue();
}
@Override
@Test
public void update_verifyObjectExistsInDatabase_success() {
request.setPayload(new UpdateOfficialInSequenceDto(ACTIVE_OFFICIAL_IN_SEQUENCE_ID_2, true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertThat(response.getPayload().getActive()).isTrue();
OfficialInSequenceEntity entity = dataService.getById(ACTIVE_OFFICIAL_IN_SEQUENCE_ID_2);
assertThat(entity.getActive()).isTrue();
}
@Override
@Test
public void missingPrivilege_forbidden() {
requestMetaDTO.setPrivileges(emptyList());
request.setPayload(new UpdateOfficialInSequenceDto(randomUUID(), true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertResponseForbidden(response.getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
request.setPayload(new UpdateOfficialInSequenceDto(randomUUID(), true), requestMetaDTO);
UpdateOfficialInSequenceResponse response = listener.update(request);
assertResponseForbidden(response.getError());
}
}
package ee.sm.ti.teis.officials.officialssequence;
import ee.sm.ti.teis.OfficialsAppTestBase;
import ee.sm.ti.teis.officegateway.official.dto.OfficialUserInSequenceDetailsDto;
import ee.sm.ti.teis.officegateway.official.dto.OfficialsSequenceDetailsDto;
import ee.sm.ti.teis.officegateway.official.request.GetOfficialsSequenceRequest;
import ee.sm.ti.teis.officegateway.official.response.GetOfficialsSequenceResponse;
import ee.sm.ti.teis.officials.officialssequence.listener.OfficialsSequenceGwListener;
import ee.sm.ti.teis.servicecommon.test.ListenerGetObjectRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_VIEW_OFFICIALS_SEQUENCES;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
class OfficialsSequenceGwListenerTest extends OfficialsAppTestBase implements ListenerGetObjectRequestTestBase {
GetOfficialsSequenceRequest request;
RequestMetaDTO requestMetaDTO;
@Autowired
private OfficialsSequenceGwListener listener;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), List.of(TI_VIEW_OFFICIALS_SEQUENCES.name()));
request = new GetOfficialsSequenceRequest();
request.setPayload(null, requestMetaDTO);
}
@Override
@Test
public void getObject_idNotExists_notFound() {
request.setPayload(randomUUID(), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
assertResponseNotFound(response.getError());
}
@Test
public void getObject_idMissing_badRequest() {
request.setPayload(null, requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
assertBadRequest(response.getError());
}
@Override
@Test
public void getObject_objectStatusDeleted_success() {
request.setPayload(UUID.fromString("c5c590ef-3231-481a-8a30-7274361c016d"), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
OfficialsSequenceDetailsDto dto = OfficialsSequenceDetailsDto.builder()
.id(UUID.fromString("c5c590ef-3231-481a-8a30-7274361c016d"))
.code("testCodeDeletedSequence")
.title("testTitleForDeleted")
.lastSelectedOfficialId(null)
.officialsInSequence(List.of(
OfficialUserInSequenceDetailsDto.builder()
.id(UUID.fromString("9d647f88-81bb-429f-8052-6a19d96a3644"))
.officialUserId(UUID.fromString("3dac227f-a8af-4771-8d8b-01409ac7fef0"))
.active(false)
.idCode("38909120274")
.firstName("Esimene")
.lastName("Test-Kasutaja")
.build()))
.build();
assertThat(response.getPayload()).isEqualTo(dto);
}
@Override
@Test
public void getObject_success() {
request.setPayload(UUID.fromString("7a61faf4-d22e-40f5-ace3-c58a5b54b4d1"), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
OfficialsSequenceDetailsDto dto = OfficialsSequenceDetailsDto.builder()
.id(UUID.fromString("7a61faf4-d22e-40f5-ace3-c58a5b54b4d1"))
.code("testCode")
.title("testTitle10")
.lastSelectedOfficialId(UUID.fromString("e0ee766d-4332-450a-9d9c-9835ae663d96"))
.officialsInSequence(List.of(
OfficialUserInSequenceDetailsDto.builder()
.id(UUID.fromString("f80c6a60-278f-4a45-8fc2-a6eed7aa8cb6"))
.officialUserId(UUID.fromString("620437e0-3b57-48fc-bc40-5adcfd994638"))
.active(false)
.idCode("37802170149")
.firstName("Kolmas")
.lastName("Test-Kasutaja")
.build(),
OfficialUserInSequenceDetailsDto.builder()
.id(UUID.fromString("122eddbd-50aa-4b6c-b3c7-fadf385b3fc2"))
.officialUserId(UUID.fromString("3dac227f-a8af-4771-8d8b-01409ac7fef0"))
.active(true)
.idCode("38909120274")
.firstName("Esimene")
.lastName("Test-Kasutaja")
.build()
))
.build();
assertThat(response.getPayload()).isEqualTo(dto);
}
@Test
public void getObject_noRelatedCurrentOfficialUsers_success() {
request.setPayload(UUID.fromString("2240f456-0d7c-4e54-bec7-4e57026e8575"), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
OfficialsSequenceDetailsDto dto = OfficialsSequenceDetailsDto.builder()
.id(UUID.fromString("2240f456-0d7c-4e54-bec7-4e57026e8575"))
.code("testCode2")
.title("testTitle11")
.lastSelectedOfficialId(null)
.officialsInSequence(emptyList())
.build();
assertThat(response.getPayload()).isEqualTo(dto);
}
@Test
public void getObject_noRelatedCurrentUsers_success() {
request.setPayload(UUID.fromString("7730f0e1-89f3-48c3-99da-44fce34b607f"), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
OfficialsSequenceDetailsDto dto = OfficialsSequenceDetailsDto.builder()
.id(UUID.fromString("7730f0e1-89f3-48c3-99da-44fce34b607f"))
.code("testCode3")
.title("testTitle12")
.lastSelectedOfficialId(null)
.officialsInSequence(emptyList())
.build();
assertThat(response.getPayload()).isEqualTo(dto);
}
@Test
public void getObject_oneRelatedCurrentUser_success() {
request.setPayload(UUID.fromString("25c02b6b-2189-4736-9d61-4f9132c70dd5"), requestMetaDTO);
GetOfficialsSequenceResponse response = listener.getOfficialsSequence(request);
OfficialsSequenceDetailsDto dto = OfficialsSequenceDetailsDto.builder()
.id(UUID.fromString("25c02b6b-2189-4736-9d61-4f9132c70dd5"))
.code("testCode4")
.title("testTitle13")
.lastSelectedOfficialId(null)
.officialsInSequence(List.of(OfficialUserInSequenceDetailsDto.builder()