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;
}
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();
}
Aggregations