Search in sources :

Example 41 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByContractAttrWithoutRecalcualte.

@Test
public void testAssingByContractAttrWithoutRecalcualte() {
    String testValue = "123!@#" + System.currentTimeMillis();
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.position.getName(), null, testValue);
    // 
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    IdmIdentityContractDto primeContract = testHelper.getPrimeContract(identity.getId());
    primeContract.setPosition(testValue);
    primeContract = identityContractService.save(primeContract);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
    assertNotNull(identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getId(), identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
    // 
    // change value and recalculate
    primeContract.setPosition(testValue + "test");
    primeContract = identityContractService.save(primeContract);
    // 
    // recalculate isn't needed, is done when save identity
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) 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 42 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAssingByIdentityEavAttrWithRecalcualte.

@Test
public void testAssingByIdentityEavAttrWithRecalcualte() {
    String testValue = "123!@#" + System.currentTimeMillis();
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.SHORTTEXT);
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.SHORTTEXT);
    // 
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue);
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // add new one
    this.recalculateSync(automaticRole.getId());
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
    // 
    IdmIdentityRoleDto identityRoleDto = identityRoles.get(0);
    assertNotNull(identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getId(), identityRoleDto.getRoleTreeNode());
    assertEquals(automaticRole.getRole(), identityRoleDto.getRole());
    // 
    // change value and recalculate
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue + "-test", PersistentType.SHORTTEXT);
    // 
    // recalculate isn't needed, is done when save identity contract
    // 
    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) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 43 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleDoubleEav.

@Test
public void testAutomaticRoleDoubleEav() {
    Double testValue = 123456d;
    IdmIdentityDto identity = testHelper.createIdentity();
    // 
    IdmFormAttributeDto createEavAttribute = testHelper.createEavAttribute("testingEav" + System.currentTimeMillis(), IdmIdentity.class, PersistentType.DOUBLE);
    // 
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, createEavAttribute.getId(), testValue.toString());
    // 
    List<IdmIdentityRoleDto> identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(0, identityRoles.size());
    // 
    // change eav value
    testHelper.setEavValue(identity, createEavAttribute, IdmIdentity.class, testValue, PersistentType.DOUBLE);
    // 
    identityRoles = identityRoleService.findAllByIdentity(identity.getId());
    assertEquals(1, identityRoles.size());
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmIdentityRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 44 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testAutomaticRoleRuleCrud.

@Test
public void testAutomaticRoleRuleCrud() {
    IdmRoleDto role = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = new IdmAutomaticRoleAttributeDto();
    automaticRole.setRole(role.getId());
    automaticRole.setName(getTestName());
    automaticRole = automaticRoleAttributeService.save(automaticRole);
    // 
    IdmAutomaticRoleAttributeRuleDto rule1 = new IdmAutomaticRoleAttributeRuleDto();
    rule1.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule1.setType(AutomaticRoleAttributeRuleType.IDENTITY);
    rule1.setValue("test");
    rule1.setAttributeName(IdmIdentity_.username.getName());
    rule1.setAutomaticRoleAttribute(automaticRole.getId());
    IdmAutomaticRoleAttributeRuleDto rule1Saved = automaticRoleAttributeRuleService.save(rule1);
    // 
    assertNotNull(rule1Saved.getId());
    assertEquals(rule1.getComparison(), rule1Saved.getComparison());
    assertEquals(rule1.getValue(), rule1Saved.getValue());
    assertEquals(rule1.getAttributeName(), rule1Saved.getAttributeName());
    assertEquals(rule1.getAutomaticRoleAttribute(), rule1Saved.getAutomaticRoleAttribute());
    // 
    IdmAutomaticRoleAttributeRuleDto rule2 = new IdmAutomaticRoleAttributeRuleDto();
    rule2.setComparison(AutomaticRoleAttributeRuleComparison.EQUALS);
    rule2.setType(AutomaticRoleAttributeRuleType.CONTRACT);
    rule2.setAttributeName(IdmIdentityContract_.description.getName());
    rule2.setValue("test2");
    rule2.setAutomaticRoleAttribute(automaticRole.getId());
    IdmAutomaticRoleAttributeRuleDto rule2Saved = automaticRoleAttributeRuleService.save(rule2);
    // 
    assertNotNull(rule2Saved.getId());
    assertEquals(rule2.getComparison(), rule2Saved.getComparison());
    assertEquals(rule2.getValue(), rule2Saved.getValue());
    assertEquals(rule2.getAttributeName(), rule2Saved.getAttributeName());
    assertEquals(rule2.getAutomaticRoleAttribute(), rule2Saved.getAutomaticRoleAttribute());
    // 
    // update is allowed
    rule1Saved.setAttributeName(IdmIdentity_.description.getName());
    IdmAutomaticRoleAttributeRuleDto updatedRule1 = automaticRoleAttributeRuleService.save(rule1Saved);
    assertEquals(rule1Saved.getComparison(), updatedRule1.getComparison());
    assertEquals(rule1Saved.getValue(), updatedRule1.getValue());
    assertEquals(rule1Saved.getAttributeName(), updatedRule1.getAttributeName());
    assertEquals(rule1Saved.getAutomaticRoleAttribute(), updatedRule1.getAutomaticRoleAttribute());
    // 
    IdmAutomaticRoleAttributeRuleFilter filter = new IdmAutomaticRoleAttributeRuleFilter();
    filter.setAutomaticRoleAttributeId(automaticRole.getId());
    List<IdmAutomaticRoleAttributeRuleDto> content = automaticRoleAttributeRuleService.find(filter, null).getContent();
    assertEquals(2, content.size());
    // 
    automaticRoleAttributeRuleService.delete(rule1Saved);
    content = automaticRoleAttributeRuleService.find(filter, null).getContent();
    assertEquals(1, content.size());
    IdmAutomaticRoleAttributeRuleDto findAutomaticRole = automaticRoleAttributeRuleService.get(rule1Saved.getId());
    assertNull(findAutomaticRole);
}
Also used : IdmRoleDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleDto) IdmAutomaticRoleAttributeRuleDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto) IdmAutomaticRoleAttributeRuleFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter) IdmAutomaticRoleAttributeDto(eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 45 with IdmAutomaticRoleAttributeDto

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

the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testEmptyIdentityEav.

@Test
public void testEmptyIdentityEav() {
    String testDescription = "testDescription-" + System.currentTimeMillis();
    String eavCode = "eavCode-test-";
    // 
    IdmIdentityDto identity1 = testHelper.createIdentity();
    IdmIdentityDto identity2 = testHelper.createIdentity();
    IdmIdentityDto identity3 = testHelper.createIdentity();
    IdmIdentityContractDto contract1 = testHelper.getPrimeContract(identity1.getId());
    IdmIdentityContractDto contract2 = testHelper.getPrimeContract(identity2.getId());
    IdmIdentityContractDto contract3 = testHelper.getPrimeContract(identity3.getId());
    contract1.setDescription(testDescription);
    contract2.setDescription(testDescription);
    contract3.setDescription(testDescription);
    contract1 = identityContractService.save(contract1);
    contract2 = identityContractService.save(contract2);
    contract3 = identityContractService.save(contract3);
    IdmFormAttributeDto eavAttribute = testHelper.createEavAttribute(eavCode + System.currentTimeMillis(), IdmIdentity.class, PersistentType.BOOLEAN);
    testHelper.setEavValue(identity1, eavAttribute, IdmIdentity.class, Boolean.TRUE, PersistentType.BOOLEAN);
    IdmRoleDto role1 = testHelper.createRole();
    IdmAutomaticRoleAttributeDto automaticRole = testHelper.createAutomaticRole(role1.getId());
    testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT, IdmIdentityContract_.description.getName(), null, testDescription);
    List<IdmIdentityRoleDto> roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    List<IdmIdentityRoleDto> roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    List<IdmIdentityRoleDto> roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(0, roles1.size());
    assertEquals(0, roles2.size());
    assertEquals(0, roles3.size());
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(1, roles2.size());
    assertEquals(1, roles3.size());
    IdmAutomaticRoleAttributeRuleDto rule = testHelper.createAutomaticRoleRule(automaticRole.getId(), AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, null, eavAttribute.getId(), Boolean.TRUE.toString());
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(0, roles2.size());
    assertEquals(0, roles3.size());
    automaticRoleAttributeRuleService.delete(rule);
    this.recalculateSync(automaticRole.getId());
    roles1 = identityRoleService.findAllByIdentity(identity1.getId());
    roles2 = identityRoleService.findAllByIdentity(identity2.getId());
    roles3 = identityRoleService.findAllByIdentity(identity3.getId());
    assertEquals(1, roles1.size());
    assertEquals(1, roles2.size());
    assertEquals(1, roles3.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) 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)

Aggregations

IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)56 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)44 Test (org.junit.Test)41 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)37 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)34 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)30 IdmAutomaticRoleAttributeRuleDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeRuleDto)20 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)15 UUID (java.util.UUID)12 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)7 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)7 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)7 IdmAutomaticRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleRequestDto)6 AbstractIdmAutomaticRoleDto (eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto)5 IdmAutomaticRoleAttributeRuleFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmAutomaticRoleAttributeRuleFilter)5 LocalDate (org.joda.time.LocalDate)5 IdmRoleTreeNodeDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto)4 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)4 RoleRequestException (eu.bcvsolutions.idm.core.api.exception.RoleRequestException)4