@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 @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)); }
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(); }
@Override public boolean isValid(List<?> entries, ConstraintValidatorContext context) { boolean valid = true; if(entries == null){ return valid; } if(ArrayUtils.getLength(constraints) != ArrayUtils.getLength(messages)){ throw new ConstraintDeclarationException("Number of messages must be the same as number of constraints"); } ValidatorFactory validatorFactory = Validation.buildDefaultValidatorFactory(); ConstraintValidatorFactory constraintValidatorFactory = validatorFactory.getConstraintValidatorFactory(); for(Object element : entries) { for(Class<?> constraint : constraints) { Constraint constraintAnnotation = constraint.getAnnotation(Constraint.class); Class<? extends ConstraintValidator<?, ?>>[] constraintValidators = constraintAnnotation.validatedBy(); for (int i = 0; i < constraintValidators.length; i++) { ConstraintValidator constraintValidator = constraintValidatorFactory.getInstance(constraintValidators[i]); if(!constraintValidator.isValid(element, context)){ context.buildConstraintViolationWithTemplate(messages[i]).addConstraintViolation().disableDefaultConstraintViolation(); valid = false; } } } } return valid; }
public ConstraintDeclarationException getErrorDuringScriptExecutionException(final String script, final Exception exception) { return new ConstraintDeclarationException( MESSAGE.getErrorDuringScriptExecutionException(script), exception); }
public ConstraintDeclarationException getScriptMustReturnTrueOrFalseException( final String script) { return new ConstraintDeclarationException( MESSAGE.getScriptMustReturnTrueOrFalseExceptionSingle(script)); }
public ConstraintDeclarationException getScriptMustReturnTrueOrFalseException(final String script, final Object executionResult, final String type) { return new ConstraintDeclarationException( MESSAGE.getScriptMustReturnTrueOrFalseException(script, executionResult.toString(), type)); }
public ConstraintDeclarationException getMultipleGroupConversionsForSameSourceException( final Class<?> from, final Set<Class<?>> tos) { return new ConstraintDeclarationException( MESSAGE.getMultipleGroupConversionsForSameSourceException(from, tos)); }
public ConstraintDeclarationException getGroupConversionOnNonCascadingElementException( final String location) { return new ConstraintDeclarationException( MESSAGE.getGroupConversionOnNonCascadingElementException(location)); }
public ConstraintDeclarationException getGroupConversionForSequenceException( final Class<?> from) { return new ConstraintDeclarationException(MESSAGE.getGroupConversionForSequenceException(from)); }
public ConstraintDeclarationException getImplicitConstraintTargetInAmbiguousConfigurationException( final String constraint) { return new ConstraintDeclarationException( MESSAGE.getImplicitConstraintTargetInAmbiguousConfigurationException(constraint)); }
public ConstraintDeclarationException getCrossParameterConstraintOnMethodWithoutParametersException( final String constraint, final String member) { return new ConstraintDeclarationException( MESSAGE.getCrossParameterConstraintOnMethodWithoutParametersException(constraint, member)); }
public ConstraintDeclarationException getCrossParameterConstraintOnClassException( final String constraint) { return new ConstraintDeclarationException( MESSAGE.getCrossParameterConstraintOnClassException(constraint)); }
public ConstraintDeclarationException getCrossParameterConstraintOnFieldException( final String constraint, final String field) { return new ConstraintDeclarationException( MESSAGE.getCrossParameterConstraintOnFieldException(constraint, field)); }
public ConstraintDeclarationException getCreationOfScriptExecutorFailedException( final String languageName, final Exception exception) { return new ConstraintDeclarationException( MESSAGE.getCreationOfScriptExecutorFailedException(languageName), exception); }
public ConstraintDeclarationException getInconsistentValueUnwrappingConfigurationBetweenFieldAndItsGetterException( final String property, final String clazz) { return new ConstraintDeclarationException( MESSAGE.getInconsistentValueUnwrappingConfigurationBetweenFieldAndItsGetterException( property, clazz)); }