当前位置: 首页>>代码示例>>Java>>正文


Java ConstraintValidatorContext类代码示例

本文整理汇总了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;
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:20,代码来源:InterDependentFieldsConstraintValidator.java

示例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;
}
 
开发者ID:dvbern,项目名称:beanvalidation,代码行数:20,代码来源:CompareToValidator.java

示例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;
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:18,代码来源:InterDependentFieldsConstraintValidator.java

示例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;
}
 
开发者ID:membaza,项目名称:users-service,代码行数:20,代码来源:PasswordConstraintValidator.java

示例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;
}
 
开发者ID:Code4SocialGood,项目名称:c4sg-services,代码行数:24,代码来源:ListEntryValidator.java

示例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;
}
 
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:17,代码来源:ValidCountyCourtJudgmentValidator.java

示例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();
}
 
开发者ID:gilmardeveloper,项目名称:java-validator-safeguard,代码行数:18,代码来源:VerifyValidator.java

示例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;
}
 
开发者ID:DevOpsStudio,项目名称:Re-Collector,代码行数:19,代码来源:IsOneOfValidator.java

示例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;
}
 
开发者ID:onsoul,项目名称:os,代码行数:17,代码来源:PasswordValidator.java

示例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;
}
 
开发者ID:nomemory,项目名称:java-bean-validation-extension,代码行数:18,代码来源:InstanceOfValidator.java

示例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;
}
 
开发者ID:nomemory,项目名称:java-bean-validation-extension,代码行数:20,代码来源:CCValidator.java

示例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;
}
 
开发者ID:nomemory,项目名称:java-bean-validation-extension,代码行数:25,代码来源:ParseableValidator.java

示例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;
    }
}
 
开发者ID:cerner,项目名称:jwala,代码行数:23,代码来源:PathValidator.java

示例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;
}
 
开发者ID:Azanx,项目名称:Smart-Shopping,代码行数:17,代码来源:FieldsVerificationValidator.java

示例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;
}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:21,代码来源:MultipartFilesUploadValidate.java


注:本文中的javax.validation.ConstraintValidatorContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。