Class KiwiJaxrsValidations


  • public class KiwiJaxrsValidations
    extends Object
    Static utility methods that perform validation on an object or value, and throw an appropriate subclass of JaxrsException if there are validation errors.
    • Constructor Detail

      • KiwiJaxrsValidations

        public KiwiJaxrsValidations()
    • 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 validated
        obj - 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 validated
        obj - the object to validate
        groupClasses - 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 validated
        obj - the object to validate
        propertyPathMappings - 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 validated
        obj - the object to validate
        propertyPathMappings - mapping from property path to (human-readable) field name
        groupClasses - 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 validated
        value - 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 validated
        value - 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 check
        message - the message to use in the thrown exception
        Throws:
        JaxrsBadRequestException - if the value is false