private void throwConstraintErrorsIfPresent(final Collection<ConstraintViolationException> errors) { if (!errors.isEmpty()) { if (errors.size() == 1) { //throw the original constraint error if there //is only one so that the constraints document that //is returned to the user is as accurate as possible. throw errors.stream().findFirst().get(); } else { throw new ConstraintViolationException( errors.stream().map(Exception::getMessage).collect(joining(",\n"))); } } }
@Override public Response toResponse(final ConstraintViolationException e) { debugException(this, e, LOGGER); final Link link = buildConstraintLink(e, context, uriInfo); final String msg = e.getMessage(); return status(BAD_REQUEST).entity(msg).links(link).type(TEXT_PLAIN_WITH_CHARSET).build(); }
private static void assertContainsRequiredProperties(final Model model, final Collection<Property> properties) { for (final Property property : properties) { if (!model.contains(null, property, (RDFNode) null)) { throw new ConstraintViolationException("Missing required property " + property.getURI()); } } }
private static void assertContainsRequiredTypes(final Model model, final Collection<Resource> types) { for (final Resource type : types) { if (!model.contains(null, RDF.type, type)) { throw new ConstraintViolationException("Missing required type " + type.getURI()); } } } }
throw new ConstraintViolationException( "Cannot create historic memento from an empty body");