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