本文整理汇总了Java中javax.validation.ConstraintValidatorContext类的典型用法代码示例。如果您正苦于以下问题:Java ConstraintValidatorContext类的具体用法?Java ConstraintValidatorContext怎么用?Java ConstraintValidatorContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConstraintValidatorContext类属于javax.validation包,在下文中一共展示了ConstraintValidatorContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateInterestDate
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
private boolean validateInterestDate(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
InterestDate interestDate = (InterestDate) fieldObj.get(validateThis);
Interest interest = (Interest) dependentFieldObj.get(validateThis);
if (interest != null && !interestTypeIsNoInterest(interest.getType())) {
Set<ConstraintViolation<Object>> violations = validator.validate(interestDate);
if (!violations.isEmpty()) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate(getViolationMessages(violations, ctx))
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
}
return true;
}
示例2: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
public boolean isValid(Object value, ConstraintValidatorContext context) {
boolean returnValue = false;
try {
Comparable first = (Comparable) getNestedProperty(value, property);
Object second = getNestedProperty(value, otherProperty);
if (first == null) {
returnValue = true;
} else if (second != null) {
returnValue = doComparison(first, second, comparison);
}
// Wenn first != null und second == null: Prüfung würde NPE bewirken, einfach false zurückgeben.
} catch (Exception e) {
throw new ValidationException("Cannot read property " + property + " and comparison property " + otherProperty);
}
if (!returnValue) {
createViolationMessageForNestedProperty(property, messageTemplate, context);
}
return returnValue;
}
示例3: validateRate
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
private boolean validateRate(Object validateThis,
ConstraintValidatorContext ctx,
Field fieldObj,
Field dependentFieldObj) throws IllegalAccessException {
BigDecimal rate = (BigDecimal) fieldObj.get(validateThis);
Interest.InterestType type = (Interest.InterestType) dependentFieldObj.get(validateThis);
if ((type == null || !interestTypeIsNoInterest(type)) && rate == null) {
ctx.disableDefaultConstraintViolation();
ctx.buildConstraintViolationWithTemplate("may not be null")
.addPropertyNode(field)
.addConstraintViolation();
return false;
}
return true;
}
示例4: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(final String password, final ConstraintValidatorContext context) {
final PasswordValidator validator = new PasswordValidator(singletonList(
new LengthRule(8, 30)
// More rules can be added to increase security
));
final RuleResult result = validator.validate(new PasswordData(password));
if (result.isValid()) {
return true;
}
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(
validator.getMessages(result).stream().collect(joining("\n"))
).addConstraintViolation();
return false;
}
示例5: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(List<String> values, ConstraintValidatorContext context) {
if(values == null || values.isEmpty()) {
return true;
}
for (String val : values) {
boolean valid = false;
for(String cat: categories) {
if(cat.equals(val)) {
valid = true;
}
}
if(!valid) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
return false;
}
}
return true;
}
示例6: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(CountyCourtJudgment ccj, ConstraintValidatorContext context) {
if (ccj == null) {
return true;
}
PaymentOption type = ccj.getPaymentOption();
boolean payByDateIsPopulated = ccj.getPayBySetDate().isPresent();
boolean repaymentPlanIsPopulated = ccj.getRepaymentPlan().isPresent();
boolean isValidImmediately = type.equals(IMMEDIATELY) && !payByDateIsPopulated && !repaymentPlanIsPopulated;
boolean isValidFull = type.equals(FULL_BY_SPECIFIED_DATE) && payByDateIsPopulated && !repaymentPlanIsPopulated;
boolean isValidByInstalments = type.equals(INSTALMENTS) && !payByDateIsPopulated && repaymentPlanIsPopulated;
return isValidImmediately || isValidFull || isValidByInstalments;
}
示例7: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if(value == null) {
return false;
}
check = new SafeguardCheck();
parametros.forEach((parametro) -> check.elementOf(value, parametro).validate());
if(check.hasError()) {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate("(" + value + ") contém caracteres inválidos ")
.addConstraintViolation();
}
return !check.hasError();
}
示例8: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的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;
}
示例9: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
// 不能9位以下纯数字
if (value.matches("^\\d{1,9}")) {
return false;
}
// 不能相同字符组成
if (value.matches("^(.)\\1+$")) {
return false;
}
// 不能由连续字符组成
if (consectiveStr(value)) {
return false;
}
return true;
}
示例10: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
if (null == value) {
return false;
}
Class<?>[] classes = annotation.value();
for(Class<?> cls : classes) {
if (cls.isInstance(value)) {
return true;
}
}
return false;
}
示例11: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (null == value) {
return false;
}
CreditCardType[] types = annotation.value();
for(CreditCardType creditCardType : types) {
CreditCardValidator ccv =
new CreditCardValidator(creditCardType.getInternalValue());
if (ccv.isValid(value)) {
return true;
}
}
return false;
}
示例12: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
if (null == value) {
return false;
}
ParseableType type = annotation.value();
switch (type) {
case TO_INT:
return catcher(value, Integer::parseInt);
case TO_DOUBLE:
return catcher(value, Double::parseDouble);
case TO_LONG:
return catcher(value, Long::parseLong);
case TO_SHORT:
return catcher(value, Short::parseShort);
case TO_FLOAT:
return catcher(value, Float::parseFloat);
}
return false;
}
示例13: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(final String value, final ConstraintValidatorContext context) {
try {
if (StringUtils.isEmpty(value)) {
return true; // do not validate empty value there are other constraints for that e.g. @NotNull, @Size etc...
}
final Path path = Paths.get(value);
if (checkIfExists && !path.toFile().exists()) {
return false;
}
final String fileExt = FilenameUtils.getExtension(value);
return allowableFileExtensions.isEmpty() ||
!allowableFileExtensions.stream().filter(fileExt::equalsIgnoreCase).findFirst().orElse(StringUtils.EMPTY).isEmpty();
} catch (final InvalidPathException e) {
LOGGER.error(e.getMessage(), e);
return false;
}
}
示例14: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
Object fieldValue = new BeanWrapperImpl(value).getPropertyValue(field);
Object fieldMatchValue = new BeanWrapperImpl(value).getPropertyValue(fieldMatch);
boolean result = false;
if(fieldValue != null)
{
//Passwords are kept as char arrays, other values mostly as Strings
if(fieldValue instanceof char[])
result = Arrays.equals((char[])fieldValue, (char[])fieldMatchValue);
else result = fieldValue.equals(fieldMatchValue);
} else
result = fieldMatchValue == null;
return result;
}
示例15: isValid
import javax.validation.ConstraintValidatorContext; //导入依赖的package包/类
@Override
public boolean isValid(MultipartFile[] multipartFiles, ConstraintValidatorContext constraintValidatorContext) {
long _totalSize = 0L;
if (multipartFiles == null || multipartFiles.length <= 0) {
return allowEmpty;
}
boolean result = false;
for (MultipartFile multipartFile : multipartFiles) {
result = (allowSize(multipartFile) && allowContentType(multipartFile));
if (!result) {
return false;
}
_totalSize += multipartFile.getSize();
}
/*
totalSize = 0 ,则不限制
如果超出大小,则限制
*/
return totalSize == 0 || _totalSize < totalSize;
}