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;
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations