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 Detail

      • LOG

        static final org.apache.log4j.Logger LOG
    • 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 given model or Pojo.

        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 validate
        groups - A collection of constraint groups. Each group contains some constraints. 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 groups
        javax.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 given model or Pojo.

        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 validate
        groups - 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 of object named propertyName.
        Parameters:
        object - object to validate
        propertyName - property to validate (i.e. field and getter constraints)
        groups - A collection of constraint groups. Each group contains n constraints. 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 - if object is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
        javax.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 of object named propertyName.
        Parameters:
        object - object to validate
        propertyName - property to validate (ie field and getter constraints)
        groups - group or list of groups targeted for validation (default to javax.validation.groups.Default )
        Returns:
        a set with constraint violations or an empty set if no validation was found.
        Throws:
        java.lang.IllegalArgumentException - if object is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
        javax.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 named propertyName of the class beanType would the property value be value

        ConstraintViolation objects return null for ConstraintViolation.getRootBean() and ConstraintViolation.getLeafBean()

        Parameters:
        beanType - the bean type
        propertyName - property to validate
        value - property value to validate
        groups - A collection of constraint groups. Each group contains n constraints. Use an empty collection for validate agains the default constraints.
        Returns:
        constraint violations or an empty Set if none
        Throws:
        java.lang.IllegalArgumentException - if beanType is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
        javax.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 named propertyName of the class beanType would the property value be value.

        ConstraintViolation objects return null for ConstraintViolation.getRootBean() and ConstraintViolation.getLeafBean().

        Parameters:
        beanType - the bean type
        propertyName - property to validate
        value - property value to validate
        groups - group or list of groups targeted for validation (default to javax.validation.groups.Default )
        Returns:
        constraint violations or an empty Set if none
        Throws:
        java.lang.IllegalArgumentException - if beanType is null, if propertyName null, empty or not a valid object property or if null is passed to the varargs groups
        javax.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 the ConstraintGroupModels 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 active constraint 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 for Validator, since it call no violation should be noticed.
      • 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