io.convergence_platform.common.validations.ValidateUUIDValidator 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;
import java.util.Base64;
import java.util.UUID;
public class ValidateUUIDValidator implements ConstraintValidator {
public static void pathVariable(String value, String varName) {
boolean valid = true;
if ("".equals(value)) {
valid = false;
} else {
valid = validate(value);
}
ValidationHelper.raiseValidationErrorForPathVariable(valid, "uuid", varName);
}
@Override
public boolean isValid(Object value, ConstraintValidatorContext context) {
return validate(value);
}
private static boolean validate(Object value) {
if (value instanceof UUID) {
return true;
}
if (!(value instanceof String)) {
return false;
}
try {
UUID.fromString((String) value);
} catch (IllegalArgumentException ex) {
return false;
}
return true;
}
}