org.springframework.batch.item.validator.ValidationException Java Examples

The following examples show how to use org.springframework.batch.item.validator.ValidationException. 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: CsvBeanValidator.java    From Demo with Apache License 2.0 5 votes vote down vote up
@Override
public void validate(T t) throws ValidationException {
    // 使用 validator 的 validate 方法校验数据
    Set<ConstraintViolation<T>> constraintViolations = validator.validate(t);

    if (constraintViolations.size() > 0){
        StringBuilder message = new StringBuilder();
        for (ConstraintViolation<T> constraintViolation : constraintViolations){
            message.append(constraintViolation.getMessage() + "\n");
        }
        throw new ValidationException(message.toString());
    }
}
 
Example #2
Source File: MyBeanValidator.java    From SpringBootBucket with MIT License 5 votes vote down vote up
@Override
public void validate(T value) throws ValidationException {
    /*
     * 使用Validator的validate方法校验数据
     */
    Set<ConstraintViolation<T>> constraintViolations = validator.validate(value);
    if (constraintViolations.size() > 0) {
        StringBuilder message = new StringBuilder();
        for (ConstraintViolation<T> constraintViolation : constraintViolations) {
            message.append(constraintViolation.getMessage()).append("\n");
        }
        throw new ValidationException(message.toString());
    }
}
 
Example #3
Source File: ValidatingItemProcessorDemo.java    From SpringAll with MIT License 5 votes vote down vote up
private ValidatingItemProcessor<TestData> validatingItemProcessor() {
    ValidatingItemProcessor<TestData> processor = new ValidatingItemProcessor<>();
    processor.setValidator(value -> {
        // 对每一条数据进行校验
        if ("".equals(value.getField3())) {
            // 如果field3的值为空串,则抛异常
            throw new ValidationException("field3的值不合法");
        }
    });
    return processor;
}
 
Example #4
Source File: DeptIDValidProcesor.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public DeptIDValidProcesor() {
    super(
        item -> {
            if (item.getDeptid() < 400) {
                throw new ValidationException("Customer ID lower than 400...");
            }
        }
    );
    setFilter(true);
}
 
Example #5
Source File: DeptIDValidProcesor.java    From Spring-5.0-Cookbook with MIT License 5 votes vote down vote up
public DeptIDValidProcesor() {
    super(
        item -> {
            if (item.getDeptid() < 400) {
                throw new ValidationException("Customer ID lower than 400...");
            }
        }
    );
    setFilter(true);
}
 
Example #6
Source File: TransactionValidatingProcessor.java    From spring-batch-article with MIT License 5 votes vote down vote up
public TransactionValidatingProcessor(final int limit) {
    super(
        item -> {
            if (item.getTransactions() >= limit) {
                throw new ValidationException("Customer has more than " + limit + " transactions");
            }
            log.info("Customer {} matched the transaction filter", item);
        }
    );
    setFilter(true);
}