Class DefaultValidationService

  • All Implemented Interfaces:
    ValidationService, java.io.Serializable, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean

    public class DefaultValidationService
    extends AbstractBusinessService
    implements ValidationService
    Validation service which by default use HybrisHibernateValidator. Service exposes two main features: 1) validation methods 2) validation engine reloading
    See Also:
    Serialized Form
    • Constructor Detail

      • DefaultValidationService

        public DefaultValidationService()
    • Method Detail

      • getOrCreateConfiguration

        protected javax.validation.Configuration getOrCreateConfiguration​(boolean replace)
      • reloadValidationEngine

        public void reloadValidationEngine()
        Just set a flag , lazy with first validation engine will be reloaded.
        Specified by:
        reloadValidationEngine in interface ValidationService
      • validateConstraint

        public void validateConstraint​(AbstractConstraintModel model)
        Description copied from interface: ValidationService
        Creates TEST validation configuration using given constraint model. Does NOT influence current configuration of validation engine. When invalid constraint model is given throws ValidationException.
        Specified by:
        validateConstraint in interface ValidationService
        Parameters:
        model - the constraint
      • validate

        public <T> java.util.Set<HybrisConstraintViolation> validate​(T object,
                                                                     java.util.Collection<ConstraintGroupModel> groups)
        Description copied from interface: ValidationService
        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.

        Specified by:
        validate in interface ValidationService
        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.
      • validate

        public <T> java.util.Set<HybrisConstraintViolation> validate​(T object,
                                                                     java.lang.Class<?>... groups)
        Description copied from interface: ValidationService
        Validates the given model or Pojo.

        Same as ValidationService.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.

        Specified by:
        validate in interface ValidationService
        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.
      • getClassesForLocalizedAttributeConstraints

        protected java.util.Set<java.lang.Class> getClassesForLocalizedAttributeConstraints​(java.lang.Object object)
      • getClassesForPropertyValidationLocalizedAttributeConstraints

        protected java.util.Set<java.lang.Class> getClassesForPropertyValidationLocalizedAttributeConstraints​(java.lang.Object object)
      • isMultiLanguageValidationDisabled

        protected boolean isMultiLanguageValidationDisabled()
      • validateLocalizedConstraint

        protected java.util.Set<HybrisConstraintViolation> validateLocalizedConstraint​(java.lang.Object object,
                                                                                       LocalizedAttributeConstraint localizedConstraint,
                                                                                       java.lang.Class<?>... groups)
        method validates the object's localized attribute defined in localizedConstraint in context of provided in groups constraint groups. The validation will be performed on localized values of the attribute only for locales defined in localizedConstraint.
        Parameters:
        object - object, which attribute should be validated
        localizedConstraint - constraint defining the attribute which should be validated and the locales of the attribute that should be validated
        groups - A collection of constraint groups. Each group contains n constraints. Use an empty collection for validate against the default constraints.
        Returns:
        constraint violations or an empty Set if none
      • validateProperty

        public <T> java.util.Set<HybrisConstraintViolation> validateProperty​(T object,
                                                                             java.lang.String propertyName,
                                                                             java.util.Collection<ConstraintGroupModel> groups)
        Description copied from interface: ValidationService
        Validates all constraints placed on the property of object named propertyName.
        Specified by:
        validateProperty in interface ValidationService
        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.
      • validateProperty

        public <T> java.util.Set<HybrisConstraintViolation> validateProperty​(T object,
                                                                             java.lang.String propertyName,
                                                                             java.lang.Class<?>... groups)
        Description copied from interface: ValidationService
        Validates all constraints placed on the property of object named propertyName.
        Specified by:
        validateProperty in interface ValidationService
        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.
      • validateValue

        public <T> java.util.Set<HybrisConstraintViolation> validateValue​(java.lang.Class<T> beanType,
                                                                          java.lang.String propertyName,
                                                                          java.lang.Object value,
                                                                          java.util.Collection<ConstraintGroupModel> groups)
        Description copied from interface: ValidationService
        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()

        Specified by:
        validateValue in interface ValidationService
        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
      • validateValue

        public <T> java.util.Set<HybrisConstraintViolation> validateValue​(java.lang.Class<T> beanType,
                                                                          java.lang.String propertyName,
                                                                          java.lang.Object value,
                                                                          java.lang.Class<?>... groups)
        Description copied from interface: ValidationService
        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().

        Specified by:
        validateValue in interface ValidationService
        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
      • lookupViolation

        protected java.util.Set<HybrisConstraintViolation> lookupViolation​(javax.validation.ConstraintViolation violation)
      • unloadValidationEngine

        public void unloadValidationEngine()
        Description copied from interface: ValidationService
        Method removes all constraints available for Validator, since it call no violation should be noticed.
        Specified by:
        unloadValidationEngine in interface ValidationService
      • setConstraintsExtractor

        public void setConstraintsExtractor​(ConstraintsExtractor constraintsExtractor)
      • setFlexibleSearchService

        public void setFlexibleSearchService​(FlexibleSearchService flexibleSearchService)
      • setConstraintDao

        public void setConstraintDao​(ConstraintDao constraintDao)