Search in sources :

Example 6 with AttributeFieldError

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

the class BaseAttributeValidationRules method validate.

@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    List<AttributeFieldError> errors = new ArrayList<>();
    if (this.isEmpty()) {
        return errors;
    }
    try {
        if (this.isRequired() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) {
            AttributeTracer tracerClone = tracer.clone();
            tracerClone.setLang(langManager.getDefaultLang());
            errors.add(new AttributeFieldError(attribute, FieldError.MANDATORY, tracerClone));
        }
        OgnlValidationRule ognlValidationRule = this.getOgnlValidationRule();
        if (null != ognlValidationRule) {
            AttributeFieldError error = ognlValidationRule.validate(attribute, tracer, langManager);
            if (null != error) {
                errors.add(error);
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating Attribute '{}'", attribute.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) ArrayList(java.util.ArrayList) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 7 with AttributeFieldError

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

the class DateAttributeValidationRules method validate.

@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
    if (this.isEmpty()) {
        return errors;
    }
    try {
        Date attributeValue = ((DateAttribute) attribute).getDate();
        if (null == attributeValue) {
            return errors;
        }
        Date startValue = (this.getRangeStart() != null) ? (Date) this.getRangeStart() : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
        if (null != startValue && attributeValue.before(startValue)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(startValue, DATE_PATTERN);
            error.setMessage("Date less than " + allowedDate);
            errors.add(error);
        }
        Date endValue = (this.getRangeEnd() != null) ? (Date) this.getRangeEnd() : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
        if (null != endValue && attributeValue.after(endValue)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(endValue, DATE_PATTERN);
            error.setMessage("Date greater than " + allowedDate);
            errors.add(error);
        }
        Date value = (this.getValue() != null) ? (Date) this.getValue() : this.getOtherAttributeValue(attribute, this.getValueAttribute());
        if (null != value && !attributeValue.equals(value)) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.NOT_EQUALS_THAN_ALLOWED, tracer);
            String allowedDate = DateConverter.getFormattedDate(value, DATE_PATTERN);
            error.setMessage("Date not equals than " + allowedDate);
            errors.add(error);
        }
    } catch (Throwable t) {
        _logger.error("Error validating Attribute '{}'", attribute.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + attribute.getName() + "'", t);
    }
    return errors;
}
Also used : AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Date(java.util.Date) DateAttribute(com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)

Example 8 with AttributeFieldError

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

the class NumberAttributeValidationRules method validate.

@Override
public List<AttributeFieldError> validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    List<AttributeFieldError> errors = super.validate(attribute, tracer, langManager);
    if (this.isEmpty()) {
        return errors;
    }
    try {
        NumberAttribute numberAttribute = (NumberAttribute) attribute;
        if (null == numberAttribute.getValue()) {
            return errors;
        }
        int attributeValue = numberAttribute.getValue().intValue();
        Integer startValue = (this.getRangeStart() != null) ? (Integer) this.getRangeStart() : this.getOtherAttributeValue(attribute, this.getRangeStartAttribute());
        if (null != startValue && attributeValue < startValue) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.LESS_THAN_ALLOWED, tracer);
            error.setMessage("Number less than " + startValue);
            errors.add(error);
        }
        Integer endValue = (this.getRangeEnd() != null) ? (Integer) this.getRangeEnd() : this.getOtherAttributeValue(attribute, this.getRangeEndAttribute());
        if (null != endValue && attributeValue > endValue) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.GREATER_THAN_ALLOWED, tracer);
            error.setMessage("Number greater than " + endValue);
            errors.add(error);
        }
        Integer value = (this.getValue() != null) ? (Integer) this.getValue() : this.getOtherAttributeValue(attribute, this.getValueAttribute());
        if (null != value && attributeValue != value) {
            AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID, tracer);
            error.setMessage("Number not equals than " + value);
            errors.add(error);
        }
    } catch (Throwable t) {
        _logger.error("Error validating number attribute", t);
        throw new RuntimeException("Error validating number attribute", t);
    }
    return errors;
}
Also used : NumberAttribute(com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 9 with AttributeFieldError

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

the class TextAttributeValidationRules method checkTextLengths.

protected void checkTextLengths(AttributeInterface attribute, AttributeTracer tracer, Lang lang, List<AttributeFieldError> errors) {
    Integer maxLength = this.getMaxLength();
    Integer minLength = this.getMinLength();
    if ((null != maxLength && maxLength > -1) || (null != minLength && minLength > -1)) {
        String text = this.getTextForCheckLength(attribute, lang);
        if (text != null && text.trim().length() > 0) {
            text = text.trim();
            if ((null != maxLength && maxLength > -1) && text.length() > maxLength) {
                AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MAX_LENGTH, tracer);
                error.setMessage("Lang '" + lang.getDescr() + "' -  length " + text.length() + " upper than " + maxLength);
                errors.add(error);
            }
            if ((null != minLength && minLength > -1) && text.length() < minLength) {
                AttributeFieldError error = new AttributeFieldError(attribute, FieldError.INVALID_MIN_LENGTH, tracer);
                error.setMessage("Lang '" + lang.getDescr() + "' -  length " + text.length() + " lower than " + minLength);
                errors.add(error);
            }
        }
    }
}
Also used : AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 10 with AttributeFieldError

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

the class ApiContentInterface method validate.

private List<ApiError> validate(Content content) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        if (null == content.getMainGroup()) {
            errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null", Response.Status.CONFLICT));
        }
        List<FieldError> fieldErrors = content.validate(this.getGroupManager());
        if (null != fieldErrors) {
            for (int i = 0; i < fieldErrors.size(); i++) {
                FieldError fieldError = fieldErrors.get(i);
                if (fieldError instanceof AttributeFieldError) {
                    AttributeFieldError attributeError = (AttributeFieldError) fieldError;
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, attributeError.getFullMessage(), Response.Status.CONFLICT));
                } else {
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, fieldError.getMessage(), Response.Status.CONFLICT));
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating content", t);
        throw new ApsSystemException("Error validating content", t);
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) FieldError(com.agiletec.aps.system.common.entity.model.FieldError) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

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