43 lines
1.3 KiB
Java
43 lines
1.3 KiB
Java
package eu.eudat.commons.validation;
|
|
|
|
import eu.eudat.convention.ConventionService;
|
|
import eu.eudat.errorcode.ErrorThesaurusProperties;
|
|
import gr.cite.tools.exception.MyValidationException;
|
|
import java.util.*;
|
|
|
|
public abstract class BaseValidator<T> extends AbstractValidator<T> {
|
|
protected final ConventionService conventionService;
|
|
protected final ErrorThesaurusProperties errors;
|
|
|
|
protected BaseValidator(ConventionService conventionService, ErrorThesaurusProperties errors) {
|
|
this.conventionService = conventionService;
|
|
this.errors = errors;
|
|
}
|
|
|
|
@Override
|
|
public void validateForce(Object target) {
|
|
this.validate(target);
|
|
ValidationResult result = result();
|
|
if (!result.isValid()) {
|
|
List<Map.Entry<String, List<String>>> errorsMap = this.flattenValidationResult();
|
|
throw new MyValidationException(this.errors.getModelValidation().getCode(), errorsMap);
|
|
}
|
|
}
|
|
|
|
protected Boolean isValidGuid(UUID guid) {
|
|
return this.conventionService.isValidGuid(guid);
|
|
}
|
|
|
|
protected Boolean isValidHash(String hash) {
|
|
return this.conventionService.isValidHash(hash);
|
|
}
|
|
|
|
protected Boolean isEmpty(String value) {
|
|
return this.conventionService.isNullOrEmpty(value);
|
|
}
|
|
protected Boolean lessEqual(String value, int size) {
|
|
return value.length() <= size;
|
|
}
|
|
}
|
|
|