All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.convergence_platform.common.validations.StringNotContainsValidator Maven / Gradle / Ivy

Go to download

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 StringNotContainsValidator 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, "not_contain", varName);
    }

    @Override
    public void initialize(StringNotContains 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.contains(constraint);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy