org.hibernate.validator.cfg.ConstraintMapping Java Examples
The following examples show how to use
org.hibernate.validator.cfg.ConstraintMapping.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BeanValidationImpl.java From cuba with Apache License 2.0 | 6 votes |
protected HibernateValidatorConfiguration getValidatorFactoryConfiguration(Locale locale) { HibernateValidatorConfiguration configuration = Validation.byProvider(HibernateValidator.class) .configure() .clockProvider(new CubaValidationTimeProvider(timeSource)) .traversableResolver(new CubaValidationTraversableResolver(metadata, entityStates)) .messageInterpolator(new CubaValidationMessagesInterpolator(messages, locale)); 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; }
Example #2
Source File: BeanValidation.java From open-Autoscaler with Apache License 2.0 | 5 votes |
public static HibernateValidatorConfiguration getPolicyTriggerRange(HibernateValidatorConfiguration config) { Map<String, Map<String, Map<String, Map<String, String>>>> mulit_range = Constants.getTriggerRangeByTriggerType(); logger.debug("mulit trigger range: " + mulit_range.toString()); for (String class_type : mulit_range.keySet()){ Map<String, Map<String, Map<String, String>>> range = mulit_range.get(class_type); Class<?> class_obj=null; if (class_type.equals("trigger_Memory")) //only one metricType supported now class_obj = PolicyTrigger.class; for (String key : range.keySet()) { Map<String, Map<String, String>> value = range.get(key); for(String value_key : value.keySet()){ Map<String, String> value_item = value.get(value_key); ConstraintMapping mapping = config.createConstraintMapping(); if (value_key.endsWith("Min")){ mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new MinDef().value(Integer.parseInt(value_item.get("value"))).message(value_item.get("message"))); } else if(value_key.endsWith("Max")){ mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new MaxDef().value(Integer.parseInt(value_item.get("value"))).message(value_item.get("message"))); } else if(value_key.endsWith("NotNull")){ mapping.type(class_obj).property(key, ElementType.FIELD).constraint( new NotNullDef().message(value_item.get("message"))); } config.addMapping( mapping ); } } } return config; }
Example #3
Source File: BeanValidationImpl.java From cuba with Apache License 2.0 | 5 votes |
@Override public Validator getValidator(@Nullable ConstraintMapping constraintMapping, ValidationOptions options) { checkNotNullArgument(options); if (constraintMapping == null && options.getFailFast() == null && options.getLocale() != null) { return getValidatorWithDefaultFactory(options.getLocale()); } Locale locale; if (options.getLocale() != null) { locale = options.getLocale(); } else { locale = getCurrentLocale(); } HibernateValidatorConfiguration configuration = getValidatorFactoryConfiguration(locale); if (options.getFailFast() != null) { configuration.failFast(options.getFailFast()); } if (constraintMapping != null) { configuration.addMapping(constraintMapping); } ValidatorFactory factory = configuration.buildValidatorFactory(); return factory.getValidator(); }
Example #4
Source File: InputValidation.java From dremio-oss with Apache License 2.0 | 4 votes |
private ConstraintMapping configureTransforms(ConstraintMapping constraints) { constraints.type(TransformSort.class) .property("sortedColumnName", FIELD).constraint(new NotBlankDef()); // order constraints.type(TransformSorts.class) .property("columns", FIELD).constraint(new NotEmptyDef()); constraints.type(TransformDrop.class) .property("droppedColumnName", FIELD).constraint(new NotBlankDef()); constraints.type(TransformRename.class) .property("oldColumnName", FIELD).constraint(new NotBlankDef()) .property("newColumnName", FIELD).constraint(new NotBlankDef()); constraints.type(TransformAddCalculatedField.class) .property("newColumnName", FIELD).constraint(new NotBlankDef()) .property("expression", FIELD).constraint(new NotBlankDef()); constraints.type(TransformUpdateSQL.class) .property("sql", FIELD).constraint(new NotBlankDef()); constraints.type(TransformField.class) .property("sourceColumnName", FIELD).constraint(new NotBlankDef()) .property("fieldTransformation", FIELD).constraint(new NotNullDef()); // newColumnName // dropSourceColumn constraints.type(FieldConvertTextToDate.class) .property("format", FIELD).constraint(new NotBlankDef()); // optional but one of the date/time types: // .property("desiredType", FIELD).constraint(new ()); constraints.type(TransformConvertToSingleType.class) .property("sourceColumnName", FIELD).constraint(new NotBlankDef()) .property("newColumnName", FIELD).constraint(new NotBlankDef()) .property("dropSourceColumn", FIELD).constraint(new NotNullDef()) .property("desiredType", FIELD).constraint(new NotNullDef()) .property("castWhenPossible", FIELD).constraint(new NotNullDef()) .property("actionForNonMatchingValue", FIELD).constraint(new NotNullDef()); // defaultValue // optional constraints.type(TransformSplitByDataType.class) .property("sourceColumnName", FIELD).constraint(new NotBlankDef()) .property("newColumnNamePrefix", FIELD).constraint(new NotBlankDef()) .property("dropSourceColumn", FIELD).constraint(new NotNullDef()) .property("selectedTypes", FIELD).constraint(new NotEmptyDef()); constraints.type(TransformFilter.class) .property("sourceColumnName", FIELD).constraint(new NotBlankDef()) .property("filter", FIELD).constraint(new NotNullDef()); // keepNull // exclude constraints.type(Dimension.class) .property("column", FIELD).constraint(new NotBlankDef()); constraints.type(Measure.class) .property("column", FIELD).constraint(new NotBlankDef()) .property("type", FIELD).constraint(new NotNullDef()); constraints.type(TransformGroupBy.class).constraint(new TransformGroupByConstraintDef()); return constraints; }
Example #5
Source File: BeanValidationImpl.java From cuba with Apache License 2.0 | 4 votes |
@Override public Validator getValidator(ConstraintMapping constraintMapping) { checkNotNullArgument(constraintMapping); return getValidator(constraintMapping, NO_VALIDATION_OPTIONS); }
Example #6
Source File: TestBeanValidation.java From cuba with Apache License 2.0 | 4 votes |
@Override public Validator getValidator(ConstraintMapping constraintMapping) { return new ValidatorStub(); }
Example #7
Source File: TestBeanValidation.java From cuba with Apache License 2.0 | 4 votes |
@Override public Validator getValidator(@Nullable ConstraintMapping constraintMapping, ValidationOptions options) { return new ValidatorStub(); }
Example #8
Source File: BeanValidation.java From cuba with Apache License 2.0 | 2 votes |
/** * Get validator with custom constraint mapping and current locale if there is current UserSession or with default locale. * * @param constraintMapping constraint mapping * @return validator */ Validator getValidator(ConstraintMapping constraintMapping);
Example #9
Source File: BeanValidation.java From cuba with Apache License 2.0 | 2 votes |
/** * Get validator with custom constraint mapping and additional validation options. * * @param constraintMapping constraint mapping * @param options options * @return validator */ Validator getValidator(@Nullable ConstraintMapping constraintMapping, ValidationOptions options);