Class FulfillmentValidationUtil
java.lang.Object
com.broadleafcommerce.cartoperation.service.fulfillment.validation.FulfillmentValidationUtil
Utility class with helper functions to perform validation.
- Author:
- Jacob Mitash
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
getField
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull Class<T> clazz) Gets the value from a field casted to the requested type.static boolean
hasHint
(@NonNull Collection<Object> hints, @NonNull String requestedHint) Tells if the specified hint is in the collection of hints.static void
rejectIfEmptyCollection
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull String errorCode) Rejects a collection value if it is empty or null.static void
rejectIfFalse
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull String errorCode) Rejects a value if it is non-null and false.static void
rejectIfNegative
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull String errorCode) Rejects a value if it is non-null and negative.static void
rejectIfNull
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull String errorCode) Rejects a value if it is null.static void
rejectIfTrue
(@NonNull org.springframework.validation.Errors errors, @NonNull String fieldName, @NonNull String errorCode) Rejects a value if it is non-null and true.static void
validateFields
(@NonNull org.springframework.validation.Errors errors, @NonNull Collection<String> fieldNames, @NonNull FulfillmentValidationUtil.FieldValidator fieldValidator, @NonNull String errorCodePattern) Validates multiple fields' values.
-
Constructor Details
-
FulfillmentValidationUtil
public FulfillmentValidationUtil()
-
-
Method Details
-
hasHint
public static boolean hasHint(@NonNull @NonNull Collection<Object> hints, @NonNull @NonNull String requestedHint) Tells if the specified hint is in the collection of hints.- Parameters:
hints
- the collection of hints to checkrequestedHint
- the hint to check if present- Returns:
- true if the hint is present, false otherwise
-
rejectIfNegative
public static void rejectIfNegative(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull String errorCode) Rejects a value if it is non-null and negative.- Parameters:
errors
- the errors container to pull the value and add the rejection tofieldName
- the name of the field to testerrorCode
- the error code to add to the errors
-
rejectIfNull
public static void rejectIfNull(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull String errorCode) Rejects a value if it is null.- Parameters:
errors
- the errors container to pull the value and add the rejection tofieldName
- the name of the field to testerrorCode
- the error code to add to the errors
-
rejectIfTrue
public static void rejectIfTrue(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull String errorCode) Rejects a value if it is non-null and true.- Parameters:
errors
- the errors container to pull the value and add the rejection tofieldName
- the name of the field to testerrorCode
- the error code to add to the errors
-
rejectIfFalse
public static void rejectIfFalse(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull String errorCode) Rejects a value if it is non-null and false.- Parameters:
errors
- the errors container to pull the value and add the rejection tofieldName
- the name of the field to testerrorCode
- the error code to add to the errors
-
rejectIfEmptyCollection
public static void rejectIfEmptyCollection(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull String errorCode) Rejects a collection value if it is empty or null.- Parameters:
errors
- the errors container to pull the value and add the rejection tofieldName
- the name of the field to testerrorCode
- the error code to add to the errors
-
getField
@Nullable public static <T> T getField(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull String fieldName, @NonNull @NonNull Class<T> clazz) Gets the value from a field casted to the requested type.- Type Parameters:
T
- the type the field value should be cast to- Parameters:
errors
- the errors container to grab the value fromfieldName
- the name of the field to fetch the value ofclazz
- the class the field value should be cast to- Returns:
- the value of the field
-
validateFields
public static void validateFields(@NonNull @NonNull org.springframework.validation.Errors errors, @NonNull @NonNull Collection<String> fieldNames, @NonNull @NonNull FulfillmentValidationUtil.FieldValidator fieldValidator, @NonNull @NonNull String errorCodePattern) Validates multiple fields' values.- Parameters:
errors
- the error container to pull values and add rejections tofieldNames
- the names of the fields to validatefieldValidator
- the validator that will validate the fields valueerrorCodePattern
- the error code with a '{}' in place of the field name (seeerrorCode(String, String)
)
-