use of com.haulmont.restapi.exception.ConstraintViolationInfo in project cuba by cuba-platform.
the class RestControllerExceptionHandler method handleCustomValidationException.
@ExceptionHandler(CustomValidationException.class)
@ResponseBody
public ResponseEntity<List<ConstraintViolationInfo>> handleCustomValidationException(CustomValidationException e) {
log.debug("CustomValidationException: {}", e.getMessage());
ConstraintViolationInfo errorInfo = new ConstraintViolationInfo();
errorInfo.setPath("");
errorInfo.setInvalidValue(null);
errorInfo.setMessage(e.getLocalizedMessage());
errorInfo.setMessageTemplate("{com.haulmont.cuba.core.global.validation.CustomValidationException}");
return new ResponseEntity<>(Collections.singletonList(errorInfo), HttpStatus.BAD_REQUEST);
}
use of com.haulmont.restapi.exception.ConstraintViolationInfo in project cuba by cuba-platform.
the class RestControllerExceptionHandler method getConstraintViolationInfos.
protected List<ConstraintViolationInfo> getConstraintViolationInfos(Set<ConstraintViolation<?>> violations) {
List<ConstraintViolationInfo> violationInfos = new ArrayList<>();
for (ConstraintViolation<?> violation : violations) {
ConstraintViolationInfo info = new ConstraintViolationInfo();
info.setMessage(violation.getMessage());
info.setMessageTemplate(violation.getMessageTemplate());
Object invalidValue = violation.getInvalidValue();
if (invalidValue != null) {
Class<?> invalidValueClass = invalidValue.getClass();
boolean serializable = false;
for (Class serializableType : serializableInvalidValueTypes) {
// noinspection unchecked
if (serializableType.isAssignableFrom(invalidValueClass)) {
serializable = true;
break;
}
}
if (serializable) {
info.setInvalidValue(invalidValue);
} else {
info.setInvalidValue(null);
}
}
if (violation.getPropertyPath() != null) {
info.setPath(violation.getPropertyPath().toString());
}
violationInfos.add(info);
}
return violationInfos;
}
Aggregations