Search in sources :

Example 66 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method testPreventToRemoveRoles.

/**
 * Prevent to remove automatic roles assigned by contract position, when contract primary position is changed.
 */
@Test
public void testPreventToRemoveRoles() {
    IdmRoleDto roleOne = getHelper().createRole();
    IdmTreeNodeDto treeNodeOne = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRoleOne = getHelper().createAutomaticRole(roleOne, treeNodeOne);
    // 
    IdmRoleDto roleTwo = getHelper().createRole();
    IdmTreeNodeDto treeNodeTwo = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRoleTwo = getHelper().createAutomaticRole(roleTwo, treeNodeTwo);
    // 
    // create identity
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    // 
    // empty roles
    IdmIdentityRoleFilter filter = new IdmIdentityRoleFilter();
    filter.setIdentityId(identity.getId());
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertTrue(assignedRoles.isEmpty());
    // 
    // create contract positon
    IdmContractPositionDto contractPosition = getHelper().createContractPosition(contract, treeNodeOne);
    assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
    // 
    // update contract
    contract.setWorkPosition(treeNodeTwo.getId());
    contract = contractService.save(contract);
    // 
    assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(2, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
    // 
    // clear prime contract position
    contract.setWorkPosition(null);
    contract = contractService.save(contract);
    // 
    assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleOne.getId())));
    // 
    contract.setWorkPosition(treeNodeTwo.getId());
    contract = contractService.save(contract);
    // 
    // remove contract
    service.delete(contractPosition);
    // 
    assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertTrue(assignedRoles.stream().anyMatch(ir -> ir.getAutomaticRole().equals(automaticRoleTwo.getId())));
    // 
    // remove contract position
    contractService.delete(contract);
    // 
    assignedRoles = identityRoleService.find(filter, null).getContent();
    Assert.assertTrue(assignedRoles.isEmpty());
}
Also used : Lists(org.testng.collections.Lists) IdmRoleTreeNodeService(eu.bcvsolutions.idm.core.api.service.IdmRoleTreeNodeService) ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmContractPositionFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmContractPositionFilter) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) Before(org.junit.Before) IdmIdentityRoleService(eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService) RecursionType(eu.bcvsolutions.idm.core.api.domain.RecursionType) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityContractService(eu.bcvsolutions.idm.core.api.service.IdmIdentityContractService) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) ContractState(eu.bcvsolutions.idm.core.api.domain.ContractState) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) ApplicationContext(org.springframework.context.ApplicationContext) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) List(java.util.List) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(java.time.LocalDate) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) Transactional(org.springframework.transaction.annotation.Transactional) IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityRoleFilter) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 67 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method testChangeContractValidityWithAssignedRoles.

@Test
@Transactional
public void testChangeContractValidityWithAssignedRoles() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
    // other
    getHelper().createContractPosition(contract, getHelper().createTreeNode());
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
    Assert.assertNull(assignedRoles.get(0).getValidTill());
    // 
    contract.setValidTill(LocalDate.now().plusDays(2));
    contract = contractService.save(contract);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(contract.getValidTill(), assignedRoles.get(0).getValidTill());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 68 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method testDontRemoveSameRole.

@Test
@Transactional
public void testDontRemoveSameRole() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
    // other
    getHelper().createContractPosition(contract, getHelper().createTreeNode());
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
    IdmIdentityRoleDto assignedRole = assignedRoles.get(0);
    // 
    IdmTreeNodeDto treeNodeOther = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRoleOther = getHelper().createAutomaticRole(role, treeNodeOther);
    // 
    // change position
    position.setWorkPosition(treeNodeOther.getId());
    position = service.save(position);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRoleOther.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
    Assert.assertEquals(assignedRole.getId(), assignedRoles.get(0).getId());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method saveAutomaticRole.

private IdmRoleTreeNodeDto saveAutomaticRole(IdmRoleTreeNodeDto automaticRole, boolean withLongRunningTask) {
    // default name
    automaticRole.setName("default");
    IdmRoleTreeNodeDto roleTreeNode = roleTreeNodeService.saveInternal(automaticRole);
    // 
    if (withLongRunningTask) {
        ProcessAutomaticRoleByTreeTaskExecutor task = new ProcessAutomaticRoleByTreeTaskExecutor();
        task.setAutomaticRoles(Lists.newArrayList(roleTreeNode.getId()));
        taskManager.executeSync(task);
    }
    // 
    return roleTreeNodeService.get(roleTreeNode.getId());
}
Also used : ProcessAutomaticRoleByTreeTaskExecutor(eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)

Example 70 with IdmRoleTreeNodeDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmContractPositionServiceIntegrationTest method testDeleteAutomaticRoleWithContractAlreadyExists.

@Test
public void testDeleteAutomaticRoleWithContractAlreadyExists() {
    IdmRoleDto role = getHelper().createRole();
    IdmTreeNodeDto treeNode = getHelper().createTreeNode();
    IdmRoleTreeNodeDto automaticRole = getHelper().createAutomaticRole(role, treeNode);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    IdmContractPositionDto position = getHelper().createContractPosition(contract, treeNode);
    // other
    getHelper().createContractPosition(contract, getHelper().createTreeNode());
    // 
    List<IdmIdentityRoleDto> assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertEquals(1, assignedRoles.size());
    Assert.assertEquals(automaticRole.getId(), assignedRoles.get(0).getAutomaticRole());
    Assert.assertEquals(position.getId(), assignedRoles.get(0).getContractPosition());
    // 
    // delete definition
    roleTreeNodeService.delete(automaticRole);
    // 
    assignedRoles = identityRoleService.findAllByIdentity(identity.getId());
    Assert.assertTrue(assignedRoles.isEmpty());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmContractPositionDto(eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)83 Test (org.junit.Test)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)48 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)46 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)42 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)39 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)38 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)38 UUID (java.util.UUID)32 Autowired (org.springframework.beans.factory.annotation.Autowired)20 IdmContractPositionDto (eu.bcvsolutions.idm.core.api.dto.IdmContractPositionDto)19 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)19 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)19 List (java.util.List)19 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)18 ProcessAutomaticRoleByTreeTaskExecutor (eu.bcvsolutions.idm.core.scheduler.task.impl.ProcessAutomaticRoleByTreeTaskExecutor)18 OperationState (eu.bcvsolutions.idm.core.api.domain.OperationState)17 Transactional (org.springframework.transaction.annotation.Transactional)17 IdmIdentityRoleService (eu.bcvsolutions.idm.core.api.service.IdmIdentityRoleService)16 Assert (org.junit.Assert)16