Interface ValidationService
- All Known Implementing Classes:
DefaultValidationService
public interface ValidationService
The hybris validation service validates
models or Pojo's (plain old java objects) agains
constraints. Use validationService.validate(yourModel) to validate this
model against all constraints in the system which ARE NOT in any group (default) or use
validationService.validate(yourModel, Collection<ConstraintGroupModel>) to validate this model
against a configured constraint groups (which contains constraints).- Spring Bean ID:
- validationService
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionReturns all activeconstraint groupswhich are bound to the current session.Returns the default constraint group (which is created during creation of eccencial data).booleanReturnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (reloadValidationEngine()) of the validation engine.voidReloads the validation engine using current validation provider.voidSets the given collection with theConstraintGroupModels to the current session context.voidMethod removes all constraints available forValidator, since it call no violation should be noticed.Validates the givenmodelorPojo.validate(T object, Collection<ConstraintGroupModel> groups) Validates the givenmodelorPojo.default voidCreates TEST validation configuration using given constraint model.validateProperty(T object, String propertyName, Class<?>... groups) Validates all constraints placed on the property ofobjectnamedpropertyName.validateProperty(T object, String propertyName, Collection<ConstraintGroupModel> groups) Validates all constraints placed on the property ofobjectnamedpropertyName.validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) Validates all constraints placed on the property namedpropertyNameof the classbeanTypewould the property value bevalue.validateValue(Class<T> beanType, String propertyName, Object value, Collection<ConstraintGroupModel> groups) Validates all constraints placed on the property namedpropertyNameof the classbeanTypewould the property value bevalue
-
Field Details
-
LOG
static final org.apache.log4j.Logger LOG
-
-
Method Details
-
reloadValidationEngine
void reloadValidationEngine()Reloads the validation engine using current validation provider. After changing constraints or constraint groups this method should always be called! -
validate
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:
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
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> Set<HybrisConstraintViolation> validateProperty(T object, String propertyName, 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:
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> Set<HybrisConstraintViolation> validateProperty(T object, String propertyName, 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:
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> Set<HybrisConstraintViolation> validateValue(Class<T> beanType, String propertyName, Object value, 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:
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> Set<HybrisConstraintViolation> validateValue(Class<T> beanType, String propertyName, Object value, 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:
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
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
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
Returnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (reloadValidationEngine()) of the validation engine.- Parameters:
model- the constraint- Returns:
falseotherwise
-
validateConstraint
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
-