Java Code Examples for javax.validation.Path.Node

The following are Jave code examples for showing how to use Node of the javax.validation.Path class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: lams   File: HibernateTraversableResolver.java   View Source Code Vote up 6 votes
private String getStringBasedPath(Path.Node traversableProperty, Path pathToTraversableObject) {
	StringBuilder path = new StringBuilder( );
	for ( Path.Node node : pathToTraversableObject ) {
		if (node.getName() != null) {
			path.append( node.getName() ).append( "." );
		}
	}
	if ( traversableProperty.getName() == null ) {
		throw new AssertionFailure(
				"TraversableResolver being passed a traversableProperty with null name. pathToTraversableObject: "
						+ path.toString() );
	}
	path.append( traversableProperty.getName() );

	return path.toString();
}
 
Example 2
Project: continuous-delivery-demo   File: GlobalControllerExceptionHandler.java   View Source Code Vote up 6 votes
private List<ValidationMessage> getValidationErrorResponse(ConstraintViolationException constraintViolationException) {
    final List<ValidationMessage> validationErrors = new ArrayList<>();
    LOG.error("Got validation errors", constraintViolationException);
    for (ConstraintViolation<?> violationSet : constraintViolationException.getConstraintViolations()) {
        List<String> propertyList = new ArrayList<>();
        Iterator<Path.Node> propertyIterator = violationSet
                .getPropertyPath().iterator();
        while (propertyIterator.hasNext()) {
            propertyList.add(propertyIterator.next().getName());
        }
        // add violations errors in response
        validationErrors.add(ValidationMessage.builder()
                .entity(violationSet.getRootBeanClass().getName())
                        // remove { and }
                .messageTemplate(violationSet.getMessageTemplate().replaceAll("^[{]|[}]$", ""))
                .propertyList(propertyList).build());
    }
    return validationErrors;
}
 
Example 3
Project: angular-spring-boot-sample   File: GlobalControllerExceptionHandler.java   View Source Code Vote up 6 votes
private List<ValidationMessage> getValidationErrorResponse(ConstraintViolationException constraintViolationException) {
    final List<ValidationMessage> validationErrors = new ArrayList<>();
    LOG.error("Got validation errors", constraintViolationException);
    for (ConstraintViolation<?> violationSet : constraintViolationException.getConstraintViolations()) {
        List<String> propertyList = new ArrayList<>();
        Iterator<Path.Node> propertyIterator = violationSet
                .getPropertyPath().iterator();
        while (propertyIterator.hasNext()) {
            propertyList.add(propertyIterator.next().getName());
        }
        // add violations errors in response
        validationErrors.add(ValidationMessage.builder()
                .entity(violationSet.getRootBeanClass().getName())
                        // remove { and }
                .messageTemplate(violationSet.getMessageTemplate().replaceAll("^[{]|[}]$", ""))
                .propertyList(propertyList).build());
    }
    return validationErrors;
}
 
Example 4
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 5
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 6
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 7
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 8
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 9
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 10
Project: hql-builder   File: JavaxValidationConverter.java   View Source Code Vote up 6 votes
/**
 * @see org.tools.hqlbuilder.common.interfaces.ValidationExceptionConverter#convert(java.lang.Exception)
 */
@Override
public ValidationException convert(Exception e) {
    javax.validation.ConstraintViolationException ex = (ConstraintViolationException) e;
    List<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue> ivs = new ArrayList<org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue>();
    for (javax.validation.ConstraintViolation<?> iv : ex.getConstraintViolations()) {
        Object bean = iv.getLeafBean();
        Class<?> beanClass = iv.getRootBeanClass();
        String message = iv.getMessage();
        Path path = iv.getPropertyPath();
        Iterator<javax.validation.Path.Node> it = path.iterator();
        Path.Node node = it.next();
        while (it.hasNext()) {
            node = it.next();
        }
        String propertyName = String.valueOf(node);
        String propertyPath = String.valueOf(path);
        Object rootBean = iv.getRootBean();
        Object value = iv.getInvalidValue();
        org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue tmp = new org.tools.hqlbuilder.common.exceptions.ValidationException.InvalidValue(
                bean, beanClass, message, propertyName, propertyPath, rootBean, value);
        ivs.add(tmp);
    }
    return new ValidationException(ex.getMessage(), ivs);
}
 
Example 11
Project: ocelot   File: ConstraintServicesTest.java   View Source Code Vote up 6 votes
/**
 * Test of extractViolationInfoFromNode method, of class ConstraintServices.
 */
@Test
public void testExtractViolationInfoFromNode() {
	System.out.println("extractViolationInfoFromNode");
	Path.Node node = mock(Path.Node.class);
	when(node.getKind()).thenReturn(ElementKind.METHOD).thenReturn(ElementKind.PARAMETER).thenReturn(ElementKind.PROPERTY);
	when(node.getName()).thenReturn("arg0").thenReturn("prop");
	doReturn(5).when(instance).getIndexFromArgname(anyString());

	ConstraintViolation cv = new ConstraintViolation();
	instance.extractViolationInfoFromNode(node, cv);
	assertThat(cv.getMessage()).isNull();
	assertThat(cv.getIndex()).isEqualTo(0);
	assertThat(cv.getProp()).isNull();
	cv = new ConstraintViolation();
	instance.extractViolationInfoFromNode(node, cv);
	assertThat(cv.getMessage()).isNull();
	assertThat(cv.getIndex()).isEqualTo(5);
	assertThat(cv.getProp()).isNull();
	cv = new ConstraintViolation();
	instance.extractViolationInfoFromNode(node, cv);
	assertThat(cv.getMessage()).isNull();
	assertThat(cv.getIndex()).isEqualTo(0);
	assertThat(cv.getProp()).isEqualTo("prop");
}
 
Example 12
Project: gwt-bean-validators   File: NodeImpl.java   View Source Code Vote up 6 votes
@SuppressWarnings("unchecked")
@Override
public <T extends Path.Node> T as(final Class<T> nodeType) throws ClassCastException { // NOPMD
  if (this.kind == ElementKind.BEAN && nodeType == BeanNode.class
      || this.kind == ElementKind.CONSTRUCTOR && nodeType == ConstructorNode.class
      || this.kind == ElementKind.CROSS_PARAMETER && nodeType == CrossParameterNode.class
      || this.kind == ElementKind.METHOD && nodeType == MethodNode.class
      || this.kind == ElementKind.PARAMETER && nodeType == ParameterNode.class
      || this.kind == ElementKind.PROPERTY && (nodeType == PropertyNode.class
          || nodeType == org.hibernate.validator.path.PropertyNode.class)
      || this.kind == ElementKind.RETURN_VALUE && nodeType == ReturnValueNode.class
      || this.kind == ElementKind.CONTAINER_ELEMENT && (nodeType == ContainerElementNode.class
          || nodeType == org.hibernate.validator.path.ContainerElementNode.class)) {
    return (T) this;
  }

  throw LOG.getUnableToNarrowNodeTypeException(this.getClass(), this.kind, nodeType);
}
 
Example 13
Project: ameba   File: ValidationHelper.java   View Source Code Vote up 6 votes
/**
 * Determine the response status (400 or 500) from the given BV exception.
 *
 * @param violation BV exception.
 * @return response status (400 or 500).
 */
public static Response.Status getResponseStatus(final ConstraintViolationException violation) {
    final Iterator<ConstraintViolation<?>> iterator = violation.getConstraintViolations().iterator();

    if (iterator.hasNext()) {
        for (final Path.Node node : iterator.next().getPropertyPath()) {
            final ElementKind kind = node.getKind();

            if (ElementKind.RETURN_VALUE.equals(kind)) {
                return Response.Status.INTERNAL_SERVER_ERROR;
            }
        }
    }

    return Response.Status.BAD_REQUEST;
}
 
Example 14
Project: act-platform   File: ConstraintViolationMapper.java   View Source Code Vote up 5 votes
private String printPropertyPath(Path path) {
  if (path == null) return "UNKNOWN";

  String propertyPath = "";
  Path.Node parameterNode = null;
  // Construct string representation of property path.
  // This will strip away any other nodes added by RESTEasy (method, parameter, ...).
  for (Path.Node node : path) {
    if (node.getKind() == ElementKind.PARAMETER) {
      parameterNode = node;
    }

    if (node.getKind() == ElementKind.PROPERTY) {
      if (!propertyPath.isEmpty()) {
        propertyPath += ".";
      }

      propertyPath += node;
    }
  }

  if (propertyPath.isEmpty() && parameterNode != null) {
    // No property path constructed, assume this is a validation failure on a request parameter.
    propertyPath = parameterNode.toString();
  }

  return propertyPath;
}
 
Example 15
Project: lams   File: HibernateTraversableResolver.java   View Source Code Vote up 5 votes
public boolean isReachable(Object traversableObject,
						   Path.Node traversableProperty,
						   Class<?> rootBeanType,
						   Path pathToTraversableObject,
						   ElementType elementType) {
	//lazy, don't load
	return Hibernate.isInitialized( traversableObject )
			&& Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() );
}
 
Example 16
Project: lams   File: HibernateTraversableResolver.java   View Source Code Vote up 5 votes
public boolean isCascadable(Object traversableObject,
					  Path.Node traversableProperty,
					  Class<?> rootBeanType,
					  Path pathToTraversableObject,
					  ElementType elementType) {
	String path = getStringBasedPath( traversableProperty, pathToTraversableObject );
	return ! associations.contains(path);
}
 
Example 17
Project: Pedidex   File: ConstraintViolationMapper.java   View Source Code Vote up 5 votes
private String printPropertyPath(Path path) {
    if (path == null) {
        return "UNKNOWN";
    }

    String propertyPath = "";
    Path.Node parameterNode = null;
    // Construct string representation of property path.
    // This will strip away any other nodes added by RESTEasy (method, parameter, ...).
    for (Path.Node node : path) {
        if (node.getKind() == ElementKind.PARAMETER) {
            parameterNode = node;
        }

        if (node.getKind() == ElementKind.PROPERTY) {
            if (!propertyPath.isEmpty()) {
                propertyPath += ".";
            }
            propertyPath += node;
        }
    }

    if (propertyPath.isEmpty() && parameterNode != null) {
        // No property path constructed, assume this is a validation failure on a request parameter.
        propertyPath = parameterNode.toString();
    }
    return propertyPath;
}
 
Example 18
Project: gitplex-mit   File: ValuePath.java   View Source Code Vote up 5 votes
public ValuePath(Path validationPath) {
	for (Path.Node node: validationPath) {
		if (node.getIndex() != null) 
			elements.add(new PathSegment.Element(node.getIndex()));
		if (node.getName() != null)
			elements.add(new PathSegment.Property(node.getName()));
	}
}
 
Example 19
Project: excel-util4j   File: ValidateKit.java   View Source Code Vote up 5 votes
/**
 * 通过根类和hibernate validator错误信息获取当前验证失败的field对象
 *
 * @param rootClass pojo根类, 如:User.class类包含属性info:Info.class,User即rootClass
 * @param cv        hibernate validator验证结果对象{@link ConstraintViolation}
 * @return 当前失败的field对象
 */
static Field getConstraintViolationField(Class<?> rootClass, ConstraintViolation<Object> cv) {

    try {
        Field field = null;
        for (Path.Node node : cv.getPropertyPath()) {
            String fieldName = node.getName();
            field = rootClass.getDeclaredField(fieldName);
            rootClass = field.getType();
        }
        return field;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 20
Project: nifi-registry   File: ConstraintViolationExceptionMapper.java   View Source Code Vote up 5 votes
@Override
public Response toResponse(ConstraintViolationException exception) {
    logger.info(String.format("%s. Returning %s response.", exception, Response.Status.BAD_REQUEST));

    if (logger.isDebugEnabled()) {
        logger.debug(StringUtils.EMPTY, exception);
    }

    // start with the overall message which will be something like "Cannot create xyz"
    final StringBuilder errorMessage = new StringBuilder(exception.getMessage()).append(" - ");

    boolean first = true;
    for (final ConstraintViolation violation : exception.getConstraintViolations()) {
        if (!first) {
            errorMessage.append(", ");
        }
        first = false;

        // lastNode should end up as the field that failed validation
        Path.Node lastNode = null;
        for (final Path.Node node : violation.getPropertyPath()) {
            lastNode = node;
        }

        // append something like "xyz must not be..."
        errorMessage.append(lastNode.getName()).append(" ").append(violation.getMessage());
    }

    return Response.status(Response.Status.BAD_REQUEST).entity(errorMessage.toString()).type("text/plain").build();
}
 
Example 21
Project: crudlet   File: RestValidationConstraintErrorBuilder.java   View Source Code Vote up 5 votes
private static String readPropertyName(ConstraintViolation violation) {
    Iterator<Path.Node> i = violation.getPropertyPath().iterator();
    Path.Node current = i.next();
    while (i.hasNext()) {
        current = i.next();
    }
    // Use '.' as the key if the entire object is erroneous
    if ("arg0".equals(current.getName())) {
        return ".";
    }
    else {
        return violation.getPropertyPath().toString();
    }
}
 
Example 22
Project: cuba   File: CubaValidationTraversableResolver.java   View Source Code Vote up 5 votes
@Override
public final boolean isReachable(Object traversableObject,
                                 Path.Node traversableProperty,
                                 Class<?> rootBeanType,
                                 Path pathToTraversableObject,
                                 ElementType elementType) {
    log.trace("Calling isReachable on object {} with node name {}", traversableObject, traversableProperty.getName());

    if (traversableObject == null
            || metadata.getClass(traversableObject.getClass()) == null) {
        return true;
    }

    return entityStates.isLoaded(traversableObject, traversableProperty.getName());
}
 
Example 23
Project: nexus-public   File: ConstraintViolationExceptionMapper.java   View Source Code Vote up 5 votes
private Status getResponseStatus(final ConstraintViolation<?> violation) {
  for (Path.Node node : violation.getPropertyPath()) {
    ElementKind kind = node.getKind();

    if (ElementKind.RETURN_VALUE.equals(kind)) {
      return Status.INTERNAL_SERVER_ERROR;
    }
  }

  return Status.BAD_REQUEST;
}
 
Example 24
Project: lastaflute   File: ActionValidator.java   View Source Code Vote up 5 votes
protected String derivePropertyPathByNode(ConstraintViolation<Object> vio) {
    final StringBuilder sb = new StringBuilder();
    final Path path = vio.getPropertyPath();
    int elementCount = 0;
    for (Path.Node node : path) {
        if (node.isInIterable()) { // building e.g. "[0]" of seaList[0]
            Object nodeIndex = node.getIndex();
            if (nodeIndex == null) {
                nodeIndex = node.getKey(); // null if e.g. iterable
            }
            sb.append("[").append(nodeIndex != null ? nodeIndex : "").append("]"); // e.g. [0] or []
        }
        final String nodeName = node.getName();
        if (nodeName != null && node.getKind() == ElementKind.PROPERTY) {
            // _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
            // if e.g.
            //  private List<@Required String> seaList;
            // then path is "seaList[0].<list element>" since Hibernate Validator-6.x
            // <list element> part is unneeded for property path of message so skip here
            // _/_/_/_/_/_/_/_/_/_/
            if (!nodeName.startsWith("<")) { // except e.g. <list element>
                if (elementCount > 0) {
                    sb.append(".");
                }
                sb.append(nodeName);
                ++elementCount;
            }
        }
    }
    return sb.toString(); // e.g. sea, sea.hangar, seaList[0], seaList[0].hangar
}
 
Example 25
Project: rise   File: ValidationPathUtil.java   View Source Code Vote up 5 votes
/**
 * Convert a single node of a javax.validation path to the corresponding
 * beanutils property path segment.
 */
public static String toPathString(Path.Node node) {
    if (!node.isInIterable()) {
        return node.getName();
    } else {
        if (node.getIndex() != null) {
            return node.getName() + "[" + node.getIndex() + "]";
        }
        return node.getName() + "(" + node.getIndex() + ")";
    }
}
 
Example 26
Project: ocelot   File: ConstraintServices.java   View Source Code Vote up 5 votes
void extractViolationInfoFromNode(Path.Node node, ConstraintViolation cv) {
	ElementKind kind = node.getKind();
	logger.debug("Kind:{} Index:{} Key:{} Name:{}", kind, node.getIndex(), node.getKey(), node.getName());
	
	if (ElementKind.PARAMETER.equals(kind)) {
		cv.setIndex(getIndexFromArgname(node.getName()));
	} else if (ElementKind.PROPERTY.equals(kind)) {
		cv.setProp(node.getName());
	}
}
 
Example 27
Project: ocelot   File: ConstraintServicesTest.java   View Source Code Vote up 5 votes
/**
 * Test of extractViolationInfoFromNodes method, of class ConstraintServices.
 */
@Test
public void testExtractViolationInfoFromNodes() {
	System.out.println("extractViolationInfoFromNodes");
	List<Path.Node> list = Collections.EMPTY_LIST;
	Iterator<Path.Node> nodeIterator = list.iterator();
	ConstraintViolation cv = new ConstraintViolation();
	instance.extractViolationInfoFromNodes(nodeIterator, cv);
	verify(instance, never()).extractViolationInfoFromNode(any(Path.Node.class), any(ConstraintViolation.class));
}
 
Example 28
Project: ocelot   File: ConstraintServicesTest.java   View Source Code Vote up 5 votes
/**
 * Test of extractViolationInfoFromNodes method, of class ConstraintServices.
 */
@Test
public void testExtractViolationInfoFromNodes2() {
	System.out.println("extractViolationInfoFromNodes");
	List<Path.Node> list = new ArrayList<>();
	list.add(mock(Path.Node.class));
	list.add(mock(Path.Node.class));
	Iterator<Path.Node> nodeIterator = list.iterator();
	ConstraintViolation cv = new ConstraintViolation();
	doNothing().when(instance).extractViolationInfoFromNode(any(Path.Node.class), any(ConstraintViolation.class));
	instance.extractViolationInfoFromNodes(nodeIterator, cv);
	verify(instance, times(2)).extractViolationInfoFromNode(any(Path.Node.class), any(ConstraintViolation.class));
}
 
Example 29
Project: gwt-bean-validators   File: PathImpl.java   View Source Code Vote up 5 votes
@Override
public Iterator<Path.Node> iterator() {
  if (this.nodeList.size() == 0) {
    return Collections.<Path.Node>emptyList().iterator();
  }
  if (this.nodeList.size() == 1) {
    return this.nodeList.iterator();
  }
  return this.nodeList.subList(1, this.nodeList.size()).iterator();
}
 
Example 30
Project: ix3   File: ExceptionTranslator.java   View Source Code Vote up 5 votes
private String getPropertyNameFromPath(Class clazz, Path path) {
    StringBuilder sb = new StringBuilder();
    if (path != null) {
        Class currentClazz = clazz;
        for (Path.Node node : path) {
            ClassAndLabel clazzAndCaption = getSingleCaption(currentClazz, node.getName());
            if (clazzAndCaption.label != null) {
                if (sb.length() != 0) {
                    sb.append(" ");
                }
                if (node.isInIterable()) {
                    if (node.getIndex() != null) {
                        sb.append(node.getIndex());
                        sb.append("º ");
                        sb.append(clazzAndCaption.label);
                    } else if (node.getKey() != null) {
                        sb.append(clazzAndCaption.label);
                        sb.append(" de ");
                        sb.append(node.getKey());
                    } else {
                        sb.append(clazzAndCaption.label);
                    }
                } else {
                    sb.append(clazzAndCaption.label);
                }
            } else {
                sb.append("");
            }
            currentClazz = clazzAndCaption.clazz;
        }

        return sb.toString();

    } else {
        return null;
    }

}
 
Example 31
Project: dropwizard-orient-server   File: DummyTraversableResolver.java   View Source Code Vote up 5 votes
@Override
public boolean isReachable(
        final Object traversableObject,
        final Path.Node traversableProperty,
        final Class<?> rootBeanType,
        final Path pathToTraversableObject,
        final ElementType elementType) {
    return true;
}
 
Example 32
Project: dropwizard-orient-server   File: DummyTraversableResolver.java   View Source Code Vote up 5 votes
@Override
public boolean isCascadable(
        final Object traversableObject,
        final Path.Node traversableProperty,
        final Class<?> rootBeanType,
        final Path pathToTraversableObject,
        final ElementType elementType) {
    return true;
}
 
Example 33
Project: guice-validator   File: ValidationMethodInterceptor.java   View Source Code Vote up 5 votes
private String getMessage(final Member member, final Object[] args,
                          final Set<? extends ConstraintViolation<?>> violations) {
    final StringBuilder message = new StringBuilder(200)
            .append(violations.size())
            .append(" constraint violation(s) occurred during method validation.")
            .append("\nConstructor or Method: ").append(member)
            .append("\nArgument values: ").append(Arrays.toString(args))
            .append("\nConstraint violations: ");
    int i = 1;
    for (ConstraintViolation<?> constraintViolation : violations) {
        final Path.Node leafNode = getLeafNode(constraintViolation);
        message.append("\n (")
                .append(i++)
                .append(") Kind: ")
                .append(leafNode.getKind());
        if (leafNode.getKind() == ElementKind.PARAMETER) {
            message.append("\n parameter index: ")
                    .append(leafNode.as(Path.ParameterNode.class).getParameterIndex());
        }
        message.append("\n message: ").append(constraintViolation.getMessage())
                .append("\n root bean: ").append(constraintViolation.getRootBean())
                .append("\n property path: ").append(constraintViolation.getPropertyPath())
                .append("\n constraint: ").append(constraintViolation.getConstraintDescriptor().getAnnotation());
    }

    return message.toString();
}
 
Example 34
Project: guice-validator   File: ValidationMethodInterceptor.java   View Source Code Vote up 5 votes
private Path.Node getLeafNode(final ConstraintViolation<?> constraintViolation) {
    final Iterator<Path.Node> nodes = constraintViolation.getPropertyPath().iterator();
    Path.Node leafNode = null;
    while (nodes.hasNext()) {
        leafNode = nodes.next();
    }
    return leafNode;
}
 
Example 35
Project: ironjacamar   File: IronJacamarTraversableResolver.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
public boolean isReachable(Object traversableObject, Path.Node traversableProperty,
                           Class<?> rootBeanType, Path pathToTraversableObject,
                           ElementType elementType)
{
   return true;
}
 
Example 36
Project: ironjacamar   File: IronJacamarTraversableResolver.java   View Source Code Vote up 5 votes
/**
 * {@inheritDoc}
 */
public boolean isCascadable(Object traversableObject,
                            Path.Node traversableProperty, Class<?> rootBeanType,
                            Path pathToTraversableObject, ElementType elementType)
{
   return true;
}
 
Example 37
Project: jaxrs-beanvalidation-javaee7   File: ValidationExceptionMapper.java   View Source Code Vote up 5 votes
private Response.Status getResponseStatus(final ConstraintViolation<?> constraintViolation) {
    for (final Path.Node node : constraintViolation.getPropertyPath()) {
        final ElementKind kind = node.getKind();

        if (ElementKind.RETURN_VALUE.equals(kind)) {
            return Response.Status.INTERNAL_SERVER_ERROR;
        }
    }

    return Response.Status.BAD_REQUEST;
}
 
Example 38
Project: onetwo   File: EmptyTraversableResolver.java   View Source Code Vote up 4 votes
public final boolean isReachable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
	return true;
}
 
Example 39
Project: onetwo   File: EmptyTraversableResolver.java   View Source Code Vote up 4 votes
public final boolean isCascadable(Object traversableObject, Path.Node traversableProperty, Class<?> rootBeanType, Path pathToTraversableObject, ElementType elementType) {
	return true;
}
 
Example 40
Project: ocelot   File: ConstraintServices.java   View Source Code Vote up 4 votes
void extractViolationInfoFromNodes(Iterator<Path.Node> nodeIterator, ConstraintViolation cv) {
	while (nodeIterator.hasNext()) {
		extractViolationInfoFromNode(nodeIterator.next(), cv);
	}
}
 
Example 41
Project: ozark   File: ConstraintViolations.java   View Source Code Vote up 3 votes
private static Annotation[] getAnnotations(ConstraintViolation<?> violation) {


        // create a simple list of nodes from the path
        List<Path.Node> nodes = new ArrayList<>();
        for (Path.Node node : violation.getPropertyPath()) {
            nodes.add(node);
        }
        Path.Node lastNode = nodes.get(nodes.size() - 1);

        // the path refers to some property of the leaf bean
        if (lastNode.getKind() == ElementKind.PROPERTY) {

            Path.PropertyNode propertyNode = lastNode.as(Path.PropertyNode.class);
            return getPropertyAnnotations(violation, propertyNode);

        }

        // The path refers to a method parameter
        else if (lastNode.getKind() == ElementKind.PARAMETER && nodes.size() == 2) {

            Path.MethodNode methodNode = nodes.get(0).as(Path.MethodNode.class);
            Path.ParameterNode parameterNode = nodes.get(1).as(Path.ParameterNode.class);

            return getParameterAnnotations(violation, methodNode, parameterNode);

        }


        log.warning("Could not read annotations for path: " + violation.getPropertyPath().toString());
        return new Annotation[0];

    }