当前位置: 首页>>代码示例>>Java>>正文


Java ValidationException类代码示例

本文整理汇总了Java中javax.validation.ValidationException的典型用法代码示例。如果您正苦于以下问题:Java ValidationException类的具体用法?Java ValidationException怎么用?Java ValidationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ValidationException类属于javax.validation包,在下文中一共展示了ValidationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isValid

import javax.validation.ValidationException; //导入依赖的package包/类
public boolean isValid(Object value, ConstraintValidatorContext context) {
	boolean returnValue = false;
	try {
		Comparable first = (Comparable) getNestedProperty(value, property);
		Object second = getNestedProperty(value, otherProperty);
		if (first == null) {
			returnValue = true;
		} else if (second != null) {
			returnValue = doComparison(first, second, comparison);
		}
		// Wenn first != null und second == null: Prüfung würde NPE bewirken, einfach false zurückgeben.
	} catch (Exception e) {
		throw new ValidationException("Cannot read property " + property + " and comparison property " + otherProperty);
	}
	if (!returnValue) {
		createViolationMessageForNestedProperty(property, messageTemplate, context);
	}
	return returnValue;
}
 
开发者ID:dvbern,项目名称:beanvalidation,代码行数:20,代码来源:CompareToValidator.java

示例2: validate

import javax.validation.ValidationException; //导入依赖的package包/类
/**
 * Validates the {@code request} based on its type and returns it or throws a {@code ValidationException}
 * if any {@link ConstraintViolation} is found.
 *
 * @param request the request object to validate
 * @param <T>     request type param
 * @return The validated request(the same object passed as {@code request})
 * @throws ValidationException if any {@link ConstraintViolation} is found
 */
public static <T extends SafechargeBaseRequest> T validate(T request) throws ValidationException {

    Set<ConstraintViolation<T>> constraintViolations = validator.validate(request);

    if (constraintViolations != null && !constraintViolations.isEmpty()) {
        StringBuilder sb = new StringBuilder();
        for (ConstraintViolation<T> constraintViolation : constraintViolations) {
            sb.append(constraintViolation.getMessage())
                    .append(" ");
        }

        String errorMessage = sb.toString();

        if (logger.isDebugEnabled()) {
            logger.debug(errorMessage);
        }

        throw new ConstraintViolationException(constraintViolations);
    }

    return request;
}
 
开发者ID:SafeChargeInternational,项目名称:safecharge-java,代码行数:32,代码来源:ValidationUtils.java

示例3: check

import javax.validation.ValidationException; //导入依赖的package包/类
/**
 * 检查参数是否符合注解(用户自行加的验证注解)
 *
 * @param params 参数
 * @throws ValidationException 当参数不符合规定时抛出该异常
 */
public void check(Object[] params) throws ValidationException {
    Set<ConstraintViolation<T>> methodValidators = executableValidator.validateParameters(instance,
            resourceMethod, params);
    for (ConstraintViolation<T> constraintViolation : methodValidators) {
        throw new ValidationException(constraintViolation.getMessage());
    }
}
 
开发者ID:935237604,项目名称:easysocket,代码行数:14,代码来源:Resource.java

示例4: list

import javax.validation.ValidationException; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public PaginatedList<RouterDto> list(PagingRequest request)
    throws CommsRouterException {

  return transactionManager.execute(em -> {

    String countString = "SELECT COUNT(id) FROM Router";
    long totalCount = (long) em.createQuery(countString).getSingleResult();

    int startPosition = (request.getPage() * request.getPerPage()) - request.getPerPage();

    if (totalCount > 0 && totalCount <= startPosition) {
      throw new ValidationException("{resource.list.max.page.number}");
    }

    String qlString = "SELECT r FROM Router r";
    List<Router> jpaResult = em.createQuery(qlString)
        .setFirstResult(startPosition)
        .setMaxResults(request.getPerPage())
        .getResultList();

    return new PaginatedList<>(request, entityMapper.toDto(jpaResult), totalCount);
  });
}
 
开发者ID:Nexmo,项目名称:comms-router,代码行数:26,代码来源:CoreRouterService.java

示例5: deleteAppRole

import javax.validation.ValidationException; //导入依赖的package包/类
@Override
public void deleteAppRole(String id) {
	AppRole role = appRoleRepository.findById(id);
	if (role == null) {
		return;
	}
	if (relationshipRepository.findFirstByRole(role) != null) {
		throw new RoleException("该角色下已绑定用户,请解除和用户的关系后再进行删除角色操作");
	}

	if (roleReferenceList != null) {
		roleReferenceList.forEach(ref -> {
			if (ref.hasReference(role)) {
				throw new ValidationException("该数据已经被其他数据引用,不能删除");
			}
		});
	}

	appRoleRepository.delete(role);
}
 
开发者ID:melthaw,项目名称:spring-backend-boilerplate,代码行数:21,代码来源:RoleServiceImpl.java

示例6: buildNotEmptyValidator

import javax.validation.ValidationException; //导入依赖的package包/类
private static MinijaxConstraintDescriptor<NotEmpty> buildNotEmptyValidator(final NotEmpty notEmpty, final Class<?> valueClass) {
    if (valueClass.isArray()) {
        return new MinijaxConstraintDescriptor<>(notEmpty, NotEmptyValidatorForArray.INSTANCE);
    }

    if (CharSequence.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty, NotEmptyValidatorForCharSequence.INSTANCE);
    }

    if (Collection.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty, NotEmptyValidatorForCollection.INSTANCE);
    }

    if (Map.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(notEmpty, NotEmptyValidatorForMap.INSTANCE);
    }

    throw new ValidationException("Unsupported type for @NotEmpty annotation: " + valueClass);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:MinijaxConstraintDescriptor.java

示例7: buildSizeValidator

import javax.validation.ValidationException; //导入依赖的package包/类
private static MinijaxConstraintDescriptor<Size> buildSizeValidator(final Size size, final Class<?> valueClass) {
    if (valueClass.isArray()) {
        return new MinijaxConstraintDescriptor<>(size, new SizeValidatorForArray(size));
    }

    if (CharSequence.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(size, new SizeValidatorForCharSequence(size));
    }

    if (Collection.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(size, new SizeValidatorForCollection(size));
    }

    if (Map.class.isAssignableFrom(valueClass)) {
        return new MinijaxConstraintDescriptor<>(size, new SizeValidatorForMap(size));
    }

    throw new ValidationException("Unsupported type for @Size annotation: " + valueClass);
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:MinijaxConstraintDescriptor.java

示例8: assertValidationException

import javax.validation.ValidationException; //导入依赖的package包/类
private static void assertValidationException(
        final boolean shouldFail,
        final String huntingParty,
        final Required r,
        final HuntingAreaType huntingAreaType) {

    try {
        r.validateHuntingParty(huntingParty, huntingAreaType);
        if (shouldFail) {
            fail("Exception should have happend");
        }
    } catch (final ValidationException iex) {
        if (!shouldFail) {
            fail("Unexpected exception: " + iex);
        }
    } catch (final Exception e) {
        fail("Unexpected exception thrown: " + e);
    }
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-web,代码行数:20,代码来源:RequiredTest.java

示例9: RouteDefinition

import javax.validation.ValidationException; //导入依赖的package包/类
public RouteDefinition(String text) {
	int eqIdx = text.indexOf("=");
	if (eqIdx <= 0) {
		throw new ValidationException("Unable to parse RouteDefinition text '" + text + "'" +
				", must be of the form name=value");
	}

	setId(text.substring(0, eqIdx));

	String[] args = tokenizeToStringArray(text.substring(eqIdx+1), ",");

	setUri(URI.create(args[0]));

	for (int i=1; i < args.length; i++) {
		this.predicates.add(new PredicateDefinition(args[i]));
	}
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-gateway,代码行数:18,代码来源:RouteDefinition.java

示例10: toResponse

import javax.validation.ValidationException; //导入依赖的package包/类
@Override
public Response toResponse(ValidationException e) {
    ApiErrorCode errorCode = ApiErrorCode.PARAM_ERROR;

    StringBuffer errorMsgBuf = new StringBuffer();
    
    final ConstraintViolationException cve = (ConstraintViolationException) e;
    List<ValidationError> errors = ValidationHelper.constraintViolationToValidationErrors(cve);
    for (ValidationError error : errors) {
        errorMsgBuf.append(error.getMessage()).append(";");
    }
    
    String errorMsg = errorMsgBuf.toString();
    if (StringUtils.isBlank(errorMsg)) {
        errorMsg = IMConstant.MSG_PARAM_ERROR;
    }        
    
    String requestId = RequestContext.get("requestId");
    
    ApiErrorCodeException errorCodeException = new ApiErrorCodeException(requestId, errorCode, errorMsg, e);
    logger.error(requestId, errorCodeException);

    return RestResult.failure(requestId, errorCode.errorCode, errorMsg);
}
 
开发者ID:projectsrepos,项目名称:jim,代码行数:25,代码来源:ImValidationExceptionMapper.java

示例11: testLocalityValidation

import javax.validation.ValidationException; //导入依赖的package包/类
@Test
public void testLocalityValidation()
{
  TestGeneratorInputOperator input1 = dag.addOperator("input1", TestGeneratorInputOperator.class);
  GenericTestOperator o1 = dag.addOperator("o1", GenericTestOperator.class);
  StreamMeta s1 = dag.addStream("input1.outport", input1.outport, o1.inport1).setLocality(Locality.THREAD_LOCAL);
  dag.validate();

  TestGeneratorInputOperator input2 = dag.addOperator("input2", TestGeneratorInputOperator.class);
  dag.addStream("input2.outport", input2.outport, o1.inport2);

  try {
    dag.validate();
    Assert.fail("Exception expected for " + o1);
  } catch (ValidationException ve) {
    Assert.assertThat("", ve.getMessage(), RegexMatcher.matches("Locality THREAD_LOCAL invalid for operator .* with multiple input streams .*"));
  }

  s1.setLocality(null);
  dag.validate();
}
 
开发者ID:apache,项目名称:apex-core,代码行数:22,代码来源:LogicalPlanTest.java

示例12: setup

import javax.validation.ValidationException; //导入依赖的package包/类
@Override
public void setup(DAGSetupPlugin.Context context)
{
  this.dag = context.getDAG();
  try {
    this.path = context.getConfiguration().get("propertyVisitor.Path");
    Properties properties = new Properties();
    properties.load(this.getClass().getResourceAsStream(path));
    for (Map.Entry<Object, Object> entry : properties.entrySet()) {
      propertyMap.put(entry.getKey().toString(), entry.getValue().toString());
    }
  } catch (IOException ex) {
    throw new ValidationException("Not able to load input file " + path);
  }
  context.register(PRE_VALIDATE_DAG, this);
}
 
开发者ID:apache,项目名称:apex-core,代码行数:17,代码来源:PropertyInjectorVisitor.java

示例13: validate

import javax.validation.ValidationException; //导入依赖的package包/类
public void validate() throws ValidationException
{
  if (accumulation == null) {
    throw new ValidationException("Accumulation must be set");
  }
  if (dataStorage == null) {
    throw new ValidationException("Data storage must be set");
  }
  if (windowStateMap == null) {
    throw new ValidationException("Window state storage must be set");
  }
  if (triggerOption != null) {
    if (triggerOption.isFiringOnlyUpdatedPanes()) {
      if (retractionStorage == null) {
        throw new ValidationException("A retraction storage is required for firingOnlyUpdatedPanes option");
      }
      if (triggerOption.getAccumulationMode() == TriggerOption.AccumulationMode.DISCARDING) {
        throw new ValidationException("DISCARDING accumulation mode is not valid for firingOnlyUpdatedPanes option");
      }
    }
    if (triggerOption.getAccumulationMode() == TriggerOption.AccumulationMode.ACCUMULATING_AND_RETRACTING &&
        retractionStorage == null) {
      throw new ValidationException("A retraction storage is required for ACCUMULATING_AND_RETRACTING accumulation mode");
    }
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:27,代码来源:AbstractWindowedOperator.java

示例14: create

import javax.validation.ValidationException; //导入依赖的package包/类
private void create(User user, Set<Test> tests, TestSuite parent) throws NotFoundException, ValidationException {
    for (final Test test : tests) {
        if (parent != null) {
            test.setParent(parent);
        }

        if (test instanceof TestCase) {
            create(user, test);
        } else {
            final TestSuite testSuite = (TestSuite) test;
            final Set<Test> testsInSuite = testSuite.getTests();

            testSuite.setTests(new HashSet<>());
            create(user, testSuite);
            create(user, testsInSuite, testSuite);
        }
    }
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:19,代码来源:TestDAOImpl.java

示例15: delete

import javax.validation.ValidationException; //导入依赖的package包/类
@Override
@Transactional
public void delete(User user, Long projectId, Long id) throws NotFoundException, ValidationException {
    if (id == 0) {
        throw new ValidationException("The root test suite cannot be deleted");
    }

    Test test = get(user, projectId, id);

    Test parent = test.getParent();
    if (parent != null) {
        ((TestSuite) parent).getTests().remove(test);
        test.setParent(null);
    }

    testRepository.delete(test);
}
 
开发者ID:LearnLib,项目名称:alex,代码行数:18,代码来源:TestDAOImpl.java


注:本文中的javax.validation.ValidationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。