Search in sources :

Example 1 with TextAttributeValidationRules

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

the class MonoTextAttributeManager method getCustomAttributeErrorMessage.

@Override
protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) {
    AttributeInterface attribute = attributeFieldError.getAttribute();
    TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules();
    if (null != valRules) {
        ITextAttribute textAttribute = (ITextAttribute) attribute;
        String text = textAttribute.getTextForLang(null);
        String errorCode = attributeFieldError.getErrorCode();
        if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMinLength()) };
            return action.getText("MonotextAttribute.fieldError.invalidMinLength", args);
        } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMaxLength()) };
            return action.getText("MonotextAttribute.fieldError.invalidMaxLength", args);
        } else if (errorCode.equals(FieldError.INVALID_FORMAT)) {
            return action.getText("MonotextAttribute.fieldError.invalidInsertedText");
        }
    }
    return action.getText(this.getInvalidAttributeMessage());
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)

Example 2 with TextAttributeValidationRules

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

the class TextAttributeManager method getCustomAttributeErrorMessage.

@Override
protected String getCustomAttributeErrorMessage(AttributeFieldError attributeFieldError, ActionSupport action) {
    AttributeInterface attribute = attributeFieldError.getAttribute();
    TextAttributeValidationRules valRules = (TextAttributeValidationRules) attribute.getValidationRules();
    if (null != valRules) {
        ITextAttribute textAttribute = (ITextAttribute) attribute;
        Lang lang = attributeFieldError.getTracer().getLang();
        String langCode = (null != lang) ? lang.getCode() : null;
        String text = textAttribute.getTextForLang(langCode);
        String errorCode = attributeFieldError.getErrorCode();
        if (errorCode.equals(FieldError.INVALID_MIN_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMinLength()), lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidMinLength", args);
        } else if (errorCode.equals(FieldError.INVALID_MAX_LENGTH)) {
            String[] args = { String.valueOf(text.length()), String.valueOf(valRules.getMaxLength()), lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidMaxLength", args);
        } else if (errorCode.equals(FieldError.INVALID_FORMAT)) {
            String[] args = { lang.getDescr() };
            return action.getText("TextAttribute.fieldError.invalidInsertedText", args);
        }
    }
    return action.getText(this.getInvalidAttributeMessage());
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Lang(com.agiletec.aps.system.services.lang.Lang) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) TextAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)

Example 3 with TextAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules 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 4 with TextAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules 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 5 with TextAttributeValidationRules

use of com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules 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

TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)5 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 NumberAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)3 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)2 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)2 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)2 Lang (com.agiletec.aps.system.services.lang.Lang)1