Search in sources :

Example 1 with IAttributeValidationRules

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

the class AbstractEntityService method buildAttribute.

protected AttributeInterface buildAttribute(String typeCode, EntityAttributeFullDto attributeDto, Map<String, AttributeInterface> attributeMap, BindingResult bindingResult) {
    String type = attributeDto.getType();
    AttributeInterface prototype = attributeMap.get(type);
    if (null == prototype) {
        logger.warn("Undefined attribute of type {}", type);
        this.addError(EntityTypeValidator.ERRCODE_INVALID_ATTRIBUTE_TYPE, bindingResult, new String[] { typeCode, type }, "entityType.attribute.type.invalid");
        return null;
    }
    AttributeInterface attribute = (AttributeInterface) prototype.getAttributePrototype();
    attribute.setName(attributeDto.getCode());
    attribute.setDescription(attributeDto.getName());
    attribute.setIndexingType(attributeDto.isIndexable() ? IndexableAttributeInterface.INDEXING_TYPE_TEXT : null);
    List<AttributeRoleDto> dtoRoles = attributeDto.getRoles();
    if (null != dtoRoles && !dtoRoles.isEmpty()) {
        List<String> codes = dtoRoles.stream().map(AttributeRoleDto::getCode).collect(Collectors.toList());
        attribute.setRoles(codes.toArray(new String[codes.size()]));
    }
    attribute.setRequired(attributeDto.isMandatory());
    attribute.setSearchable(attributeDto.isListFilter());
    if (attribute instanceof EnumeratorAttribute) {
        // to check into validator
        String staticItems = attributeDto.getEnumeratorStaticItems();
        String extractor = attributeDto.getEnumeratorExtractorBean();
        if (StringUtils.isEmpty(staticItems) && StringUtils.isEmpty(extractor)) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_ENUMERATOR, bindingResult, new String[] { typeCode, attributeDto.getCode() }, "entityType.attribute.enumerator.invalid");
        }
        ((EnumeratorAttribute) attribute).setStaticItems(staticItems);
        ((EnumeratorAttribute) attribute).setExtractorBeanName(extractor);
        ((EnumeratorAttribute) attribute).setCustomSeparator(attributeDto.getEnumeratorStaticItemsSeparator());
    }
    IAttributeValidationRules validationRules = attribute.getValidationRules();
    validationRules.setRequired(attributeDto.isMandatory());
    EntityAttributeValidationDto validationDto = attributeDto.getValidationRules();
    if (null != validationDto) {
        validationDto.buildAttributeValidation(typeCode, attribute, bindingResult);
    }
    if (attribute instanceof AbstractListAttribute) {
        if (null != attributeDto.getNestedAttribute()) {
            EntityAttributeFullDto nestedAttributeDto = attributeDto.getNestedAttribute();
            ((AbstractListAttribute) attribute).setNestedAttributeType(this.buildAttribute(typeCode, nestedAttributeDto, attributeMap, bindingResult));
        } else {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_LIST, bindingResult, new String[] { typeCode, type }, "entityType.attribute.list.missingNestedAttribute");
        }
    } else if (attribute instanceof CompositeAttribute) {
        List<EntityAttributeFullDto> compositeElementsDto = attributeDto.getCompositeAttributes();
        if (null != compositeElementsDto && !compositeElementsDto.isEmpty()) {
            for (EntityAttributeFullDto attributeElementDto : compositeElementsDto) {
                AttributeInterface attributeElement = this.buildAttribute(typeCode, attributeElementDto, attributeMap, bindingResult);
                ((CompositeAttribute) attribute).getAttributeMap().put(attributeElement.getName(), attributeElement);
                ((CompositeAttribute) attribute).getAttributes().add(attributeElement);
            }
        } else {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_COMPOSITE, bindingResult, new String[] { typeCode, type }, "entityType.attribute.composite.missingElements");
        }
    }
    return attribute;
}
Also used : EnumeratorAttribute(com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute) CompositeAttribute(com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute) AttributeRoleDto(org.entando.entando.aps.system.services.entity.model.AttributeRoleDto) EntityAttributeFullDto(org.entando.entando.aps.system.services.entity.model.EntityAttributeFullDto) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) ArrayList(java.util.ArrayList) List(java.util.List) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface) AbstractListAttribute(com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute) EntityAttributeValidationDto(org.entando.entando.aps.system.services.entity.model.EntityAttributeValidationDto)

Example 2 with IAttributeValidationRules

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

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

the class EntityAttributeOgnlValidationDto method buildAttributeOgnlValidation.

public void buildAttributeOgnlValidation(String typeCode, AttributeInterface attribute, BindingResult bindingResult) {
    IAttributeValidationRules validationRules = attribute.getValidationRules();
    if (!StringUtils.isEmpty(this.getOgnlExpression())) {
        // to check into validator
        OgnlValidationRule ognlValidationRule = new OgnlValidationRule();
        if (StringUtils.isEmpty(this.getErrorMessage()) && StringUtils.isEmpty(this.getKeyForErrorMessage())) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_OGNL_ERROR, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.ognl.missingErrorMessage");
        }
        if (StringUtils.isEmpty(this.getHelpMessage()) && StringUtils.isEmpty(this.getKeyForHelpMessage())) {
            this.addError(EntityTypeValidator.ERRCODE_INVALID_OGNL_HELP, bindingResult, new String[] { typeCode, attribute.getName() }, "entityType.attribute.ognl.missingHelpMessage");
        }
        ognlValidationRule.setErrorMessage(this.getErrorMessage());
        ognlValidationRule.setErrorMessageKey(this.getKeyForErrorMessage());
        ognlValidationRule.setEvalExpressionOnValuedAttribute(this.isApplyOnlyToFilledAttr());
        ognlValidationRule.setExpression(this.getOgnlExpression());
        ognlValidationRule.setHelpMessage(this.getHelpMessage());
        ognlValidationRule.setHelpMessageKey(this.getKeyForHelpMessage());
        validationRules.setOgnlValidationRule(ognlValidationRule);
    }
}
Also used : IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) OgnlValidationRule(com.agiletec.aps.system.common.entity.model.attribute.util.OgnlValidationRule)

Example 4 with IAttributeValidationRules

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

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

IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)7 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)3 EnumeratorAttribute (com.agiletec.aps.system.common.entity.model.attribute.EnumeratorAttribute)3 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)3 DateAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.DateAttributeValidationRules)3 NumberAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.NumberAttributeValidationRules)3 TextAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.TextAttributeValidationRules)3 ArrayList (java.util.ArrayList)2 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)1 AbstractListAttribute (com.agiletec.aps.system.common.entity.model.attribute.AbstractListAttribute)1 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 CompositeAttribute (com.agiletec.aps.system.common.entity.model.attribute.CompositeAttribute)1 OgnlValidationRule (com.agiletec.aps.system.common.entity.model.attribute.util.OgnlValidationRule)1 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)1 List (java.util.List)1 AttributeRoleDto (org.entando.entando.aps.system.services.entity.model.AttributeRoleDto)1 EntityAttributeFullDto (org.entando.entando.aps.system.services.entity.model.EntityAttributeFullDto)1 EntityAttributeValidationDto (org.entando.entando.aps.system.services.entity.model.EntityAttributeValidationDto)1 Element (org.jdom.Element)1