2018-08-30 13:09:36 +02:00
|
|
|
package eu.eudat.models.validators.fluentvalidator;
|
|
|
|
|
|
|
|
import eu.eudat.models.validators.fluentvalidator.predicates.FieldSelector;
|
|
|
|
import org.springframework.validation.Errors;
|
|
|
|
import org.springframework.validation.Validator;
|
|
|
|
|
2018-08-31 16:12:31 +02:00
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2018-08-30 13:09:36 +02:00
|
|
|
/**
|
|
|
|
* Created by ikalyvas on 8/28/2018.
|
|
|
|
*/
|
2018-08-31 16:12:31 +02:00
|
|
|
public abstract class FluentValidator<T> implements Validator {
|
2018-08-30 13:09:36 +02:00
|
|
|
|
2018-08-31 16:12:31 +02:00
|
|
|
private List<FluentValidatorBuilder> fluentValidatorBuilders = new LinkedList<>();
|
2018-08-30 13:09:36 +02:00
|
|
|
|
2018-08-31 16:12:31 +02:00
|
|
|
public <R> FluentValidatorBuilder<T> ruleFor(FieldSelector<T, R> selector) {
|
|
|
|
FluentValidatorBuilder<T> fluentValidatorBuilder = new FluentValidatorBuilder<>(selector);
|
|
|
|
this.fluentValidatorBuilders.add(fluentValidatorBuilder);
|
|
|
|
return fluentValidatorBuilder;
|
2018-08-30 13:09:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-08-31 16:12:31 +02:00
|
|
|
public abstract boolean supports(Class<?> clazz);
|
2018-08-30 13:09:36 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void validate(Object target, Errors errors) {
|
2018-08-31 16:12:31 +02:00
|
|
|
List<FluentValidatorResult> validatorResults = new LinkedList<>();
|
2018-10-18 11:34:11 +02:00
|
|
|
//this.fluentValidatorBuilders.forEach(x-> validatorResults.addAll(x.validate(target)));
|
|
|
|
//validatorResults.forEach(x-> errors.rejectValue(x.getField(),x.getError()));
|
2018-08-30 13:09:36 +02:00
|
|
|
}
|
|
|
|
}
|