use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeIntegrationTest method testMoreContracts.
@Test
public void testMoreContracts() {
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(5), new LocalDate().plusDays(5));
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());
identityContractService.delete(contract3);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(2, identityRoles.size());
identityContractService.delete(contract2);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(1, identityRoles.size());
identityContractService.delete(primeContract);
identityRoles = identityRoleService.findAllByIdentity(identity.getId());
assertEquals(0, identityRoles.size());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto 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());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto 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());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto 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());
}
use of eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeService method getPredicateForRuleByContract.
/**
* Return predicate for given rule by contract
*
* @param rule
* @param root
* @param query
* @param cb
* @return
*/
private Predicate getPredicateForRuleByContract(IdmAutomaticRoleAttributeRuleDto rule, Root<IdmIdentityContract> root, CriteriaQuery<?> query, CriteriaBuilder cb, boolean pass) {
//
Metamodel metamodel = entityManager.getMetamodel();
if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT) {
SingularAttribute<? super IdmIdentityContract, ?> singularAttribute = metamodel.entity(IdmIdentityContract.class).getSingularAttribute(rule.getAttributeName());
Path<Object> path = root.get(singularAttribute.getName());
return getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue()), cb, rule.getComparison(), !pass);
} else if (rule.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
//
Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
//
Subquery<IdmIdentityContractFormValue> subquery = query.subquery(IdmIdentityContractFormValue.class);
Root<IdmIdentityContractFormValue> subRoot = subquery.from(IdmIdentityContractFormValue.class);
subquery.select(subRoot);
//
Path<?> path = subRoot.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
//
subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentityContractFormValue_.owner), root), cb.equal(subRoot.get(IdmIdentityContractFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
//
Predicate existsInEav = getPredicateForConnection(subquery, cb, pass);
//
return existsInEav;
} else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV) {
IdmFormAttributeDto formAttributeDto = formAttributeService.get(rule.getFormAttribute());
//
Object value = getEavValue(rule.getValue(), formAttributeDto.getPersistentType());
//
Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
subquery.select(subRoot);
Subquery<IdmIdentityFormValue> subQueryIdentityEav = query.subquery(IdmIdentityFormValue.class);
Root<IdmIdentityFormValue> subRootIdentityEav = subQueryIdentityEav.from(IdmIdentityFormValue.class);
subQueryIdentityEav.select(subRootIdentityEav);
//
Path<?> path = subRootIdentityEav.get(getSingularAttributeForEav(formAttributeDto.getPersistentType()));
subQueryIdentityEav.where(cb.and(cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.owner), subRoot), cb.equal(root.get(IdmIdentityContract_.identity), subRoot), cb.equal(subRootIdentityEav.get(IdmIdentityFormValue_.formAttribute).get(AbstractFormValue_.id), formAttributeDto.getId()), getPredicateWithComparsion(path, value, cb, rule.getComparison(), null)));
//
Predicate existsInEav = getPredicateForConnection(subQueryIdentityEav, cb, pass);
//
subquery.where(cb.and(cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), existsInEav));
//
return cb.exists(subquery);
} else if (rule.getType() == AutomaticRoleAttributeRuleType.IDENTITY) {
Subquery<IdmIdentity> subquery = query.subquery(IdmIdentity.class);
Root<IdmIdentity> subRoot = subquery.from(IdmIdentity.class);
subquery.select(subRoot);
//
SingularAttribute<? super IdmIdentity, ?> singularAttribute = metamodel.entity(IdmIdentity.class).getSingularAttribute(rule.getAttributeName());
Path<Object> path = subRoot.get(singularAttribute.getName());
//
subquery.where(// correlation attr
cb.and(// correlation attr
cb.equal(subRoot.get(IdmIdentity_.id), root.get(IdmIdentityContract_.identity).get(AbstractEntity_.id)), getPredicateWithComparsion(path, castToType(singularAttribute, rule.getValue()), cb, rule.getComparison(), null)));
//
return getPredicateForConnection(subquery, cb, pass);
} else {
throw new UnsupportedOperationException("Type: " + rule.getType().name() + ", isn't supported for contract rules!");
}
}
Aggregations