Class DefaultValidationService

All Implemented Interfaces:
ValidationService, 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:
  • Field Details

  • Constructor Details

    • DefaultValidationService

      public DefaultValidationService()
  • Method Details

    • 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
    • needReloadOfValidationEngine

      public boolean needReloadOfValidationEngine(AbstractConstraintModel model)
      Description copied from interface: ValidationService
      Returns true if the given constraint was modified (see ItemModel.getModifiedtime()) after the last reload (ValidationService.reloadValidationEngine()) of the validation engine.
      Specified by:
      needReloadOfValidationEngine in interface ValidationService
      Parameters:
      model - the constraint
      Returns:
      false otherwise
    • 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> Set<HybrisConstraintViolation> validate(T object, 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> Set<HybrisConstraintViolation> validate(T object, 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 Set<Class> getClassesForLocalizedAttributeConstraints(Object object)
    • getClassForLocalizedAttributeConstraints

      @Deprecated(since="2005.0", forRemoval=true) protected Class<?> getClassForLocalizedAttributeConstraints(Object object)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getClassesForPropertyValidationLocalizedAttributeConstraints

      protected Set<Class> getClassesForPropertyValidationLocalizedAttributeConstraints(Object object)
    • isMultiLanguageValidationDisabled

      protected boolean isMultiLanguageValidationDisabled()
    • validateLocalizedConstraint

      protected Set<HybrisConstraintViolation> validateLocalizedConstraint(Object object, LocalizedAttributeConstraint localizedConstraint, 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> Set<HybrisConstraintViolation> validateProperty(T object, String propertyName, 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> Set<HybrisConstraintViolation> validateProperty(T object, String propertyName, 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> Set<HybrisConstraintViolation> validateValue(Class<T> beanType, String propertyName, Object value, 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> Set<HybrisConstraintViolation> validateValue(Class<T> beanType, String propertyName, Object value, 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 Set<HybrisConstraintViolation> lookupViolation(javax.validation.ConstraintViolation violation)
    • lookupViolation

      @Deprecated(since="2005.0", forRemoval=true) protected ConfigurableHybrisConstraintViolation lookupViolation()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • getActiveConstraintGroups

      public Collection<ConstraintGroupModel> getActiveConstraintGroups()
      Description copied from interface: ValidationService
      Returns all active constraint groups which are bound to the current session.
      Specified by:
      getActiveConstraintGroups in interface ValidationService
      Returns:
      an empty set if no group is set
    • setActiveConstraintGroups

      public void setActiveConstraintGroups(Collection<ConstraintGroupModel> groups)
      Description copied from interface: ValidationService
      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(...).
      Specified by:
      setActiveConstraintGroups in interface ValidationService
      Parameters:
      groups - a collection with ConstraintGroupModel
    • 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
    • getDefaultConstraintGroup

      public ConstraintGroupModel getDefaultConstraintGroup()
      Description copied from interface: ValidationService
      Returns the default constraint group (which is created during creation of eccencial data). This group displays ( ConstraintGroupModel.getConstraints()) all constraints which ARE NOT in any group. Meaning AbstractConstraintModel.getConstraintGroups() returns an empty set. Setting any constraint to this default group or adding this default group to any constraint results in a ModelSavingException! The getInterfaceName() returns always "javax.validation.groups.Default" and the Id returns always "default". Both values cannot be modified!
      Specified by:
      getDefaultConstraintGroup in interface ValidationService
    • setConstraintsExtractor

      public void setConstraintsExtractor(ConstraintsExtractor constraintsExtractor)
    • setFlexibleSearchService

      public void setFlexibleSearchService(FlexibleSearchService flexibleSearchService)
    • setConstraintDao

      public void setConstraintDao(ConstraintDao constraintDao)
    • setLocalizedConstraintsRegistry

      public void setLocalizedConstraintsRegistry(LocalizedConstraintsRegistry registry)
    • setViolationFactory

      public void setViolationFactory(ConstraintViolationFactory violationFactory)