本文整理汇总了Java中org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext类的典型用法代码示例。如果您正苦于以下问题:Java HibernateConstraintValidatorContext类的具体用法?Java HibernateConstraintValidatorContext怎么用?Java HibernateConstraintValidatorContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HibernateConstraintValidatorContext类属于org.hibernate.validator.constraintvalidation包,在下文中一共展示了HibernateConstraintValidatorContext类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final boolean valid = Arrays.asList(strings).contains(value);
if (!valid) {
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.disableDefaultConstraintViolation();
hibernateContext.addExpressionVariable("validValues", Joiner.on(" ").join(strings))
.buildConstraintViolationWithTemplate(hibernateContext.getDefaultConstraintMessageTemplate())
.addConstraintViolation();
}
return valid;
}
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:19,代码来源:IsOneOfValidator.java
示例2: isValidInSession
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
public boolean isValidInSession(Object value, ConstraintValidatorContext context){
if(value == null){
return true;
}
TreeMap<String, Object> fieldMap = _countRows(value);
if(fieldMap != null){
String message = _messageSource.getMessage(context.getDefaultConstraintMessageTemplate(), null, _defaultMesssage, LocaleContextHolder.getLocale());
Map.Entry<String, Object> field = fieldMap.entrySet().iterator().next();
context.unwrap(HibernateConstraintValidatorContext.class)
.addExpressionVariable("name", value.getClass().getSimpleName())
.addExpressionVariable("fullName", value.getClass().getName())
.addExpressionVariable("field", field.getKey())
.addExpressionVariable("value", field.getValue())
.addExpressionVariable("allFields", StringUtils.join(fieldMap.keySet(), ", "))
.addExpressionVariable("values", StringUtils.join(fieldMap.values(), ", "))
.buildConstraintViolationWithTemplate(message)
.addPropertyNode(field.getKey())
.addConstraintViolation()
.disableDefaultConstraintViolation();
return false;
}
return true;
}
开发者ID:Klinton90,项目名称:UniqueValidator,代码行数:27,代码来源:UniqueValidator.java
示例3: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(final CharSequence value,
final ConstraintValidatorContext constraintValidatorContext) {
if (value == null || this.pattern == null) {
return true;
}
if (constraintValidatorContext instanceof HibernateConstraintValidatorContext) {
constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class)
.addMessageParameter("regexp", this.escapedRegexp);
}
final MatchResult match = this.pattern.exec(value.toString());
if (match == null) {
return false;
}
// Must match the entire string
return match.getGroup(0).length() == value.length();
}
开发者ID:ManfredTremmel,项目名称:gwt-bean-validators,代码行数:19,代码来源:PatternValidator.java
示例4: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(final WithId<?> value, final ConstraintValidatorContext context) {
if (value == null) {
return true;
}
final PropertyAccessor bean = new BeanWrapperImpl(value);
final String propertyValue = String.valueOf(bean.getPropertyValue(property));
@SuppressWarnings({"rawtypes", "unchecked"})
final Class<WithId> modelClass = (Class) value.getKind().modelClass;
@SuppressWarnings("unchecked")
final Set<String> ids = dataManager.fetchIdsByPropertyValue(modelClass, property, propertyValue);
final boolean isUnique = ids.isEmpty() || value.getId().map(id -> ids.contains(id)).orElse(false);
if (!isUnique) {
if (ids.stream().allMatch(id -> consideredValidByException(modelClass, id))) {
return true;
}
context.disableDefaultConstraintViolation();
context.unwrap(HibernateConstraintValidatorContext.class).addExpressionVariable("nonUnique", propertyValue)
.buildConstraintViolationWithTemplate(context.getDefaultConstraintMessageTemplate())
.addPropertyNode(property).addConstraintViolation();
}
return isUnique;
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:32,代码来源:UniquePropertyValidator.java
示例5: shouldAscertainPropertyUniqueness
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Test
public void shouldAscertainPropertyUniqueness() {
final HibernateConstraintValidatorContext context = mock(HibernateConstraintValidatorContext.class);
when(context.unwrap(HibernateConstraintValidatorContext.class)).thenReturn(context);
when(context.addExpressionVariable(eq("nonUnique"), anyString())).thenReturn(context);
when(context.getDefaultConstraintMessageTemplate()).thenReturn("template");
final ConstraintViolationBuilder builder = mock(ConstraintViolationBuilder.class);
when(context.buildConstraintViolationWithTemplate("template")).thenReturn(builder);
when(builder.addPropertyNode(anyString())).thenReturn(mock(NodeBuilderCustomizableContext.class));
assertThat(validator.isValid(connection, context)).isEqualTo(validity);
}
开发者ID:syndesisio,项目名称:syndesis,代码行数:13,代码来源:UniquePropertyValidatorTest.java
示例6: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDate value, ConstraintValidatorContext context) {
// null values are valid
if (value == null) {
return true;
}
TimeProvider timeProvider = context.unwrap(HibernateConstraintValidatorContext.class)
.getTimeProvider();
long now = timeProvider.getCurrentTime();
final LocalDate localDate = Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault())
.toLocalDate();
return localDate
.isBefore(value) || localDate.isEqual(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:16,代码来源:PresentOrFutureValidatorForLocalDate.java
示例7: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDate value, ConstraintValidatorContext context) {
// null values are valid
if (value == null) {
return true;
}
TimeProvider timeProvider = context.unwrap(HibernateConstraintValidatorContext.class)
.getTimeProvider();
long now = timeProvider.getCurrentTime();
return Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault())
.toLocalDate()
.isBefore(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:15,代码来源:FutureValidatorForLocalDate.java
示例8: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDateTime value, ConstraintValidatorContext constraintValidatorContext) {
if(value ==null){
return true;
}
TimeProvider timeProvider=constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class).getTimeProvider();
long now=timeProvider.getCurrentTime();
final LocalDateTime localDateTime = Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault()).toLocalDateTime();
return localDateTime.isBefore(value) || localDateTime.isEqual(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:12,代码来源:PresentOrFutureValidatorForLocalDateTime.java
示例9: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDateTime value, ConstraintValidatorContext constraintValidatorContext) {
if (value == null) {
return true;
}
TimeProvider timeProvider = constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class).getTimeProvider();
long now = timeProvider.getCurrentTime();
final LocalDate localDate = Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault())
.toLocalDate();
final LocalDateTime localDateTime = LocalDateTime.of(localDate, LocalTime.MIN);
return localDateTime.isBefore(value) || localDateTime.isEqual(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:14,代码来源:StartOfTodayOrFutureValidatorForLocalDateTime.java
示例10: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDateTime value, ConstraintValidatorContext constraintValidatorContext) {
if (value == null) {
return true;
}
TimeProvider timeProvider = constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class).getTimeProvider();
long now = timeProvider.getCurrentTime();
return Instant.ofEpochMilli(now).atZone(ZoneId.systemDefault()).toLocalDateTime().isBefore(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:10,代码来源:FutureValidatorForLocalDateTime.java
示例11: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDate value, ConstraintValidatorContext context) {
// null values are valid
if (value == null) {
return true;
}
TimeProvider timeProvider = context.unwrap(HibernateConstraintValidatorContext.class)
.getTimeProvider();
long now = timeProvider.getCurrentTime();
final LocalDate localDate = Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault())
.toLocalDate();
return localDate
.isAfter(value) || localDate.isEqual(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:16,代码来源:PastOrPresentValidatorForLocalDate.java
示例12: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDateTime value, ConstraintValidatorContext constraintValidatorContext) {
if (value == null) {
return true;
}
TimeProvider timeProvider = constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class).getTimeProvider();
long now = timeProvider.getCurrentTime();
final LocalDateTime localDateTime = Instant.ofEpochMilli(now).atZone(ZoneId.systemDefault()).toLocalDateTime();
return localDateTime.isAfter(value) || localDateTime.isEqual(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:11,代码来源:PastOrPresentValidatorForLocalDateTime.java
示例13: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDate value, ConstraintValidatorContext context) {
// null values are valid
if (value == null) {
return true;
}
TimeProvider timeProvider = context.unwrap(HibernateConstraintValidatorContext.class)
.getTimeProvider();
long now = timeProvider.getCurrentTime();
return Instant.ofEpochMilli(now)
.atZone(ZoneId.systemDefault())
.toLocalDate()
.isAfter(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:15,代码来源:PastValidatorForLocalDate.java
示例14: assertNoLat
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void assertNoLat(ConstraintValidatorContext context) {
ConstraintViolationCreationContext x = ((ConstraintValidatorContextImpl) context.unwrap(HibernateConstraintValidatorContext.class)).getConstraintViolationCreationContexts().get(0);
Map<String, Object> ev = x.getExpressionVariables();
assertEquals(2, ev.size());
Set<String> contains = (Set<String>) ev.get("containsSet");
assertThat(contains, containsInAnyOrder("long", "within"));
Set<String> missing = (Set<String>) ev.get("missingSet");
assertThat(missing, containsInAnyOrder("lat"));
assertEquals("{message}", x.getMessage());
}
开发者ID:NWQMC,项目名称:WQP-WQX-Services,代码行数:12,代码来源:PointLocationValidatorTest.java
示例15: assertNoLong
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void assertNoLong(ConstraintValidatorContext context) {
ConstraintViolationCreationContext x = ((ConstraintValidatorContextImpl) context.unwrap(HibernateConstraintValidatorContext.class)).getConstraintViolationCreationContexts().get(0);
Map<String, Object> ev = x.getExpressionVariables();
assertEquals(2, ev.size());
Set<String> contains = (Set<String>) ev.get("containsSet");
assertThat(contains, containsInAnyOrder("lat", "within"));
Set<String> missing = (Set<String>) ev.get("missingSet");
assertThat(missing, containsInAnyOrder("long"));
assertEquals("{message}", x.getMessage());
}
开发者ID:NWQMC,项目名称:WQP-WQX-Services,代码行数:12,代码来源:PointLocationValidatorTest.java
示例16: assertNoWithin
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void assertNoWithin(ConstraintValidatorContext context) {
ConstraintViolationCreationContext x = ((ConstraintValidatorContextImpl) context.unwrap(HibernateConstraintValidatorContext.class)).getConstraintViolationCreationContexts().get(0);
Map<String, Object> ev = x.getExpressionVariables();
assertEquals(2, ev.size());
Set<String> contains = (Set<String>) ev.get("containsSet");
assertThat(contains, containsInAnyOrder("lat", "long"));
Set<String> missing = (Set<String>) ev.get("missingSet");
assertThat(missing, containsInAnyOrder("within"));
assertEquals("{message}", x.getMessage());
}
开发者ID:NWQMC,项目名称:WQP-WQX-Services,代码行数:12,代码来源:PointLocationValidatorTest.java
示例17: setMessageTemplate
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
private void setMessageTemplate(ConstraintValidatorContext context, String messageTemplate, String value) {
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.disableDefaultConstraintViolation();
hibernateContext.addExpressionVariable("value", value).buildConstraintViolationWithTemplate(messageTemplate).addConstraintViolation();
}
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:6,代码来源:FileInputConfigurationValidator.java
示例18: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(LocalDateTime value, ConstraintValidatorContext constraintValidatorContext) {
TimeProvider timeProvider= constraintValidatorContext.unwrap(HibernateConstraintValidatorContext.class).getTimeProvider();
long now=timeProvider.getCurrentTime();
return Instant.ofEpochMilli(now).atZone(ZoneId.systemDefault()).toLocalDateTime().isAfter(value);
}
开发者ID:bhits,项目名称:common-libraries,代码行数:7,代码来源:PastValidatorForLocalDateTime.java
示例19: isValid
import org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(FilterParameters value, ConstraintValidatorContext context) {
if (value == null) {
return true;
}
SortedSet<String> containsSet = new TreeSet<String>();
SortedSet<String> missingSet = new TreeSet<String>();
if (StringUtils.isBlank(value.getLat())) {
missingSet.add(Parameters.LATITUDE.toString());
} else {
containsSet.add(Parameters.LATITUDE.toString());
}
if (StringUtils.isBlank(value.getLong())) {
missingSet.add(Parameters.LONGITUDE.toString());
} else {
containsSet.add(Parameters.LONGITUDE.toString());
}
if (StringUtils.isBlank(value.getWithin())) {
missingSet.add(Parameters.WITHIN.toString());
} else {
containsSet.add(Parameters.WITHIN.toString());
}
if (containsSet.size() > 0 && missingSet.size() > 0) {
HibernateConstraintValidatorContext hibernateContext = context.unwrap(HibernateConstraintValidatorContext.class);
hibernateContext.disableDefaultConstraintViolation();
hibernateContext
.addExpressionVariable("containsSet", containsSet)
.addExpressionVariable("missingSet", missingSet)
.buildConstraintViolationWithTemplate("{message}")
.addConstraintViolation();
return false;
} else {
return true;
}
}
开发者ID:NWQMC,项目名称:WQP-WQX-Services,代码行数:43,代码来源:PointLocationValidator.java
注:本文中的org.hibernate.validator.constraintvalidation.HibernateConstraintValidatorContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论