use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeRuleRequestService method saveInternal.
@Override
@Transactional
public IdmAutomaticRoleAttributeRuleRequestDto saveInternal(IdmAutomaticRoleAttributeRuleRequestDto dto) {
// Numeric attribute can be only EAV (for now, even external code is string)
boolean isAttributeNumeric = false;
AutomaticRoleAttributeRuleComparison comparison = dto.getComparison();
AutomaticRoleAttributeRuleType type = dto.getType();
// Boolean attribute is allowed only with equals and not equals comparison.
boolean isEqualsOrNotEquals = comparison == AutomaticRoleAttributeRuleComparison.EQUALS || comparison == AutomaticRoleAttributeRuleComparison.NOT_EQUALS;
// use only short text
if ((AutomaticRoleAttributeRuleType.CONTRACT_EAV == type || AutomaticRoleAttributeRuleType.IDENTITY_EAV == type) && dto.getFormAttribute() != null) {
IdmFormAttributeDto formAttribute = formAttributeService.get(dto.getFormAttribute());
if (formAttribute == null) {
throw new ResultCodeException(CoreResultCode.NOT_FOUND, ImmutableMap.of("attribute", dto.getFormAttribute()));
}
PersistentType formAttributePersistenType = formAttribute.getPersistentType();
if (formAttributePersistenType == PersistentType.TEXT) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_PERSISTENT_TYPE_TEXT);
}
if (formAttribute.isMultiple() && (comparison != AutomaticRoleAttributeRuleComparison.EQUALS && comparison != AutomaticRoleAttributeRuleComparison.IS_EMPTY && comparison != AutomaticRoleAttributeRuleComparison.IS_NOT_EMPTY)) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_INVALID_COMPARSION_WITH_MULTIPLE_ATTIBUTE, ImmutableMap.of("comparison", comparison.name()));
}
if (formAttributePersistenType == PersistentType.BOOLEAN && !isEqualsOrNotEquals) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_INVALID_COMPARSION_BOOLEAN, ImmutableMap.of("comparison", comparison.name()));
}
// Numeric value now can be only EAV
isAttributeNumeric = formAttributePersistenType == PersistentType.INT || formAttributePersistenType == PersistentType.DOUBLE || formAttributePersistenType == PersistentType.LONG;
}
if ((comparison == AutomaticRoleAttributeRuleComparison.GREATER_THAN_OR_EQUAL || comparison == AutomaticRoleAttributeRuleComparison.LESS_THAN_OR_EQUAL) && !isAttributeNumeric) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_COMPARSION_IS_ONLY_FOR_NUMERIC_ATTRIBUTE, ImmutableMap.of("comparison", comparison.name()));
}
//
String attributeName = dto.getAttributeName();
// check if is filled all necessary attribute
if ((type == AutomaticRoleAttributeRuleType.CONTRACT || type == AutomaticRoleAttributeRuleType.IDENTITY) && StringUtils.isEmpty(attributeName)) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_ATTRIBUTE_EMPTY, ImmutableMap.of("automaticRoleId", dto.getId(), "attribute", IdmAutomaticRoleAttributeRule_.attributeName.getName()));
}
//
if (!isEqualsOrNotEquals) {
if (type == AutomaticRoleAttributeRuleType.CONTRACT) {
if (attributeName.equals(IdmIdentityContract_.main.getName())) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_INVALID_COMPARSION_BOOLEAN, ImmutableMap.of("comparison", comparison.name()));
}
if (attributeName.equals(IdmIdentityContract_.externe.getName())) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_INVALID_COMPARSION_BOOLEAN, ImmutableMap.of("comparison", comparison.name()));
}
}
if (type == AutomaticRoleAttributeRuleType.IDENTITY && attributeName.equals(IdmIdentity_.disabled.getName())) {
if (attributeName.equals(IdmIdentity_.disabled.getName())) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_INVALID_COMPARSION_BOOLEAN, ImmutableMap.of("comparison", comparison.name()));
}
}
}
//
if (comparison == AutomaticRoleAttributeRuleComparison.EQUALS && dto.getValue() == null) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_ATTRIBUTE_EMPTY, ImmutableMap.of("attribute", IdmAutomaticRoleAttributeRule_.value.getName()));
}
return super.saveInternal(dto);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testIsEmptyContractEav.
@Test
public void testIsEmptyContractEav() {
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, false);
IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.IS_EMPTY, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, null);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
saveEavValue(contract, attribute, persistentType, Lists.newArrayList(getHelper().createName()));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(contract, attribute, persistentType, Lists.newArrayList());
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
saveEavValue(contract, attribute, persistentType, Lists.newArrayList("00000"));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(contract, attribute, persistentType, Lists.newArrayList(" "));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testEqualsIdentityMultivaluedEav.
@Test
public void testEqualsIdentityMultivaluedEav() {
String value = "10";
PersistentType persistentType = PersistentType.LONG;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.IDENTITY_EAV, persistentType, true);
IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.IDENTITY_EAV, attribute, value);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(10, 20, 30));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(9, 2, 3));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(11, 10, 12));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testIncompatibleNotContainsMultivaluedContractEav.
@Test(expected = ResultCodeException.class)
public void testIncompatibleNotContainsMultivaluedContractEav() {
String value = getHelper().createName();
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, true);
createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.NOT_CONTAINS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, value);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testIsNotEmptyIdentityEav.
@Test
public void testIsNotEmptyIdentityEav() {
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.IDENTITY_EAV, persistentType, false);
IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.IS_NOT_EMPTY, AutomaticRoleAttributeRuleType.IDENTITY_EAV, attribute, null);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(getHelper().createName()));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(""));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList());
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
}
Aggregations