Interface ValidationService
-
- All Known Implementing Classes:
DefaultValidationService
public interface ValidationService
The hybris validation service validatesmodels
or Pojo's (plain old java objects) againsconstraints
. UsevalidationService.validate(yourModel)
to validate this model against all constraints in the system which ARE NOT in any group (default) or usevalidationService.validate(yourModel, Collection<ConstraintGroupModel>)
to validate this model against a configuredconstraint groups
(which contains constraints).- Spring Bean ID:
- validationService
-
-
Field Summary
Fields Modifier and Type Field Description static org.apache.log4j.Logger
LOG
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Collection<ConstraintGroupModel>
getActiveConstraintGroups()
Returns all activeconstraint groups
which are bound to the current session.ConstraintGroupModel
getDefaultConstraintGroup()
Returns the default constraint group (which is created during creation of eccencial data).boolean
needReloadOfValidationEngine(AbstractConstraintModel model)
Returnstrue
if the given constraint was modified (seeItemModel.getModifiedtime()
) after the last reload (reloadValidationEngine()
) of the validation engine.void
reloadValidationEngine()
Reloads the validation engine using current validation provider.void
setActiveConstraintGroups(java.util.Collection<ConstraintGroupModel> groups)
Sets the given collection with theConstraintGroupModel
s to the current session context.void
unloadValidationEngine()
Method removes all constraints available forValidator
, since it call no violation should be noticed.<T> java.util.Set<HybrisConstraintViolation>
validate(T object, java.lang.Class<?>... groups)
Validates the givenmodel
orPojo
.<T> java.util.Set<HybrisConstraintViolation>
validate(T object, java.util.Collection<ConstraintGroupModel> groups)
Validates the givenmodel
orPojo
.default void
validateConstraint(AbstractConstraintModel model)
Creates TEST validation configuration using given constraint model.<T> java.util.Set<HybrisConstraintViolation>
validateProperty(T object, java.lang.String propertyName, java.lang.Class<?>... groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.<T> java.util.Set<HybrisConstraintViolation>
validateProperty(T object, java.lang.String propertyName, java.util.Collection<ConstraintGroupModel> groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.<T> java.util.Set<HybrisConstraintViolation>
validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
.<T> java.util.Set<HybrisConstraintViolation>
validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.util.Collection<ConstraintGroupModel> groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
-
-
-
Method Detail
-
reloadValidationEngine
void reloadValidationEngine()
Reloads the validation engine using current validation provider. After changing constraints or constraint groups this method should always be called!
-
validate
<T> java.util.Set<HybrisConstraintViolation> validate(T object, java.util.Collection<ConstraintGroupModel> groups)
Validates the givenmodel
orPojo
.If groups aren't provided - this method uses for the validation all constrains which are not in any group.
- Parameters:
object
- the Model or Pojo to validategroups
- A collection ofconstraint groups
. Each group contains someconstraints
. Use an empty collection for validate agains the default constraints.- Returns:
- a set with
ConstraintViolation
s or an empty set if no validation was found. - Throws:
java.lang.IllegalArgumentException
- if object is null or if null is passed to the groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
validate
<T> java.util.Set<HybrisConstraintViolation> validate(T object, java.lang.Class<?>... groups)
Validates the givenmodel
orPojo
.Same as
validate(Object, Collection)
but here the constraint group interfaces must be provided. If not constraint group interface is provided the default constraint group is asumed per default.- Parameters:
object
- the model or pojo to validategroups
- a class array which contains the group marker interfaces.- Returns:
- a set with constraint violations or an empty set if no validation was found.
-
validateProperty
<T> java.util.Set<HybrisConstraintViolation> validateProperty(T object, java.lang.String propertyName, java.util.Collection<ConstraintGroupModel> groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.- Parameters:
object
- object to validatepropertyName
- property to validate (i.e. field and getter constraints)groups
- A collection ofconstraint groups
. Each group contains nconstraints
. Use an empty collection for validate agains the default constraints.- Returns:
- a set with constraint violations or an empty set if no validation was found.
- Throws:
java.lang.IllegalArgumentException
- ifobject
is null, ifpropertyName
null, empty or not a valid object property or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
validateProperty
<T> java.util.Set<HybrisConstraintViolation> validateProperty(T object, java.lang.String propertyName, java.lang.Class<?>... groups)
Validates all constraints placed on the property ofobject
namedpropertyName
.- Parameters:
object
- object to validatepropertyName
- property to validate (ie field and getter constraints)groups
- group or list of groups targeted for validation (default tojavax.validation.groups.Default
)- Returns:
- a set with constraint violations or an empty set if no validation was found.
- Throws:
java.lang.IllegalArgumentException
- ifobject
is null, ifpropertyName
null, empty or not a valid object property or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
validateValue
<T> java.util.Set<HybrisConstraintViolation> validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.util.Collection<ConstraintGroupModel> groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
ConstraintViolation
objects return null forConstraintViolation.getRootBean()
andConstraintViolation.getLeafBean()
- Parameters:
beanType
- the bean typepropertyName
- property to validatevalue
- property value to validategroups
- A collection ofconstraint groups
. Each group contains nconstraints
. Use an empty collection for validate agains the default constraints.- Returns:
- constraint violations or an empty Set if none
- Throws:
java.lang.IllegalArgumentException
- ifbeanType
is null, ifpropertyName
null, empty or not a valid object property or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
validateValue
<T> java.util.Set<HybrisConstraintViolation> validateValue(java.lang.Class<T> beanType, java.lang.String propertyName, java.lang.Object value, java.lang.Class<?>... groups)
Validates all constraints placed on the property namedpropertyName
of the classbeanType
would the property value bevalue
.ConstraintViolation
objects return null forConstraintViolation.getRootBean()
andConstraintViolation.getLeafBean()
.- Parameters:
beanType
- the bean typepropertyName
- property to validatevalue
- property value to validategroups
- group or list of groups targeted for validation (default tojavax.validation.groups.Default
)- Returns:
- constraint violations or an empty Set if none
- Throws:
java.lang.IllegalArgumentException
- ifbeanType
is null, ifpropertyName
null, empty or not a valid object property or if null is passed to the varargs groupsjavax.validation.ValidationException
- if a non recoverable error happens during the validation process
-
setActiveConstraintGroups
void setActiveConstraintGroups(java.util.Collection<ConstraintGroupModel> groups)
Sets the given collection with theConstraintGroupModel
s to the current session context. Those groups will be used to validate any given model during modelService.save(...).- Parameters:
groups
- a collection with ConstraintGroupModel
-
getActiveConstraintGroups
java.util.Collection<ConstraintGroupModel> getActiveConstraintGroups()
Returns all activeconstraint groups
which are bound to the current session.- Returns:
- an empty set if no group is set
-
unloadValidationEngine
void unloadValidationEngine()
Method removes all constraints available forValidator
, since it call no violation should be noticed.
-
getDefaultConstraintGroup
ConstraintGroupModel getDefaultConstraintGroup()
Returns the default constraint group (which is created during creation of eccencial data). This group displays (ConstraintGroupModel.getConstraints()
) allconstraints
which ARE NOT in any group. MeaningAbstractConstraintModel.getConstraintGroups()
returns an empty set. Setting any constraint to this default group or adding this default group to any constraint results in aModelSavingException
! ThegetInterfaceName()
returns always "javax.validation.groups.Default" and theId
returns always "default". Both values cannot be modified!
-
needReloadOfValidationEngine
boolean needReloadOfValidationEngine(AbstractConstraintModel model)
Returnstrue
if the given constraint was modified (seeItemModel.getModifiedtime()
) after the last reload (reloadValidationEngine()
) of the validation engine.- Parameters:
model
- the constraint- Returns:
false
otherwise
-
validateConstraint
default void validateConstraint(AbstractConstraintModel model)
Creates TEST validation configuration using given constraint model. Does NOT influence current configuration of validation engine. When invalid constraint model is given throws ValidationException.- Parameters:
model
- the constraint
-
-