Search in sources :

Example 11 with AttributeFieldError

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

the class ApiUserProfileInterface method validate.

private List<ApiError> validate(IUserProfile userProfile) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        List<FieldError> fieldErrors = userProfile.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 profile", t);
        // ApsSystemUtils.logThrowable(t, this, "validate");
        throw new ApsSystemException("Error validating profile", 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)

Example 12 with AttributeFieldError

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

the class EntityActionHelper method scanEntity.

@Override
public void scanEntity(IApsEntity currentEntity, ActionSupport action) {
    try {
        List<AttributeInterface> attributes = currentEntity.getAttributeList();
        for (int i = 0; i < attributes.size(); i++) {
            AttributeInterface entityAttribute = attributes.get(i);
            if (entityAttribute.isActive()) {
                List<AttributeFieldError> errors = entityAttribute.validate(new AttributeTracer());
                if (null != errors && errors.size() > 0) {
                    for (int j = 0; j < errors.size(); j++) {
                        AttributeFieldError attributeFieldError = errors.get(j);
                        AttributeTracer tracer = attributeFieldError.getTracer();
                        AttributeInterface attribute = attributeFieldError.getAttribute();
                        String messageAttributePositionPrefix = this.createErrorMessageAttributePositionPrefix(action, attribute, tracer);
                        AttributeManagerInterface attributeManager = this.getManager(attribute);
                        String errorMessage = attributeManager.getErrorMessage(attributeFieldError, action);
                        String formFieldName = tracer.getFormFieldName(attributeFieldError.getAttribute());
                        action.addFieldError(formFieldName, messageAttributePositionPrefix + " " + errorMessage);
                    }
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error scanning Entity", t);
        throw new RuntimeException("Error scanning Entity", t);
    }
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) AttributeManagerInterface(com.agiletec.apsadmin.system.entity.attribute.manager.AttributeManagerInterface) AttributeInterface(com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)

Example 13 with AttributeFieldError

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

the class MonoListAttribute 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 = (AttributeTracer) tracer.clone();
            elementTracer.setListIndex(i);
            elementTracer.setMonoListElement(true);
            Status elementStatus = attributeElement.getStatus();
            if (elementStatus.equals(Status.EMPTY)) {
                errors.add(new AttributeFieldError(attributeElement, FieldError.INVALID, elementTracer));
            } else {
                List<AttributeFieldError> elementErrors = attributeElement.validate(elementTracer);
                if (null != elementErrors) {
                    errors.addAll(elementErrors);
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating monolist attribute", t);
        throw new RuntimeException("Error validating monolist attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError)

Example 14 with AttributeFieldError

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

the class OgnlValidationRule method validate.

public AttributeFieldError validate(AttributeInterface attribute, AttributeTracer tracer, ILangManager langManager) {
    AttributeFieldError error = null;
    String expression = this.getExpression();
    if (null == expression || expression.trim().length() == 0) {
        return null;
    }
    if (this.isEvalExpressionOnValuedAttribute() && attribute.getStatus().equals(AttributeInterface.Status.EMPTY)) {
        return null;
    }
    try {
        Object expr = Ognl.parseExpression(expression);
        OgnlContext ctx = this.createContextForExpressionValidation(attribute, tracer, langManager);
        Boolean value = (Boolean) Ognl.getValue(expr, ctx, attribute, Boolean.class);
        if (!value) {
            error = new AttributeFieldError(attribute, AttributeFieldError.OGNL_VALIDATION, tracer);
            error.setMessage(this.getErrorMessage());
            error.setMessageKey(this.getErrorMessageKey());
        }
    } catch (OgnlException oe) {
        _logger.error("Error on evaluation of expression : {}", expression, oe);
    } catch (Throwable t) {
        _logger.error("Generic Error on evaluation Ognl Expression : {}", expression, t);
        throw new RuntimeException("Generic Error on evaluation Ognl Expression", t);
    }
    return error;
}
Also used : OgnlException(ognl.OgnlException) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) OgnlContext(ognl.OgnlContext)

Example 15 with AttributeFieldError

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

the class TextAttributeValidationRules 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 {
        List<Lang> langs = langManager.getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            if (!attribute.isMultilingual() && !lang.isDefault())
                continue;
            AttributeTracer textTracer = (AttributeTracer) tracer.clone();
            textTracer.setLang(lang);
            this.checkTextLengths(attribute, textTracer, lang, errors);
            this.checkRegExp(attribute, textTracer, lang, errors);
        }
    } catch (Throwable t) {
        // ApsSystemUtils.logThrowable(t, this, "validate");
        _logger.error("Error validating text attribute", t);
        throw new RuntimeException("Error validating text attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang)

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