Search in sources :

Example 16 with AttributeFieldError

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

the class TextAttributeValidationRules method checkRegExp.

protected void checkRegExp(AttributeInterface attribute, AttributeTracer tracer, Lang lang, List<AttributeFieldError> errors) {
    String text = ((ITextAttribute) attribute).getTextForLang(lang.getCode());
    if (null != text && text.trim().length() > 0 && null != this.getRegexp() && this.getRegexp().trim().length() > 0) {
        Pattern pattern = Pattern.compile(this.getRegexp());
        Matcher matcher = pattern.matcher(text);
        if (!matcher.matches()) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_FORMAT, tracer);
            error.setMessage("Lang '" + lang.getDescr() + "' - invalid format");
            errors.add(error);
        }
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 17 with AttributeFieldError

use of com.agiletec.aps.system.common.entity.model.AttributeFieldError 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)

Example 18 with AttributeFieldError

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

the class CompositeAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        List<AttributeInterface> attributes = this.getAttributes();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface attributeElement = attributes.get(i);
            AttributeTracer elementTracer = tracer.clone();
            elementTracer.setCompositeElement(true);
            elementTracer.setParentAttribute(this);
            List<AttributeFieldError> elementErrors = attributeElement.validate(elementTracer);
            if (null != elementErrors) {
                errors.addAll(elementErrors);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating composite attribute", t);
        throw new RuntimeException("Error validating composite attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) IndexableAttributeInterface(com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)

Aggregations

AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)18 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)8 ArrayList (java.util.ArrayList)5 Lang (com.agiletec.aps.system.services.lang.Lang)4 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 SymbolicLink (com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)2 SymbolicLinkValidator (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)1 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)1 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)1 AttributeManagerInterface (com.agiletec.apsadmin.system.entity.attribute.manager.AttributeManagerInterface)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1