io.convergence_platform.common.validations.StringNotEndsWithValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of service-lib Show documentation
Show all versions of service-lib Show documentation
Holds the common functionality needed by all Convergence Platform-based services written in Java.
The newest version!
package io.convergence_platform.common.validations;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
public class StringNotEndsWithValidator implements ConstraintValidator {
private String value;
public static void pathVariable(String value, String constraint, String varName) {
boolean valid = true;
if ("".equals(value)) {
valid = false;
} else {
valid = validate(value, constraint);
}
ValidationHelper.raiseValidationErrorForPathVariable(valid, "string_not_end_with", varName);
}
@Override
public void initialize(StringNotEndsWith constraintAnnotation) {
ConstraintValidator.super.initialize(constraintAnnotation);
value = constraintAnnotation.value();
}
@Override
public boolean isValid(String value, ConstraintValidatorContext context) {
return validate(value, this.value);
}
private static boolean validate(String value, String constraint) {
if (value == null) {
return false;
}
return !value.endsWith(constraint);
}
}