Search in sources :

Example 1 with NumberAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules in project entando-core by entando.

the class NumberAttributeManager method getCustomAttributeErrorMessage.

@Override
protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) {
    AttributeInterface attribute = attributeFieldError.getAttribute();
    NumberAttributeValidationRules valRules = (NumberAttributeValidationRules) attribute.getValidationRules();
    if (null != valRules) {
        String errorCode = attributeFieldError.getErrorCode();
        if (errorCode.equals(FieldError.LESS_THAN_ALLOWED)) {
            Integer startValue = (valRules.getRangeStart() != null) ? (Integer) valRules.getRangeStart() : this.getOtherAttributeValue(attribute, valRules.getRangeStartAttribute());
            String[] args = { startValue.toString() };
            return action.getText("NumberAttribute.fieldError.lessValue", args);
        } else if (errorCode.equals(FieldError.GREATER_THAN_ALLOWED)) {
            Integer endValue = (valRules.getRangeEnd() != null) ? (Integer) valRules.getRangeEnd() : this.getOtherAttributeValue(attribute, valRules.getRangeEndAttribute());
            String[] args = { endValue.toString() };
            return action.getText("NumberAttribute.fieldError.greaterValue", args);
        } else if (errorCode.equals(FieldError.NOT_EQUALS_THAN_ALLOWED)) {
            Integer value = (valRules.getValue() != null) ? (Integer) valRules.getValue() : this.getOtherAttributeValue(attribute, valRules.getValueAttribute());
            String[] args = { value.toString() };
            return action.getText("NumberAttribute.fieldError.wrongValue", args);
        }
    }
    return action.getText(this.getInvalidAttributeMessage());
}
Also used : AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) NumberAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)

Example 2 with NumberAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules in project entando-core by entando.

the class AbstractBaseEntityAttributeConfigAction method fillAttributeFields.

/**
 * Fill attribute fields.
 * @param attribute The attribute to edit with the form values.
 * @return A customized return code in the attribute needs a extra configuration, else null.
 */
protected String fillAttributeFields(AttributeInterface attribute) {
    if (null != this.getAttributeDescription() && this.getAttributeDescription().trim().length() > 0) {
        attribute.setDescription(this.getAttributeDescription().trim());
    } else {
        attribute.setDescription(null);
    }
    attribute.setRoles(this.createStringArray(this.getAttributeRoles()));
    attribute.setDisablingCodes(this.createStringArray(this.getDisablingCodes()));
    attribute.setSearchable(null != this.getSearchable() && this.getSearchable());
    String indexingType = IndexableAttributeInterface.INDEXING_TYPE_NONE;
    if (null != this.getIndexable()) {
        indexingType = IndexableAttributeInterface.INDEXING_TYPE_TEXT;
    }
    attribute.setIndexingType(indexingType);
    IAttributeValidationRules valCond = attribute.getValidationRules();
    valCond.setRequired(null != this.getRequired() && this.getRequired());
    valCond.setOgnlValidationRule(this.getOgnlValidationRule());
    if (attribute.isTextAttribute()) {
        TextAttributeValidationRules valRule = (TextAttributeValidationRules) valCond;
        valRule.setMaxLength(this.getMaxLength());
        valRule.setMinLength(this.getMinLength());
        valRule.setRegexp(this.getRegexp());
        valRule.setRangeEnd(this.getRangeEndString());
        valRule.setRangeStart(this.getRangeStartString());
        valRule.setValue(this.getEqualString());
        valRule.setRangeEndAttribute(this.getRangeEndStringAttribute());
        valRule.setRangeStartAttribute(this.getRangeStartStringAttribute());
        valRule.setValueAttribute(this.getEqualStringAttribute());
        if (attribute instanceof EnumeratorAttribute) {
            EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attribute;
            enumeratorAttribute.setStaticItems(this.getEnumeratorStaticItems());
            if (null != this.getEnumeratorStaticItemsSeparator() && this.getEnumeratorStaticItemsSeparator().length() > 0) {
                enumeratorAttribute.setCustomSeparator(this.getEnumeratorStaticItemsSeparator());
            }
            if (null != this.getEnumeratorExtractorBean() && this.getEnumeratorExtractorBean().trim().length() > 0) {
                enumeratorAttribute.setExtractorBeanName(this.getEnumeratorExtractorBean());
            } else {
                enumeratorAttribute.setExtractorBeanName(null);
            }
        }
    }
    if (attribute instanceof DateAttribute) {
        DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) valCond;
        dateValRule.setRangeEnd(this.getRangeEndDate());
        dateValRule.setRangeStart(this.getRangeStartDate());
        dateValRule.setValue(this.getEqualDate());
        dateValRule.setRangeEndAttribute(this.getRangeEndDateAttribute());
        dateValRule.setRangeStartAttribute(this.getRangeStartDateAttribute());
        dateValRule.setValueAttribute(this.getEqualDateAttribute());
    }
    if (attribute instanceof NumberAttribute) {
        NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) valCond;
        nulValRule.setRangeEnd(this.getRangeEndNumber());
        nulValRule.setRangeStart(this.getRangeStartNumber());
        nulValRule.setValue(this.getEqualNumber());
        nulValRule.setRangeEndAttribute(this.getRangeEndNumberAttribute());
        nulValRule.setRangeStartAttribute(this.getRangeStartNumberAttribute());
        nulValRule.setValueAttribute(this.getEqualNumberAttribute());
    }
    return null;
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) DateAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules) NumberAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 3 with NumberAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules in project entando-core by entando.

the class EntityAttributeValidationDto method buildAttributeValidation.

public void buildAttributeValidation(String typeCode, AttributeInterface attribute, BindingResult bindingResult) {
    EntityAttributeOgnlValidationDto ognlValidationDto = this.getOgnlValidation();
    if (null != ognlValidationDto) {
        ognlValidationDto.buildAttributeOgnlValidation(typeCode, attribute, bindingResult);
    }
    IAttributeValidationRules validationRules = attribute.getValidationRules();
    if (attribute.isTextAttribute()) {
        TextAttributeValidationRules textValRule = (TextAttributeValidationRules) validationRules;
        if (StringUtils.isEmpty(this.getRegex())) {
            textValRule.setRegexp(this.getRegex());
        }
        if (null != this.getMinLength() && null != this.getMaxLength() && (this.getMinLength() > this.getMaxLength())) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_TEXT_RANGE, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.text.invalidRange");
        } else {
            if (null != this.getMinLength()) {
                textValRule.setMinLength(this.getMinLength());
            }
            if (null != this.getMinLength()) {
                textValRule.setMaxLength(this.getMaxLength());
            }
        }
        if (StringUtils.isEmpty(this.getRangeStartString()) || StringUtils.isEmpty(this.getRangeEndString()) || StringUtils.isEmpty(this.getRangeStartStringAttribute()) || StringUtils.isEmpty(this.getRangeEndStringAttribute())) {
            textValRule.setRangeEnd(this.getRangeEndString());
            textValRule.setRangeStart(this.getRangeStartString());
            textValRule.setRangeEndAttribute(this.getRangeEndStringAttribute());
            textValRule.setRangeStartAttribute(this.getRangeStartStringAttribute());
        } else {
            textValRule.setValue(this.getEqualString());
            textValRule.setValueAttribute(this.getEqualStringAttribute());
        }
    } else if (attribute instanceof DateAttribute) {
        DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) validationRules;
        dateValRule.setRangeStart(this.extractDate(this.getRangeStartDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_RANGE_START, "entityType.attribute.date.invalidRangeStart", bindingResult));
        dateValRule.setRangeEnd(this.extractDate(this.getRangeEndDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_RANGE_END, "entityType.attribute.date.invalidRangeEnd", bindingResult));
        dateValRule.setValue(this.extractDate(this.getEqualDate(), typeCode, attribute.getName(), EntityTypeValidator.ERRCODE_INVALID_DATE_VALUE, "entityType.attribute.date.invalidValue", bindingResult));
        dateValRule.setRangeStartAttribute(this.getRangeStartDateAttribute());
        dateValRule.setRangeEndAttribute(this.getRangeEndDateAttribute());
        dateValRule.setValueAttribute(this.getEqualDateAttribute());
    } else if (attribute instanceof NumberAttribute) {
        NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) validationRules;
        nulValRule.setRangeEnd(this.getRangeEndNumber());
        nulValRule.setRangeStart(this.getRangeStartNumber());
        if (null != this.getRangeStartNumber() && null != this.getRangeEndNumber() && (this.getRangeEndNumber() < this.getRangeStartNumber())) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_NUMBER_RANGE, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.number.invalidRange");
        }
        nulValRule.setValue(this.getEqualNumber());
        nulValRule.setRangeEndAttribute(this.getRangeEndNumberAttribute());
        nulValRule.setRangeStartAttribute(this.getRangeStartNumberAttribute());
        nulValRule.setValueAttribute(nulValRule.getValueAttribute());
    }
}
Also used : DateAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules) NumberAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 4 with NumberAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules in project entando-core by entando.

the class AbstractBaseEntityAttributeConfigAction method valueFormFields.

/**
 * Fill form fields.
 * @param attribute
 */
protected void valueFormFields(AttributeInterface attribute) {
    this.setAttributeName(attribute.getName());
    if (null != attribute.getDescription() && attribute.getDescription().trim().length() > 0) {
        this.setAttributeDescription(attribute.getDescription());
    }
    this.setAttributeTypeCode(attribute.getType());
    if (null != attribute.getRoles()) {
        this.setAttributeRoles(Arrays.asList(attribute.getRoles()));
    }
    if (null != attribute.getDisablingCodes()) {
        this.setDisablingCodes(Arrays.asList(attribute.getDisablingCodes()));
    }
    IAttributeValidationRules valRule = attribute.getValidationRules();
    this.setRequired(valRule.isRequired());
    this.setOgnlValidationRule(valRule.getOgnlValidationRule());
    this.setSearchable(attribute.isSearchable());
    String indexingType = attribute.getIndexingType();
    if (null != indexingType) {
        this.setIndexable(indexingType.equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT));
    }
    if (attribute.isTextAttribute()) {
        TextAttributeValidationRules textValRule = (TextAttributeValidationRules) valRule;
        if (null != textValRule.getMaxLength() && textValRule.getMaxLength() > -1) {
            this.setMaxLength(textValRule.getMaxLength());
        }
        if (null != textValRule.getMinLength() && textValRule.getMinLength() > -1) {
            this.setMinLength(textValRule.getMinLength());
        }
        this.setRegexp(textValRule.getRegexp());
        this.setRangeEndString((String) textValRule.getRangeEnd());
        this.setRangeStartString((String) textValRule.getRangeStart());
        this.setEqualString((String) textValRule.getValue());
        this.setRangeEndStringAttribute(textValRule.getRangeEndAttribute());
        this.setRangeStartStringAttribute(textValRule.getRangeStartAttribute());
        this.setEqualStringAttribute(textValRule.getValueAttribute());
        if (attribute instanceof EnumeratorAttribute) {
            EnumeratorAttribute enumeratorAttribute = (EnumeratorAttribute) attribute;
            this.setEnumeratorStaticItems(enumeratorAttribute.getStaticItems());
            this.setEnumeratorStaticItemsSeparator(enumeratorAttribute.getCustomSeparator());
            this.setEnumeratorExtractorBean(enumeratorAttribute.getExtractorBeanName());
        }
    }
    if (attribute instanceof DateAttribute) {
        DateAttributeValidationRules dateValRule = (DateAttributeValidationRules) valRule;
        this.setRangeEndDate((Date) dateValRule.getRangeEnd());
        this.setRangeStartDate((Date) dateValRule.getRangeStart());
        this.setEqualDate((Date) dateValRule.getValue());
        this.setRangeEndDateAttribute(dateValRule.getRangeEndAttribute());
        this.setRangeStartDateAttribute(dateValRule.getRangeStartAttribute());
        this.setEqualDateAttribute(dateValRule.getValueAttribute());
    }
    if (attribute instanceof NumberAttribute) {
        NumberAttributeValidationRules nulValRule = (NumberAttributeValidationRules) valRule;
        this.setRangeEndNumber((Integer) nulValRule.getRangeEnd());
        this.setRangeStartNumber((Integer) nulValRule.getRangeStart());
        this.setEqualNumber((Integer) nulValRule.getValue());
        this.setRangeEndNumberAttribute(nulValRule.getRangeEndAttribute());
        this.setRangeStartNumberAttribute(nulValRule.getRangeStartAttribute());
        this.setEqualNumberAttribute(nulValRule.getValueAttribute());
    }
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) DateAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules) NumberAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Aggregations

NumberAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)4 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)3 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)3 DateAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules)3 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)3 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1