Search in sources :

Example 1 with PersistentType

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();
}
Also used : AutomaticRoleAttributeRuleComparison(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison) AutomaticRoleAttributeRuleEvent(eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeRuleEvent) PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AutomaticRoleAttributeRuleType(eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with PersistentType

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;
}
Also used : PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) Serializable(java.io.Serializable) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) BigDecimal(java.math.BigDecimal) Predicate(javax.persistence.criteria.Predicate)

Example 3 with PersistentType

use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testGreaterAndLessContractEav.

@Test
public void testGreaterAndLessContractEav() {
    String valueOne = "5";
    String valueTwo = "10";
    PersistentType persistentType = PersistentType.INT;
    IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, false);
    IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.GREATER_THAN_OR_EQUAL, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, valueOne);
    createAutomaticRuleForEav(automaticRole, AutomaticRoleAttributeRuleComparison.LESS_THAN_OR_EQUAL, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, valueTwo);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    checkIdentityRoles(identity, 0);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(6));
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(2));
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(5));
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(-10));
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(10));
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 1);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList());
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
    recalculateAllSync(automaticRole);
    checkIdentityRoles(identity, 0);
}
Also used : PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) 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 4 with PersistentType

use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testEqualsMultivaluedIntContractEav.

@Test
public void testEqualsMultivaluedIntContractEav() {
    String value = "10";
    PersistentType persistentType = PersistentType.INT;
    IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, true);
    IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.EQUALS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, value);
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    IdmIdentityContractDto contract = getHelper().getPrimeContract(identity);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(10));
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 1);
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 1);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(20, 30, 40, 50, 60));
    checkIdentityRoles(identity, 0);
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 0);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList());
    checkIdentityRoles(identity, 0);
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 0);
    saveEavValue(contract, attribute, persistentType, Lists.newArrayList(20, 30, 40, 50, 60, 10));
    checkIdentityRoles(identity, 1);
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 1);
}
Also used : PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) 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 5 with PersistentType

use of eu.bcvsolutions.idm.core.eav.api.domain.PersistentType in project CzechIdMng by bcvsolutions.

the class DefaultIdmAutomaticRoleAttributeServiceIntegrationTest method testNotContainsContractEav.

@Test
public void testNotContainsContractEav() {
    String value = getHelper().createName();
    PersistentType persistentType = PersistentType.SHORTTEXT;
    IdmFormAttributeDto attribute = createFormAttribute(AutomaticRoleAttributeRuleType.CONTRACT_EAV, persistentType, false);
    IdmAutomaticRoleAttributeDto automaticRole = createAutomaticRuleForEav(AutomaticRoleAttributeRuleComparison.NOT_CONTAINS, AutomaticRoleAttributeRuleType.CONTRACT_EAV, attribute, value);
    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() + value));
    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(getHelper().createName() + value + 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(value));
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 0);
    recalculateSync(automaticRole.getId());
    checkIdentityRoles(identity, 0);
}
Also used : PersistentType(eu.bcvsolutions.idm.core.eav.api.domain.PersistentType) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) 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

PersistentType (eu.bcvsolutions.idm.core.eav.api.domain.PersistentType)47 IdmFormAttributeDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto)45 Test (org.junit.Test)44 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)43 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)38 IdmAutomaticRoleAttributeDto (eu.bcvsolutions.idm.core.api.dto.IdmAutomaticRoleAttributeDto)32 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)32 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)17 AutomaticRoleAttributeRuleComparison (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleComparison)2 AutomaticRoleAttributeRuleType (eu.bcvsolutions.idm.core.api.domain.AutomaticRoleAttributeRuleType)2 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AutomaticRoleAttributeRuleEvent (eu.bcvsolutions.idm.core.model.event.AutomaticRoleAttributeRuleEvent)1 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)1 Serializable (java.io.Serializable)1 BigDecimal (java.math.BigDecimal)1 ZonedDateTime (java.time.ZonedDateTime)1 UUID (java.util.UUID)1 Predicate (javax.persistence.criteria.Predicate)1