Search in sources :

Example 81 with IdmIdentityContractDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDisabledContract.

@Test
public void testDisabledContract() {
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), new LocalDate().plusMonths(5));
    contract2.setState(ContractState.DISABLED);
    contract2 = identityContractService.save(contract2);
    // 
    IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusMonths(5));
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // 
    IdmIdentityContractDto contract4 = testHelper.createIdentityContact(identity, null, null, null);
    contract4.setState(ContractState.DISABLED);
    contract4 = identityContractService.save(contract4);
    // 
    IdmIdentityContractDto contract5 = testHelper.createIdentityContact(identity, null, new LocalDate().minusMonths(5), null);
    contract5.setState(ContractState.DISABLED);
    contract5 = identityContractService.save(contract5);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY, IdmIdentity_.username.getName(), null, identity.getUsername());
    // 
    this.recalculateSync(automaticRole.getId());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(0, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(0, identityRoles.size());
    // 
    contract5.setState(null);
    contract5 = identityContractService.save(contract5);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract5.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract4.setState(null);
    contract4 = identityContractService.save(contract4);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract4.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract3.setState(null);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(1, identityRoles.size());
    // 
    contract2.setState(null);
    contract2 = identityContractService.save(contract2);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract2.getId());
    assertEquals(1, identityRoles.size());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        assertEquals(automaticRole.getId(), identityRole.getRoleTreeNode());
        AbstractIdmAutomaticRoleDto embedded = DtoUtils.getEmbedded(identityRole, IdmAutomaticRoleAttributeService.ROLE_TREE_NODE_ATTRIBUTE_NAME, AbstractIdmAutomaticRoleDto.class, null);
        assertEquals(automaticRole, embedded);
        assertEquals(role.getId(), embedded.getRole());
        assertEquals(role.getId(), identityRole.getRole());
    }
    // 
    contract3.setState(ContractState.DISABLED);
    contract3 = identityContractService.save(contract3);
    // we must save identity, automatic role will be recalculate after identity save
    identity = identityService.save(identity);
    // 
    identityRoles = identityRoleService.findAllByContract(contract3.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 82 with IdmIdentityContractDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testDeletePrimariContract.

@Test
public void testDeletePrimariContract() {
    String eavCode = "testingEav";
    UUID testValue1 = UUID.randomUUID();
    Long testValue2 = System.currentTimeMillis();
    Boolean testValue3 = Boolean.FALSE;
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    IdmIdentityContractDto contract2 = testHelper.createIdentityContact(identity, null, null, new LocalDate().plusDays(2));
    IdmIdentityContractDto contract3 = testHelper.createIdentityContact(identity, null, new LocalDate().minusDays(2), new LocalDate().plusDays(2));
    IdmIdentityContractDto primeContractCheck = testHelper.getPrimeContract(identity.getId());
    assertEquals(primeContract.getId(), primeContractCheck.getId());
    IdmFormAttributeDto eavAttributeContract1 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.UUID);
    testHelper.setEavValue(primeContract, eavAttributeContract1, IdmIdentityContract.class, testValue1, PersistentType.UUID);
    IdmFormAttributeDto eavAttributeContract2 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
    testHelper.setEavValue(contract2, eavAttributeContract2, IdmIdentityContract.class, testValue2, PersistentType.LONG);
    IdmFormAttributeDto eavAttributeContract3 = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.BOOLEAN);
    testHelper.setEavValue(contract3, eavAttributeContract3, IdmIdentityContract.class, testValue3, PersistentType.BOOLEAN);
    IdmRoleDto role1 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole1 = testHelper.createAutomaticRole(role1.getId());
    testHelper.createAutomaticRoleRule(automaticRole1.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract1.getId(), testValue1.toString());
    IdmRoleDto role2 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole2 = testHelper.createAutomaticRole(role2.getId());
    testHelper.createAutomaticRoleRule(automaticRole2.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract2.getId(), testValue2.toString());
    IdmRoleDto role3 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole3 = testHelper.createAutomaticRole(role3.getId());
    testHelper.createAutomaticRoleRule(automaticRole3.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract3.getId(), testValue3.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole1.getId());
    this.recalculateSync(automaticRole2.getId());
    this.recalculateSync(automaticRole3.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(3, identityRoles.size());
    boolean contractCheck1 = false;
    boolean contractCheck2 = false;
    boolean contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertTrue(contractCheck1);
    assertTrue(contractCheck2);
    assertTrue(contractCheck3);
    identityContractService.delete(primeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(2, identityRoles.size());
    contractCheck1 = false;
    contractCheck2 = false;
    contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertFalse(contractCheck1);
    assertTrue(contractCheck2);
    assertTrue(contractCheck3);
    IdmIdentityContractDto newPrimeContract = testHelper.getPrimeContract(identity.getId());
    assertNotEquals(primeContract.getId(), newPrimeContract.getId());
    identityContractService.delete(newPrimeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    contractCheck1 = false;
    contractCheck2 = false;
    contractCheck3 = false;
    // 
    for (IdmIdentityRoleDto identityRole : identityRoles) {
        if (identityRole.getIdentityContract().equals(primeContract.getId())) {
            contractCheck1 = true;
        }
        if (identityRole.getIdentityContract().equals(contract2.getId())) {
            contractCheck2 = true;
        }
        if (identityRole.getIdentityContract().equals(contract3.getId())) {
            contractCheck3 = true;
        }
    }
    assertFalse(contractCheck1);
    assertTrue(contractCheck2);
    assertFalse(contractCheck3);
    IdmIdentityContractDto newNewPrimeContract = testHelper.getPrimeContract(identity.getId());
    assertNotEquals(newPrimeContract.getId(), newNewPrimeContract.getId());
    assertEquals(contract2, newNewPrimeContract);
    identityContractService.delete(newNewPrimeContract);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) LocalDate(org.joda.time.LocalDate) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) UUID(java.util.UUID) 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)

Example 83 with IdmIdentityContractDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testRemoveLastRuleWithCheck.

@Test
public void testRemoveLastRuleWithCheck() {
    String eavCode = "testingEav";
    Long testEavContractValue = System.currentTimeMillis();
    UUID testEavIdentityValue = UUID.randomUUID();
    IdmIdentityDto identity = testHelper.createIdentity();
    IdmRoleDto role = testHelper.createRole();
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    // create two eav attributes (for identity and contract)
    IdmFormAttributeDto eavAttributeIdentity = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.UUID);
    testHelper.setEavValue(identity, eavAttributeIdentity, IdmIdentity.class, testEavIdentityValue, PersistentType.UUID);
    IdmFormAttributeDto eavAttributeContract = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentityContract.class, PersistentType.LONG);
    testHelper.setEavValue(primeContract, eavAttributeContract, IdmIdentityContract.class, testEavContractValue, PersistentType.LONG);
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    IdmAutomaticRoleAttributeRuleDto rule1 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttributeIdentity.getId(), testEavIdentityValue.toString());
    IdmAutomaticRoleAttributeRuleDto rule2 = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, null, eavAttributeContract.getId(), testEavContractValue.toString());
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    automaticRoleAttributeRuleService.delete(rule1);
    this.recalculateSync(automaticRole.getId());
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // in process will be start LRT with async remove all identity roles
    automaticRoleAttributeRuleService.delete(rule2);
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 84 with IdmIdentityContractDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method testDontAssingRoleForContractValidInThePast.

@Test
public void testDontAssingRoleForContractValidInThePast() {
    IdmIdentityDto identity = helper.createIdentity();
    // 
    IdmIdentityContractDto contractD = new IdmIdentityContractDto();
    contractD.setIdentity(identity.getId());
    contractD.setWorkPosition(nodeD.getId());
    contractD.setValidTill(new LocalDate().minusDays(1));
    contractD = service.save(contractD);
    // 
    // create new automatic role
    automaticRoleD = new IdmRoleTreeNodeDto();
    automaticRoleD.setRecursionType(RecursionType.NO);
    automaticRoleD.setRole(roleA.getId());
    automaticRoleD.setTreeNode(nodeD.getId());
    automaticRoleD = saveAutomaticRole(automaticRoleD, true);
    // 
    // check
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByContract(contractD.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) LocalDate(org.joda.time.LocalDate) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 85 with IdmIdentityContractDto

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

the class DefaultIdmIdentityContractServiceIntegrationTest method externeFilterTest.

@Test
public void externeFilterTest() {
    IdmIdentityDto identity = helper.createIdentity();
    IdmIdentityDto identity2 = helper.createIdentity();
    IdmTreeNodeDto node = helper.createTreeNode();
    IdmTreeNodeDto node2 = helper.createTreeNode();
    IdmIdentityContractDto contract = helper.createIdentityContact(identity, node);
    IdmIdentityContractDto contract2 = helper.createIdentityContact(identity2, node2);
    contract.setExterne(true);
    service.save(contract);
    contract2.setExterne(false);
    service.save(contract2);
    IdmIdentityContractFilter filter = new IdmIdentityContractFilter();
    filter.setExterne(true);
    Page<IdmIdentityContractDto> result = service.find(filter, null);
    assertTrue(result.getContent().contains(contract));
    assertFalse(result.getContent().contains(contract2));
    filter.setExterne(false);
    result = service.find(filter, null);
    assertTrue(result.getContent().contains(contract2));
    assertFalse(result.getContent().contains(contract));
}
Also used : IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)220 Test (org.junit.Test)170 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)156 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)92 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)91 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)53 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)48 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)45 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)36 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)35 LocalDate (org.joda.time.LocalDate)34 ArrayList (java.util.ArrayList)31 List (java.util.List)29 IdmTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto)28 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)24 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)24 Transactional (org.springframework.transaction.annotation.Transactional)24 UUID (java.util.UUID)19 IdmTreeTypeDto (eu.bcvsolutions.idm.core.api.dto.IdmTreeTypeDto)18