Package com.atlassian.bamboo.utils
Class BambooValidationUtils
java.lang.Object
com.atlassian.bamboo.utils.BambooValidationUtils
General utility methods for validation.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
checkErrors
(@NotNull ErrorCollection errorCollection) static boolean
isStringRepresentingEnum
(@NotNull Class<? extends Enum> enumClass, @Nullable String value) Test if string represent an enum of given type.static void
Deprecated.static void
Validate any input data, checking if the given condition is fulfilled.static void
validateField
(@NotNull String fieldName, boolean validationCondition, @NotNull Supplier<String> errorMessageSupplier) Validate any input field, checking if the given condition is fulfilled.
-
Constructor Details
-
BambooValidationUtils
public BambooValidationUtils()
-
-
Method Details
-
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 verifiedvalidationCondition
- condition to verifyerrorMessageSupplier
- a supplier for a lazily evaluated error message to be used in theWebValidationException
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
@Deprecated public static void validate(boolean validationCondition, @NotNull @NotNull String errorMessage) throws WebValidationException Deprecated.since 5.10 usevalidate(boolean, Supplier)
- Throws:
WebValidationException
-
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 verifyerrorMessageSupplier
- a supplier for lazily evaluated general error message to be used in theWebValidationException
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.
-
checkErrors
public static void checkErrors(@NotNull @NotNull ErrorCollection errorCollection) throws WebValidationException - Parameters:
errorCollection
- an error collection (a result of any data validation)- Throws:
WebValidationException
- thrown if the passed error collection contains any errors. This exception will be constructed using the error collection.
-
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 typevalue
- value to check- Returns:
- iff string is an enum constant
-
validate(boolean, Supplier)