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