Class BambooValidationUtils


  • public class BambooValidationUtils
    extends Object
    General utility methods for validation.
    • Constructor Detail

      • BambooValidationUtils

        public BambooValidationUtils()
    • Method Detail

      • validateField

        public static void validateField​(@NotNull
                                         @NotNull String fieldName,
                                         boolean validationCondition,
                                         @NotNull
                                         @NotNull Supplier<String> errorMessageSupplier)
                                  throws WebValidationException

        Validate any input field, checking if the given condition is fulfilled. If not, a WebValidationException will be thrown.

        This method is designated to be used when verifying a specific field from any data (e.g. a form). If you want to verify general conditions not related to a specific field, use validate(boolean, Supplier) instead.

        Parameters:
        fieldName - name of the field being verified
        validationCondition - condition to verify
        errorMessageSupplier - a supplier for a lazily evaluated error message to be used in the WebValidationException if the condition is not met; lambda expressions are welcome here as they allow to avoid using internationalization if it is not necessary
        Throws:
        WebValidationException - thrown if the given condition is not fulfilled. The exception will have one field error and no general errors. Field name and error message from method arguments will be used to construct the exception.
      • validate

        public static void validate​(boolean validationCondition,
                                    @NotNull
                                    @NotNull Supplier<String> errorMessageSupplier)
                             throws WebValidationException

        Validate any input data, checking if the given condition is fulfilled. If not, a WebValidationException will be thrown.

        This method is designated to be used when verifying general conditions (e.g. a state of an entire form). If the data being verified is related to a specific field, use validateField(String, boolean, Supplier) instead.

        Parameters:
        validationCondition - condition to verify
        errorMessageSupplier - a supplier for lazily evaluated general error message to be used in the WebValidationException if the condition is not met; lambda expressions are welcome here as they allow to avoid using internationalization if it is not necessary
        Throws:
        WebValidationException - thrown if the given condition is not fulfilled. The exception will have one general error and no field errors.
      • isStringRepresentingEnum

        public static boolean isStringRepresentingEnum​(@NotNull
                                                       @NotNull Class<? extends Enum> enumClass,
                                                       @Nullable
                                                       @Nullable String value)
        Test if string represent an enum of given type.
        Parameters:
        enumClass - enum type
        value - value to check
        Returns:
        iff string is an enum constant