Package org.kiwiproject.jaxrs
Class KiwiJaxrsValidations
java.lang.Object
org.kiwiproject.jaxrs.KiwiJaxrsValidations
Static utility methods that perform validation on an object or value, and throw an appropriate
subclass of
JaxrsException if there are validation errors.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertNotBlank(String fieldName, String value) Assert that the given String value is not blank.static voidassertNotNull(String fieldName, Object value) Assert that the given Object is not null.static voidassertTrue(boolean value, String message) Asserts that the given boolean value is true.static <T> voidassertValid(String id, T obj) Assert that the given object is valid using the default validation group.static <T> voidassertValid(String id, T obj, Class<?>... groupClasses) Assert that the given object is valid using the specified validation group classes.static <T> voidassertValid(String id, T obj, Map<String, String> propertyPathMappings) Assert that the given object is valid using the default validation group and the specified property path map, which allows callers to translate property paths (e.g. firstName) to a human-readable names (e.g.static <T> voidAssert that the given object is valid using the specified validation group classes and property path map.
-
Method Details
-
assertValid
Assert that the given object is valid using the default validation group.- Type Parameters:
T- the type of object- Parameters:
id- the unique identity or ID of the object being validatedobj- the object to validate- Throws:
JaxrsValidationException- if there are any validation errors- See Also:
-
Default
-
assertValid
Assert that the given object is valid using the specified validation group classes.Note that if you want the default validation group included, it must be in
groupClasses.- Type Parameters:
T- the type of object- Parameters:
id- the unique identity or ID of the object being validatedobj- the object to validategroupClasses- validation groups to apply during validation- Throws:
JaxrsValidationException- if there are any validation errors
-
assertValid
Assert that the given object is valid using the default validation group and the specified property path map, which allows callers to translate property paths (e.g. firstName) to a human-readable names (e.g. First Name).- Type Parameters:
T- the type of object- Parameters:
id- the unique identity or ID of the object being validatedobj- the object to validatepropertyPathMappings- mapping from property path to (human-readable) field name- Throws:
JaxrsValidationException- if there are any validation errors- See Also:
-
Default
-
assertValid
public static <T> void assertValid(String id, T obj, Map<String, String> propertyPathMappings, Class<?>... groupClasses) Assert that the given object is valid using the specified validation group classes and property path map.Note that if you want the default validation group included, it must be in
groupClasses.- Type Parameters:
T- the type of object- Parameters:
id- the unique identity or ID of the object being validatedobj- the object to validatepropertyPathMappings- mapping from property path to (human-readable) field namegroupClasses- validation groups to apply during validation- Throws:
JaxrsValidationException- if there are any validation errors
-
assertNotBlank
Assert that the given String value is not blank.- Parameters:
fieldName- the field name being validatedvalue- the String value to check- Throws:
JaxrsBadRequestException- if the value is blank- Implementation Note:
- Blank check is performed using
StringUtils.isBlank(CharSequence))
-
assertNotNull
Assert that the given Object is not null.- Parameters:
fieldName- the field name being validatedvalue- the value to check- Throws:
JaxrsBadRequestException- if the value is null
-
assertTrue
Asserts that the given boolean value is true.- Parameters:
value- the value to checkmessage- the message to use in the thrown exception- Throws:
JaxrsBadRequestException- if the value is false
-