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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations