in src/main/java/org/apache/sling/models/validation/impl/ModelValidationImpl.java [86:123]
private RuntimeException validate(@NotNull Resource resource, boolean required) {
try {
ValidationModel validationModel = validation.getValidationModel(resource, true);
if (validationModel == null) {
String error = String.format("Could not find validation model for resource '%s' with type '%s'", resource.getPath(), resource.getResourceType());
if (required) {
return new ValidationException(error);
} else {
log.debug(error);
}
} else {
try {
ValidationResult validationResult = validation.validate(resource, validationModel);
if (!validationResult.isValid()) {
boolean shouldThrow = false;
// evaluate all severities
for (ValidationFailure failure : validationResult.getFailures()) {
if (failure.getSeverity() >= configuration.severityThreshold()) {
shouldThrow = true;
break;
}
}
if (shouldThrow) {
return new InvalidResourceException("Sling Model is invalid", validationResult, resource.getPath());
} else {
log.debug("Although the resource {} is considered invalid by Sling Validation, all validation failures have a severity below the threshold '{}', "
+ "therefore considering this Sling Model valid.", resource.getPath(), configuration.severityThreshold());
}
}
} catch (SlingValidationException e) {
return new ValidationException(e);
}
}
} catch (IllegalStateException e) {
return new ValidationException(e);
}
return null;
}