Java 类javax.validation.ConstraintDeclarationException 实例源码
项目:jaxrs-beanvalidation-javaee7
文件:ValidationExceptionMapper.java
@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);
}
项目: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));
}
项目: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();
}
项目: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));
}
项目:InSpider
文件:ValidCollectionValidator.java
@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;
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getErrorDuringScriptExecutionException(final String script,
final Exception exception) {
return new ConstraintDeclarationException(
MESSAGE.getErrorDuringScriptExecutionException(script), exception);
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getScriptMustReturnTrueOrFalseException(
final String script) {
return new ConstraintDeclarationException(
MESSAGE.getScriptMustReturnTrueOrFalseExceptionSingle(script));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getScriptMustReturnTrueOrFalseException(final String script,
final Object executionResult, final String type) {
return new ConstraintDeclarationException(
MESSAGE.getScriptMustReturnTrueOrFalseException(script, executionResult.toString(), type));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getMultipleGroupConversionsForSameSourceException(
final Class<?> from, final Set<Class<?>> tos) {
return new ConstraintDeclarationException(
MESSAGE.getMultipleGroupConversionsForSameSourceException(from, tos));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getGroupConversionOnNonCascadingElementException(
final String location) {
return new ConstraintDeclarationException(
MESSAGE.getGroupConversionOnNonCascadingElementException(location));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getGroupConversionForSequenceException(
final Class<?> from) {
return new ConstraintDeclarationException(MESSAGE.getGroupConversionForSequenceException(from));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getImplicitConstraintTargetInAmbiguousConfigurationException(
final String constraint) {
return new ConstraintDeclarationException(
MESSAGE.getImplicitConstraintTargetInAmbiguousConfigurationException(constraint));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getCrossParameterConstraintOnMethodWithoutParametersException(
final String constraint, final String member) {
return new ConstraintDeclarationException(
MESSAGE.getCrossParameterConstraintOnMethodWithoutParametersException(constraint, member));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getCrossParameterConstraintOnClassException(
final String constraint) {
return new ConstraintDeclarationException(
MESSAGE.getCrossParameterConstraintOnClassException(constraint));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getCrossParameterConstraintOnFieldException(
final String constraint, final String field) {
return new ConstraintDeclarationException(
MESSAGE.getCrossParameterConstraintOnFieldException(constraint, field));
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getCreationOfScriptExecutorFailedException(
final String languageName, final Exception exception) {
return new ConstraintDeclarationException(
MESSAGE.getCreationOfScriptExecutorFailedException(languageName), exception);
}
项目:gwt-bean-validators
文件:Log.java
public ConstraintDeclarationException getInconsistentValueUnwrappingConfigurationBetweenFieldAndItsGetterException(
final String property, final String clazz) {
return new ConstraintDeclarationException(
MESSAGE.getInconsistentValueUnwrappingConfigurationBetweenFieldAndItsGetterException(
property, clazz));
}