Search in sources :

Example 1 with ConstraintMapping

use of org.hibernate.validator.cfg.ConstraintMapping in project cuba by cuba-platform.

the class BeanValidationImpl method getValidatorFactoryConfiguration.

protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Supplier<Locale> localeSupplier) {
    HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class).configure().clockProvider(new CubaValidationTimeProvider(timeSource)).traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates)).messageInterpolator(new CubaValidationMessagesInterpolator(messages, localeSupplier));
    ConstraintMapping constraintMapping = configuration.createConstraintMapping();
    // Hibernate validators doesn't support java.sql.Date.
    // Replace standard validators for java.util.Date with support java.sql.Date
    registerPastValidators(constraintMapping.constraintDefinition(Past.class));
    registerPastOrPresentValidators(constraintMapping.constraintDefinition(PastOrPresent.class));
    registerFutureValidators(constraintMapping.constraintDefinition(Future.class));
    registerFutureOrPresentValidators(constraintMapping.constraintDefinition(FutureOrPresent.class));
    configuration.addMapping(constraintMapping);
    return configuration;
}
Also used : ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) FutureOrPresent(javax.validation.constraints.FutureOrPresent) Past(javax.validation.constraints.Past) Future(javax.validation.constraints.Future) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration) CubaValidationTimeProvider(com.haulmont.cuba.core.sys.validation.CubaValidationTimeProvider) CubaValidationTraversableResolver(com.haulmont.cuba.core.sys.validation.CubaValidationTraversableResolver) CubaValidationMessagesInterpolator(com.haulmont.cuba.core.sys.validation.CubaValidationMessagesInterpolator) PastOrPresent(javax.validation.constraints.PastOrPresent)

Example 2 with ConstraintMapping

use of org.hibernate.validator.cfg.ConstraintMapping in project thingsboard by thingsboard.

the class ConstraintValidator method initializeValidators.

private static void initializeValidators() {
    HibernateValidatorConfiguration validatorConfiguration = Validation.byProvider(HibernateValidator.class).configure();
    ConstraintMapping constraintMapping = validatorConfiguration.createConstraintMapping();
    constraintMapping.constraintDefinition(NoXss.class).validatedBy(NoXssValidator.class);
    constraintMapping.constraintDefinition(Length.class).validatedBy(StringLengthValidator.class);
    validatorConfiguration.addMapping(constraintMapping);
    fieldsValidator = validatorConfiguration.buildValidatorFactory().getValidator();
}
Also used : HibernateValidator(org.hibernate.validator.HibernateValidator) ConstraintMapping(org.hibernate.validator.cfg.ConstraintMapping) Length(org.thingsboard.server.common.data.validation.Length) NoXss(org.thingsboard.server.common.data.validation.NoXss) HibernateValidatorConfiguration(org.hibernate.validator.HibernateValidatorConfiguration)

Aggregations

HibernateValidatorConfiguration (org.hibernate.validator.HibernateValidatorConfiguration)2 ConstraintMapping (org.hibernate.validator.cfg.ConstraintMapping)2 CubaValidationMessagesInterpolator (com.haulmont.cuba.core.sys.validation.CubaValidationMessagesInterpolator)1 CubaValidationTimeProvider (com.haulmont.cuba.core.sys.validation.CubaValidationTimeProvider)1 CubaValidationTraversableResolver (com.haulmont.cuba.core.sys.validation.CubaValidationTraversableResolver)1 Future (javax.validation.constraints.Future)1 FutureOrPresent (javax.validation.constraints.FutureOrPresent)1 Past (javax.validation.constraints.Past)1 PastOrPresent (javax.validation.constraints.PastOrPresent)1 HibernateValidator (org.hibernate.validator.HibernateValidator)1 Length (org.thingsboard.server.common.data.validation.Length)1 NoXss (org.thingsboard.server.common.data.validation.NoXss)1