javax.validation.ConstraintDeclarationException Java Examples

The following examples show how to use javax.validation.ConstraintDeclarationException. 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: ResteasyViolationExceptionMapper.java    From quarkus with Apache License 2.0 6 votes vote down vote up
@Override
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);
}
 
Example #2
Source File: ValidationExceptionMapper.java    From jaxrs-beanvalidation-javaee7 with Apache License 2.0 6 votes vote down vote up
@Override
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);
}
 
Example #3
Source File: JpaRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Async
public ListenableFuture<RolloutGroupsValidation> validateTargetsInGroups(final List<RolloutGroupCreate> groups,
        final String targetFilter, final Long createdAt) {

    final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt);
    final long totalTargets = targetManagement.countByRsql(baseFilter);
    if (totalTargets == 0) {
        throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
    }

    return new AsyncResult<>(validateTargetsInGroups(
            groups.stream().map(RolloutGroupCreate::build).collect(Collectors.toList()), baseFilter, totalTargets));
}
 
Example #4
Source File: AbstractRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
protected long calculateRemainingTargets(final List<RolloutGroup> groups, final String targetFilter,
        final Long createdAt) {
    final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt);
    final long totalTargets = targetManagement.countByRsql(baseFilter);
    if (totalTargets == 0) {
        throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
    }

    final RolloutGroupsValidation validation = validateTargetsInGroups(groups, baseFilter, totalTargets);

    return totalTargets - validation.getTargetsInGroups();
}
 
Example #5
Source File: AbstractRolloutManagement.java    From hawkbit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Async
public ListenableFuture<RolloutGroupsValidation> validateTargetsInGroups(final List<RolloutGroupCreate> groups,
        final String targetFilter, final Long createdAt) {

    final String baseFilter = RolloutHelper.getTargetFilterQuery(targetFilter, createdAt);
    final long totalTargets = targetManagement.countByRsql(baseFilter);
    if (totalTargets == 0) {
        throw new ConstraintDeclarationException("Rollout target filter does not match any targets");
    }

    return new AsyncResult<>(validateTargetsInGroups(
            groups.stream().map(RolloutGroupCreate::build).collect(Collectors.toList()), baseFilter, totalTargets));
}
 
Example #6
Source File: ConstraintValidators.java    From tomee with Apache License 2.0 5 votes vote down vote up
public <A extends Annotation> boolean canValidate(final ConstraintD<A> descriptor, final Class<?> validatedType) {
    final ComputeConstraintValidatorClass<A> aComputeConstraintValidatorClass = new ComputeConstraintValidatorClass<A>(
            constraintsCache,
            descriptor,
            ValidationTarget.ANNOTATED_ELEMENT,
            validatedType);

    try {
        aComputeConstraintValidatorClass.get();
        return true;
    } catch (ConstraintDeclarationException e) {
        return false;
    }

}
 
Example #7
Source File: GlobalErrorController.java    From spring-boot-start-current with Apache License 2.0 4 votes vote down vote up
@ExceptionHandler( ConstraintDeclarationException.class )
public ResponseEntity constraintDeclarationException ( ConstraintDeclarationException e ) {
	LogUtils.getLogger().error( "error" , e );
	return ResponseEntityPro.badRequest( e.getMessage() );
}