Skip to content

Improve Validation code #74

@javier-godoy

Description

@javier-godoy

In order torun all the validators, you need to copy-paste the following code.

List<Validator<T>> validators = ((ValidationSupport<T>) this).getValidators(DeletionValidator.class);
List<ErrorDescription> errors = validators.stream().flatMap(val->val.validate(entity).stream()).collect(Collectors.toList());
if (!errors.isEmpty()) {
	throw new DeletionValidationException(errors);
}

There should be a utility method for that purpose. For instance, in ValidationSupport add:

List<ErrorDescription> validate(Class<Validator<T>> validatorType, T t) {
    List<Validator<T>> validators = ((ValidationSupport<T>) this).getValidators(validatorType);
    return validators.stream().flatMap(val -> val.validate(t).stream()).collect(Collectors.toList());
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions