use of org.hibernate.validator.internal.engine.path.PathImpl in project hibernate-validator by hibernate.
the class ValidatorImpl method validateValue.
@Override
public final <T> Set<ConstraintViolation<T>> validateValue(Class<T> beanType, String propertyName, Object value, Class<?>... groups) {
Contracts.assertNotNull(beanType, MESSAGES.beanTypeCannotBeNull());
sanityCheckPropertyPath(propertyName);
sanityCheckGroups(groups);
BeanMetaData<T> rootBeanMetaData = beanMetaDataManager.getBeanMetaData(beanType);
if (!rootBeanMetaData.hasConstraints()) {
return Collections.emptySet();
}
PathImpl propertyPath = PathImpl.createPathFromString(propertyName);
BaseBeanValidationContext<T> validationContext = getValidationContextBuilder().forValidateValue(beanType, rootBeanMetaData, propertyPath);
ValidationOrder validationOrder = determineGroupValidationOrder(groups);
return validateValueInContext(validationContext, value, propertyPath, validationOrder);
}
use of org.hibernate.validator.internal.engine.path.PathImpl in project hibernate-validator by hibernate.
the class ConstraintValidatorContextImplTest method createEmptyConstraintValidatorContextImpl.
private ConstraintValidatorContextImpl createEmptyConstraintValidatorContextImpl() {
PathImpl path = PathImpl.createRootPath();
path.addBeanNode();
ConstraintValidatorContextImpl context = new ConstraintValidatorContextImpl(null, path, null, null, ExpressionLanguageFeatureLevel.BEAN_PROPERTIES, ExpressionLanguageFeatureLevel.NONE);
context.disableDefaultConstraintViolation();
return context;
}
use of org.hibernate.validator.internal.engine.path.PathImpl in project hibernate-validator by hibernate.
the class PathImplTest method testCreationOfExecutablePath.
@Test
public void testCreationOfExecutablePath() throws Exception {
Method executable = Container.class.getMethod("addItem", Key.class, Item.class);
BeanMetaDataManager beanMetaDataManager = new BeanMetaDataManagerImpl(getDummyConstraintCreationContext(), new ExecutableHelper(new TypeResolutionHelper()), new ExecutableParameterNameProvider(new DefaultParameterNameProvider()), new JavaBeanHelper(new DefaultGetterPropertySelectionStrategy(), new DefaultPropertyNodeNameProvider()), new DefaultBeanMetaDataClassNormalizer(), new ValidationOrderGenerator(), Collections.<MetaDataProvider>emptyList(), new MethodValidationConfiguration.Builder().build());
ExecutableMetaData executableMetaData = beanMetaDataManager.getBeanMetaData(Container.class).getMetaDataFor(executable).get();
PathImpl methodParameterPath = PathImpl.createPathForExecutable(executableMetaData);
assertEquals(methodParameterPath.toString(), "addItem");
}
use of org.hibernate.validator.internal.engine.path.PathImpl in project hibernate-validator by hibernate.
the class PathImplTest method testParsingPropertyWithGermanCharacter.
@Test
public void testParsingPropertyWithGermanCharacter() {
PathImpl path = PathImpl.createPathFromString("höchstBetrag");
Iterator<Path.Node> it = path.iterator();
assertEquals(it.next().getName(), "höchstBetrag");
}
use of org.hibernate.validator.internal.engine.path.PathImpl in project litemall by linlinjava.
the class GlobalExceptionHandler method badArgumentHandler.
@ExceptionHandler(ValidationException.class)
@ResponseBody
public Object badArgumentHandler(ValidationException e) {
logger.error(e.getMessage(), e);
if (e instanceof ConstraintViolationException) {
ConstraintViolationException exs = (ConstraintViolationException) e;
Set<ConstraintViolation<?>> violations = exs.getConstraintViolations();
for (ConstraintViolation<?> item : violations) {
String message = ((PathImpl) item.getPropertyPath()).getLeafNode().getName() + item.getMessage();
return ResponseUtil.fail(402, message);
}
}
return ResponseUtil.badArgumentValue();
}
Aggregations