use of jakarta.validation.ValidationException in project minijax by minijax.
the class MinijaxConstraintDescriptor method build.
@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
if (constraint == null) {
return null;
}
final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
final Class<?> annotationClass = annotation.annotationType();
if (constraint.validatedBy().length > 0) {
return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
} else if (annotationClass == AssertFalse.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
} else if (annotationClass == AssertTrue.class) {
return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
} else if (annotationClass == Max.class) {
return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
} else if (annotationClass == Min.class) {
return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
} else if (annotationClass == NotBlank.class) {
return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
} else if (annotationClass == NotEmpty.class) {
return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
} else if (annotationClass == NotNull.class) {
return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
} else if (annotationClass == Pattern.class) {
return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
} else if (annotationClass == Size.class) {
return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
} else {
throw new ValidationException("Unrecognized constraint annotation: " + annotation);
}
}
use of jakarta.validation.ValidationException in project gocd-groovy-dsl-config-plugin by gocd-contrib.
the class BranchHelper method createContext.
public static BranchContext createContext(Attributes<?> attrs, MergeCandidate merge) {
final String ref = merge.ref();
final String branch = prettifyRef(gitShortRef(ref), attrs);
final BranchContext bc = new BranchContext(ref, branch, createMaterial(attrs, merge));
bc.setProvider(attrs.asConnectionConfig());
bc.setIdentifier(requireNonNullElse(merge.identifier(), ""));
bc.setTitle(requireNonNullElse(merge.title(), ""));
bc.setAuthor(requireNonNullElse(merge.author(), ""));
bc.setReferenceUrl(requireNonNullElse(merge.showUrl(), ""));
bc.setLabels(new ArrayList<>(requireNonNullElse(merge.labels(), Collections.emptyList())));
validate(bc, (errors) -> {
throw new ValidationException("Branch context binding is missing data! " + "Check the provider's API response. Error(s):\n" + errors.stream().map(ConstraintViolation::getMessage).collect(Collectors.joining("\n", " ", "")));
});
return bc;
}
use of jakarta.validation.ValidationException in project resteasy by resteasy.
the class ResteasyViolationExceptionMapper method toResponse.
public Response toResponse(ValidationException exception) {
if (exception instanceof ConstraintDefinitionException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof ConstraintDeclarationException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof GroupDefinitionException) {
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
if (exception instanceof ResteasyViolationException) {
ResteasyViolationException resteasyViolationException = ResteasyViolationException.class.cast(exception);
Exception e = resteasyViolationException.getException();
if (e != null) {
return buildResponse(unwrapException(e), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
} else if (resteasyViolationException.getReturnValueViolations().size() == 0) {
return buildViolationReportResponse(resteasyViolationException, Status.BAD_REQUEST);
} else {
return buildViolationReportResponse(resteasyViolationException, Status.INTERNAL_SERVER_ERROR);
}
}
return buildResponse(unwrapException(exception), MediaType.TEXT_PLAIN, Status.INTERNAL_SERVER_ERROR);
}
use of jakarta.validation.ValidationException in project resteasy by resteasy.
the class AbstractValidatorContextResolver method getContext.
public GeneralValidatorCDI getContext(Class<?> type) {
try {
BootstrapConfiguration bootstrapConfiguration = getConfig();
boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration.getDefaultValidatedExecutableTypes();
return new GeneralValidatorImpl(getValidatorFactory(), isExecutableValidationEnabled, defaultValidatedExecutableTypes);
} catch (Exception e) {
throw new ValidationException(Messages.MESSAGES.unableToLoadValidationSupport(), e);
}
}
use of jakarta.validation.ValidationException in project mojarra by eclipse-ee4j.
the class BeanValidation method getValidatorFactory.
public static ValidatorFactory getValidatorFactory(FacesContext context) {
ValidatorFactory validatorFactory = null;
Object cachedObject = context.getExternalContext().getApplicationMap().get(VALIDATOR_FACTORY_KEY);
if (cachedObject instanceof ValidatorFactory) {
validatorFactory = (ValidatorFactory) cachedObject;
} else {
try {
validatorFactory = buildDefaultValidatorFactory();
} catch (ValidationException e) {
throw new FacesException("Could not build a default Bean Validator factory", e);
}
context.getExternalContext().getApplicationMap().put(VALIDATOR_FACTORY_KEY, validatorFactory);
}
return validatorFactory;
}
Aggregations