use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testIsEmptyIdentityEav.
@Test
public void testIsEmptyIdentityEav() {
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.IDENTITY_EAV, persistentType, false);
IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.IS_EMPTY, AutomaticRoleAttributeRuleType.IDENTITY_EAV, attribute, null);
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 1);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList(getHelper().createName()));
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
recalculateSync(automaticRole.getId());
checkIdentityRoles(identity, 0);
saveEavValue(identity, attribute, persistentType, Lists.newArrayList());
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 testIncompatibleLessThanMultivaluedContractEav.
@Test(expected = ResultCodeException.class)
public void testIncompatibleLessThanMultivaluedContractEav() {
String value = getHelper().createName();
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, true);
createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.LESS_THAN_OR_EQUAL, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, value);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testNotEqualsMultivaluedContractEav.
@Test(expected = ResultCodeException.class)
public void testNotEqualsMultivaluedContractEav() {
String value = getHelper().createName();
PersistentType persistentType = PersistentType.SHORTTEXT;
IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, true);
createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.NOT_EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, value);
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class AbstractFormValueService method toPredicates.
@Override
protected List<Predicate> toPredicates(Root<E> root, CriteriaQuery<?> query, CriteriaBuilder builder, IdmFormValueFilter<O> filter) {
List<Predicate> predicates = super.toPredicates(root, query, builder, filter);
//
String text = filter.getText();
if (StringUtils.isNotEmpty(text)) {
text = text.toLowerCase();
predicates.add(builder.or(builder.like(builder.lower(root.get(AbstractFormValue_.formAttribute).get(IdmFormAttribute_.code)), "%" + text + "%"), builder.like(builder.lower(root.get(AbstractFormValue_.formAttribute).get(IdmFormAttribute_.name)), "%" + text + "%")));
}
//
PersistentType persistentType = filter.getPersistentType();
if (persistentType != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.persistentType), persistentType));
}
//
UUID definitionId = filter.getDefinitionId();
if (definitionId != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.formAttribute).get(IdmFormAttribute_.formDefinition).get(IdmFormDefinition_.id), definitionId));
}
//
List<UUID> attributeIds = filter.getAttributeIds();
if (CollectionUtils.isNotEmpty(attributeIds)) {
predicates.add(root.get(AbstractFormValue_.formAttribute).get(IdmFormAttribute_.id).in(attributeIds));
}
//
O owner = filter.getOwner();
if (owner != null) {
// by id - owner doesn't need to be persisted
Serializable ownerId = owner.getId();
if (ownerId != null) {
predicates.add(builder.equal(root.get(FormValueService.PROPERTY_OWNER).get(BaseEntity.PROPERTY_ID), ownerId));
}
}
//
String stringValue = filter.getStringValue();
if (StringUtils.isNotEmpty(stringValue)) {
predicates.add(builder.equal(root.get(AbstractFormValue_.stringValue), stringValue));
}
//
String shortTextValue = filter.getShortTextValue();
if (StringUtils.isNotEmpty(shortTextValue)) {
predicates.add(builder.equal(root.get(AbstractFormValue_.shortTextValue), shortTextValue));
}
//
String stringValueLike = filter.getStringValueLike();
if (StringUtils.isNotEmpty(stringValueLike)) {
predicates.add(builder.like(builder.lower(root.get(AbstractFormValue_.stringValue)), "%" + stringValueLike.toLowerCase() + "%"));
}
//
String shortTextValueLike = filter.getShortTextValueLike();
if (StringUtils.isNotEmpty(shortTextValueLike)) {
predicates.add(builder.like(builder.lower(root.get(AbstractFormValue_.shortTextValue)), "%" + shortTextValueLike.toLowerCase() + "%"));
}
//
Boolean booleanValue = filter.getBooleanValue();
if (booleanValue != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.booleanValue), booleanValue));
}
//
Long longValue = filter.getLongValue();
if (longValue != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.longValue), longValue));
}
//
BigDecimal doubleValue = filter.getDoubleValue();
if (doubleValue != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.doubleValue), doubleValue));
}
//
ZonedDateTime dateValue = filter.getDateValue();
if (dateValue != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.dateValue), dateValue));
}
ZonedDateTime dateValueFrom = filter.getDateValueFrom();
if (dateValueFrom != null) {
predicates.add(builder.greaterThanOrEqualTo(root.get(AbstractFormValue_.dateValue), dateValueFrom));
}
ZonedDateTime dateValueTill = filter.getDateValueTill();
if (dateValueTill != null) {
predicates.add(builder.lessThanOrEqualTo(root.get(AbstractFormValue_.dateValue), dateValueTill));
}
//
UUID uuidValue = filter.getUuidValue();
if (uuidValue != null) {
predicates.add(builder.equal(root.get(AbstractFormValue_.uuidValue), uuidValue));
}
//
return predicates;
}
use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.
the class DefaultIdmAutomaticRoleAttributeRuleService method save.
@Override
@Transactional
public IdmAutomaticRoleAttributeRuleDto save(IdmAutomaticRoleAttributeRuleDto dto, BasePermission... permission) {
// 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;
// now isn't possible do equals with string_value (clob), so it is necessary to use only short text
if ((AutomaticRoleAttributeRuleType.CONTRACT_EAV == type || AutomaticRoleAttributeRuleType.IDENTITY_EAV == type) && dto.getFormAttribute() != null) {
initFormAttributeService();
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 ((dto.getType() == AutomaticRoleAttributeRuleType.IDENTITY_EAV || dto.getType() == AutomaticRoleAttributeRuleType.CONTRACT_EAV) && dto.getAutomaticRoleAttribute() == null) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_ATTRIBUTE_EMPTY, ImmutableMap.of("automaticRoleId", dto.getId(), "attribute", IdmAutomaticRoleAttributeRule_.automaticRoleAttribute.getName()));
}
if (comparison == AutomaticRoleAttributeRuleComparison.EQUALS && dto.getValue() == null) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_RULE_ATTRIBUTE_EMPTY, ImmutableMap.of("attribute", IdmAutomaticRoleAttributeRule_.value.getName()));
}
// throw new event
if (isNew(dto)) {
return entityEventManager.process(new AutomaticRoleAttributeRuleEvent(AutomaticRoleAttributeRuleEventType.CREATE, dto)).getContent();
}
return entityEventManager.process(new AutomaticRoleAttributeRuleEvent(AutomaticRoleAttributeRuleEventType.UPDATE, dto)).getContent();
}
Aggregations