Interface ValidationService
-
- All Known Implementing Classes:
DefaultValidationService
public interface ValidationServiceThe hybris validation service validatesmodelsor 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.LoggerLOG
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.Collection<ConstraintGroupModel>getActiveConstraintGroups()Returns all activeconstraint groupswhich are bound to the current session.ConstraintGroupModelgetDefaultConstraintGroup()Returns the default constraint group (which is created during creation of eccencial data).booleanneedReloadOfValidationEngine(AbstractConstraintModel model)Returnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (reloadValidationEngine()) of the validation engine.voidreloadValidationEngine()Reloads the validation engine using current validation provider.voidsetActiveConstraintGroups(java.util.Collection<ConstraintGroupModel> groups)Sets the given collection with theConstraintGroupModels to the current session context.voidunloadValidationEngine()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 givenmodelorPojo.<T> java.util.Set<HybrisConstraintViolation>validate(T object, java.util.Collection<ConstraintGroupModel> groups)Validates the givenmodelorPojo.default voidvalidateConstraint(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 ofobjectnamedpropertyName.<T> java.util.Set<HybrisConstraintViolation>validateProperty(T object, java.lang.String propertyName, java.util.Collection<ConstraintGroupModel> groups)Validates all constraints placed on the property ofobjectnamedpropertyName.<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 namedpropertyNameof the classbeanTypewould 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 namedpropertyNameof the classbeanTypewould 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 givenmodelorPojo.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
ConstraintViolations 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 givenmodelorPojo.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 ofobjectnamedpropertyName.- 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- ifobjectis null, ifpropertyNamenull, 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 ofobjectnamedpropertyName.- 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- ifobjectis null, ifpropertyNamenull, 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 namedpropertyNameof the classbeanTypewould the property value bevalueConstraintViolationobjects 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- ifbeanTypeis null, ifpropertyNamenull, 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 namedpropertyNameof the classbeanTypewould the property value bevalue.ConstraintViolationobjects 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- ifbeanTypeis null, ifpropertyNamenull, 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 theConstraintGroupModels 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 groupswhich 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()) allconstraintswhich 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 theIdreturns always "default". Both values cannot be modified!
-
needReloadOfValidationEngine
boolean needReloadOfValidationEngine(AbstractConstraintModel model)
Returnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (reloadValidationEngine()) of the validation engine.- Parameters:
model- the constraint- Returns:
falseotherwise
-
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
-
-