类javax.validation.ConstraintDeclarationException源码实例Demo

下面列出了怎么用javax.validation.ConstraintDeclarationException的API类实例代码及写法,或者点击链接到github查看源代码。

@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);
}
 
@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);
}
 
源代码3 项目: hawkbit   文件: JpaRolloutManagement.java
@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));
}
 
源代码4 项目: hawkbit   文件: AbstractRolloutManagement.java
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();
}
 
源代码5 项目: hawkbit   文件: AbstractRolloutManagement.java
@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));
}
 
源代码6 项目: tomee   文件: ConstraintValidators.java
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;
    }

}
 
@ExceptionHandler( ConstraintDeclarationException.class )
public ResponseEntity constraintDeclarationException ( ConstraintDeclarationException e ) {
	LogUtils.getLogger().error( "error" , e );
	return ResponseEntityPro.badRequest( e.getMessage() );
}
 
 类所在包
 同包方法