Package org.apache.sling.validation

# Interface ValidationService

@ProviderType public interface ValidationService
The `ValidationService` provides methods for finding `ValidationModel`s and to trigger validations against those.

## Method Summary

Modifier and Type
Method
Description
`@Nullable ValidationModel`
`getValidationModel(@NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels)`
Tries to obtain a `ValidationModel` that is able to validate a `Resource` of type `validatedResourceType`.
`@Nullable ValidationModel`
`getValidationModel(@NotNull org.apache.sling.api.resource.Resource resource, boolean considerResourceSuperTypeModels)`
Tries to obtain a `ValidationModel` that is able to validate the given `resource`.
`@NotNull ValidationResult`
`validate(@NotNull org.apache.sling.api.resource.Resource resource, @NotNull ValidationModel model)`
Validates a `Resource` using a specific `ValidationModel`.
`@NotNull ValidationResult`
`validate(@NotNull org.apache.sling.api.resource.ValueMap valueMap, @NotNull ValidationModel model)`
Validates a `ValueMap` or any object adaptable to a `ValueMap` using a specific `ValidationModel`.
`@NotNull ValidationResult`
`validateResourceRecursively(@NotNull org.apache.sling.api.resource.Resource resource, boolean enforceValidation, Predicate<org.apache.sling.api.resource.Resource> filter, boolean considerResourceSuperTypeModels)`
Validates a `Resource` and all child resources recursively by traversing through the resource tree starting from the given resource.

## Method Details

### getValidationModel

@Nullable @Nullable ValidationModel getValidationModel(@NotNull @NotNull String validatedResourceType, String resourcePath, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException
Tries to obtain a `ValidationModel` that is able to validate a `Resource` of type `validatedResourceType`.

Parameters:
  `validatedResourceType` - the type of `Resources` the model validates, should be either relative (i.e. not start with a "/") or starting with one of the resource resolver's search paths
  `resourcePath` - the path of the validated resource, may be `null` or empty. Must match the applicablePath property of the model
  `considerResourceSuperTypeModels` - if `true` will also consider the validation model of the resource super type (recursively), otherwise not.
Returns:
  a `ValidationModel` if one is found, `null` otherwise
Throws:
  `IllegalStateException` - in case an invalid validation model was found
  `IllegalArgumentException` - in case validatedResourceType was blank, `null` or absolute but outside of the search paths or some other error occurred while retrieving the models.

### getValidationModel

@Nullable @Nullable ValidationModel getValidationModel(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException
Tries to obtain a `ValidationModel` that is able to validate the given `resource`.

Parameters:
  `resource` - the resource for which to obtain a validation model
  `considerResourceSuperTypeModels` - if `true` will also consider the validation model of the resource super type (recursively), otherwise not.
Returns:
  a `ValidationModel` if one is found, `null` otherwise
Throws:
  `IllegalStateException` - in case an invalid validation model was found
  `IllegalArgumentException` - in case resourceType being set on the given resource is blank, not set or absolute but outside of the search paths or some other error occurred while retrieving the models.

### validate

@NotNull @NotNull ValidationResult validate(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, @NotNull @NotNull ValidationModel model) throws SlingValidationException, IllegalStateException
Validates a `Resource` using a specific `ValidationModel`. If the `model` describes a resource tree, the `ResourceResolver` associated with the `resource` will be used for retrieving information about the `resource`'s descendants.

Parameters:
  `resource` - the resource to validate
  `model` - the model with which to perform the validation
Returns:
  a `ValidationResult` that provides the necessary information
Throws:
  `SlingValidationException` - if one validator was called with invalid arguments
  `IllegalStateException` - if a validator id referenced in the given model could not be resolved

### validate

@NotNull @NotNull ValidationResult validate(@NotNull @NotNull org.apache.sling.api.resource.ValueMap valueMap, @NotNull @NotNull ValidationModel model) throws SlingValidationException
Validates a `ValueMap` or any object adaptable to a `ValueMap` using a specific `ValidationModel`. Since the `valueMap` only contains the direct properties of the adapted object, the `model`'s descendants description should not be queried for this validation operation.

Parameters:
  `valueMap` - the map to validate
  `model` - the model with which to perform the validation
Returns:
  a `ValidationResult` that provides the necessary information
Throws:
  `SlingValidationException` - if one validator was called with invalid arguments

### validateResourceRecursively

@NotNull @NotNull ValidationResult validateResourceRecursively(@NotNull @NotNull org.apache.sling.api.resource.Resource resource, boolean enforceValidation, Predicate<org.apache.sling.api.resource.Resource> filter, boolean considerResourceSuperTypeModels) throws IllegalStateException, IllegalArgumentException, SlingValidationException
Validates a `Resource` and all child resources recursively by traversing through the resource tree starting from the given resource. For all resources which are included in the given `filter` the according `ValidationModel` is retrieved and validation is called on those resources.

Parameters:
  `resource` - the root resource which is validated
  `enforceValidation` - if `true` will throw an `IllegalArgumentException` in case a validation model could not be found for a (not-ignored) resource
  `filter` - a `Predicate` on a resource which is evaluated to determine whether a given resource should be validated. May be `null` in which case all resources are validated. Children of ignored resources are still validated (if this predicate applies to them).
  `considerResourceSuperTypeModels` - if `true` will also consider the validation model of the resource super type (recursively), otherwise not.
Returns:
  the aggregated `ValidationResult` over all child resource validations
Throws:
  `IllegalStateException` - in case an invalid validation model was found
  `IllegalArgumentException` - in case resourceType is absolute but outside of the search paths or if no validation model could be found (and enforceValidation is `true`).
  `SlingValidationException` - if one validator was called with invalid arguments