Class DefaultValidationService
- java.lang.Object
-
- de.hybris.platform.servicelayer.internal.service.AbstractService
-
- de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
-
- de.hybris.platform.validation.services.impl.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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
AbstractService.SerializableDTO
-
-
Field Summary
Fields Modifier and Type Field Description protected ConstraintViolationFactoryviolationFactory-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
modelService, sessionService, txManager
-
Fields inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
tenant
-
-
Constructor Summary
Constructors Constructor Description DefaultValidationService()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.util.Collection<ConstraintGroupModel>getActiveConstraintGroups()Returns all activeconstraint groupswhich are bound to the current session.protected java.util.Set<java.lang.Class>getClassesForLocalizedAttributeConstraints(java.lang.Object object)protected java.util.Set<java.lang.Class>getClassesForPropertyValidationLocalizedAttributeConstraints(java.lang.Object object)protected java.lang.Class<?>getClassForLocalizedAttributeConstraints(java.lang.Object object)Deprecated, for removal: This API element is subject to removal in a future version.ConstraintGroupModelgetDefaultConstraintGroup()Returns the default constraint group (which is created during creation of eccencial data).protected javax.validation.ConfigurationgetOrCreateConfiguration(boolean replace)protected booleanisMultiLanguageValidationDisabled()protected ConfigurableHybrisConstraintViolationlookupViolation()Deprecated, for removal: This API element is subject to removal in a future version.uselookupViolation(ConstraintViolation)insteadprotected java.util.Set<HybrisConstraintViolation>lookupViolation(javax.validation.ConstraintViolation violation)booleanneedReloadOfValidationEngine(AbstractConstraintModel model)Returnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (ValidationService.reloadValidationEngine()) of the validation engine.voidreloadValidationEngine()Just set a flag , lazy with first validation engine will be reloaded.voidsetActiveConstraintGroups(java.util.Collection<ConstraintGroupModel> groups)Sets the given collection with theConstraintGroupModels to the current session context.voidsetConstraintDao(ConstraintDao constraintDao)voidsetConstraintsExtractor(ConstraintsExtractor constraintsExtractor)voidsetFlexibleSearchService(FlexibleSearchService flexibleSearchService)voidsetLocalizedConstraintsRegistry(LocalizedConstraintsRegistry registry)voidsetViolationFactory(ConstraintViolationFactory violationFactory)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.voidvalidateConstraint(AbstractConstraintModel model)Creates TEST validation configuration using given constraint model.protected java.util.Set<HybrisConstraintViolation>validateLocalizedConstraint(java.lang.Object object, LocalizedAttributeConstraint localizedConstraint, java.lang.Class<?>... groups)method validates theobject's localized attribute defined inlocalizedConstraintin context of provided ingroupsconstraint groups.<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-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractBusinessService
getModelService, getSessionService, getTxManager, setModelService, setSessionService, setTxManager
-
Methods inherited from class de.hybris.platform.servicelayer.internal.service.AbstractService
afterPropertiesSet, getCurrentTenant, setBeanName, setCurrentTenant, writeReplace
-
-
-
-
Field Detail
-
violationFactory
protected ConstraintViolationFactory violationFactory
-
-
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:
reloadValidationEnginein interfaceValidationService
-
needReloadOfValidationEngine
public boolean needReloadOfValidationEngine(AbstractConstraintModel model)
Description copied from interface:ValidationServiceReturnstrueif the given constraint was modified (seeItemModel.getModifiedtime()) after the last reload (ValidationService.reloadValidationEngine()) of the validation engine.- Specified by:
needReloadOfValidationEnginein interfaceValidationService- Parameters:
model- the constraint- Returns:
falseotherwise
-
validateConstraint
public void validateConstraint(AbstractConstraintModel model)
Description copied from interface:ValidationServiceCreates 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:
validateConstraintin interfaceValidationService- Parameters:
model- the constraint
-
validate
public <T> java.util.Set<HybrisConstraintViolation> validate(T object, java.util.Collection<ConstraintGroupModel> groups)
Description copied from interface:ValidationServiceValidates the givenmodelorPojo.If groups aren't provided - this method uses for the validation all constrains which are not in any group.
- Specified by:
validatein interfaceValidationService- 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.
-
validate
public <T> java.util.Set<HybrisConstraintViolation> validate(T object, java.lang.Class<?>... groups)
Description copied from interface:ValidationServiceValidates the givenmodelorPojo.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:
validatein interfaceValidationService- 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.
-
getClassesForLocalizedAttributeConstraints
protected java.util.Set<java.lang.Class> getClassesForLocalizedAttributeConstraints(java.lang.Object object)
-
getClassForLocalizedAttributeConstraints
@Deprecated(since="2005.0", forRemoval=true) protected java.lang.Class<?> getClassForLocalizedAttributeConstraints(java.lang.Object object)Deprecated, for removal: This API element is subject to removal in a future version.
-
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 theobject's localized attribute defined inlocalizedConstraintin context of provided ingroupsconstraint groups. The validation will be performed on localized values of the attribute only for locales defined inlocalizedConstraint.- Parameters:
object- object, which attribute should be validatedlocalizedConstraint- constraint defining the attribute which should be validated and the locales of the attribute that should be validatedgroups- A collection ofconstraint groups. Each group contains nconstraints. 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:ValidationServiceValidates all constraints placed on the property ofobjectnamedpropertyName.- Specified by:
validatePropertyin interfaceValidationService- 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.
-
validateProperty
public <T> java.util.Set<HybrisConstraintViolation> validateProperty(T object, java.lang.String propertyName, java.lang.Class<?>... groups)
Description copied from interface:ValidationServiceValidates all constraints placed on the property ofobjectnamedpropertyName.- Specified by:
validatePropertyin interfaceValidationService- 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.
-
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:ValidationServiceValidates all constraints placed on the property namedpropertyNameof the classbeanTypewould the property value bevalueConstraintViolationobjects return null forConstraintViolation.getRootBean()andConstraintViolation.getLeafBean()- Specified by:
validateValuein interfaceValidationService- 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
-
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:ValidationServiceValidates all constraints placed on the property namedpropertyNameof the classbeanTypewould the property value bevalue.ConstraintViolationobjects return null forConstraintViolation.getRootBean()andConstraintViolation.getLeafBean().- Specified by:
validateValuein interfaceValidationService- 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
-
lookupViolation
protected java.util.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.uselookupViolation(ConstraintViolation)instead
-
getActiveConstraintGroups
public java.util.Collection<ConstraintGroupModel> getActiveConstraintGroups()
Description copied from interface:ValidationServiceReturns all activeconstraint groupswhich are bound to the current session.- Specified by:
getActiveConstraintGroupsin interfaceValidationService- Returns:
- an empty set if no group is set
-
setActiveConstraintGroups
public void setActiveConstraintGroups(java.util.Collection<ConstraintGroupModel> groups)
Description copied from interface:ValidationServiceSets the given collection with theConstraintGroupModels to the current session context. Those groups will be used to validate any given model during modelService.save(...).- Specified by:
setActiveConstraintGroupsin interfaceValidationService- Parameters:
groups- a collection with ConstraintGroupModel
-
unloadValidationEngine
public void unloadValidationEngine()
Description copied from interface:ValidationServiceMethod removes all constraints available forValidator, since it call no violation should be noticed.- Specified by:
unloadValidationEnginein interfaceValidationService
-
getDefaultConstraintGroup
public ConstraintGroupModel getDefaultConstraintGroup()
Description copied from interface:ValidationServiceReturns 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!- Specified by:
getDefaultConstraintGroupin interfaceValidationService
-
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)
-
-