Search in sources :

Example 6 with IAttributeValidationRules

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

the class AbstractAttribute method setAttributeConfig.

@Override
public void setAttributeConfig(Element attributeElement) throws ApsSystemException {
    try {
        String name = this.extractXmlAttribute(attributeElement, "name", true);
        this.setName(name);
        String description = this.extractXmlAttribute(attributeElement, "description", false);
        this.setDescription(description);
        String searchable = this.extractXmlAttribute(attributeElement, "searchable", false);
        // to guaranted compatibility with previsous version of Entando 4.0.1 *** Start Block
        if (null == searchable) {
            searchable = this.extractXmlAttribute(attributeElement, "searcheable", false);
        }
        // to guaranted compatibility with previsous version of Entando 4.0.1 *** End Block
        this.setSearchable(null != searchable && searchable.equalsIgnoreCase("true"));
        IAttributeValidationRules validationCondition = this.getValidationRules();
        validationCondition.setConfig(attributeElement);
        // to guaranted compatibility with previsous version of jAPS 2.0.12 *** Start Block
        String required = this.extractXmlAttribute(attributeElement, "required", false);
        if (null != required && required.equalsIgnoreCase("true")) {
            this.setRequired(true);
        }
        // to guaranted compatibility with previsous version of jAPS 2.0.12 *** End Block
        String indexingType = this.extractXmlAttribute(attributeElement, "indexingtype", false);
        if (null != indexingType) {
            this.setIndexingType(indexingType);
        } else {
            this.setIndexingType(IndexableAttributeInterface.INDEXING_TYPE_NONE);
        }
        Element disablingCodesElements = attributeElement.getChild("disablingCodes");
        if (null != disablingCodesElements) {
            String[] disablingCodes = this.extractValues(disablingCodesElements, "code");
            this.setDisablingCodes(disablingCodes);
        } else {
            // to guaranted compatibility with previsous version of jAPS 2.0.12 *** Start Block
            String disablingCodesStr = this.extractXmlAttribute(attributeElement, "disablingCodes", false);
            if (disablingCodesStr != null) {
                String[] disablingCodes = disablingCodesStr.split(",");
                this.setDisablingCodes(disablingCodes);
            }
        // to guaranted compatibility with previsous version of jAPS 2.0.12 *** End Block
        }
        Element rolesElements = attributeElement.getChild("roles");
        if (null != rolesElements) {
            String[] roles = this.extractValues(rolesElements, "role");
            this.setRoles(roles);
        }
    } catch (Throwable t) {
        String message = "Error detected while creating the attribute config '" + this.getName() + "' type '" + this.getType() + "'";
        _logger.error("Error detected while creating the attribute config '{}' type '{}'", this.getName(), this.getType(), t);
        throw new RuntimeException(message, t);
    }
}
Also used : Element(org.jdom.Element) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)

Example 7 with IAttributeValidationRules

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

the class AbstractAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = new ArrayList<>();
    try {
        if (this.getStatus().equals(Status.INCOMPLETE)) {
            errors.add(new AttributeFieldError(this, FieldError.INVALID, tracer));
        } else {
            IAttributeValidationRules validationRules = this.getValidationRules();
            if (null == validationRules) {
                return errors;
            }
            List<AttributeFieldError> validationRulesErrors = validationRules.validate(this, tracer, this.getLangManager());
            if (null != validationRulesErrors) {
                errors.addAll(validationRulesErrors);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating Attribute '{}'", this.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + this.getName() + "'", t);
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) IAttributeValidationRules(com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

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