org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl Java Examples

The following examples show how to use org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl. 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: ContentCheckConstraintValidator.java    From onetwo with Apache License 2.0 6 votes vote down vote up
@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (StringUtils.isBlank(value)) {
			return true;
		}
		List<String> sentitiveWords = getContentChecker().check(value);
		if (LangUtils.isEmpty(sentitiveWords)) {
			return true;
		}
		ConstraintValidatorContextImpl ctx = (ConstraintValidatorContextImpl)context;
		
		// 这种方法虽然可以动态显示错误信息,但是无法把错误信息放到i18n国际化资源文件里
//		ctx.addExpressionVariable("invalidWords", StringUtils.join(sentitiveWords, ", "));
//		ctx.buildConstraintViolationWithTemplate("${invalidWords}").addConstraintViolation();
		
		Map<String, Object> newAttributes = Maps.newHashMap(ctx.getConstraintDescriptor().getAttributes());
		newAttributes.put("invalidWords", StringUtils.join(sentitiveWords, ", "));
		ConfigurablePropertyAccessor constraintDescriptor = SpringUtils.newPropertyAccessor(ctx.getConstraintDescriptor(), true);
		constraintDescriptor.setPropertyValue("attributes", newAttributes);
		return false;
	}
 
Example #2
Source File: AbstractValidatorTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
ConstraintViolationBuilder getConstraintViolationBuilder() {
    return new ConstraintValidatorContextImpl(null,
            PathImpl.createRootPath(),
            new DummyConstraintDescriptor(),
            null
    ).buildConstraintViolationWithTemplate("dummytemplate");
}
 
Example #3
Source File: UpdateStackRequestValidatorTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    underTest = new UpdateStackRequestValidator();
    constraintValidatorContext = new ConstraintValidatorContextImpl(
            null,
            PathImpl.createPathFromString("status"),
            new DummyConstraintDescriptor(),
            null
    );
}
 
Example #4
Source File: EnumListValidatorTest.java    From edison-microservice with Apache License 2.0 4 votes vote down vote up
private ConstraintValidatorContext createContext() {
    return new ConstraintValidatorContextImpl(Collections.emptyList(), DefaultClockProvider.INSTANCE, PathImpl.createPathFromString("target"), mock(ConstraintDescriptor.class), null);
}