Package org.kiwiproject.jaxrs
Class KiwiJaxrsValidations
- java.lang.Object
-
- org.kiwiproject.jaxrs.KiwiJaxrsValidations
-
public class KiwiJaxrsValidations extends Object
Static utility methods that perform validation on an object or value, and throw an appropriate subclass ofJaxrsExceptionif there are validation errors.
-
-
Constructor Summary
Constructors Constructor Description KiwiJaxrsValidations()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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.static <T> voidassertValid(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.
-
-
-
Method Detail
-
assertValid
public static <T> void assertValid(String id, T obj)
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
public static <T> void assertValid(String id, T obj, Class<?>... groupClasses)
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
public static <T> void assertValid(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. 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
public static void assertNotBlank(String fieldName, String value)
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
public static void assertNotNull(String fieldName, Object value)
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
public static void assertTrue(boolean value, String message)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
-
-