Class ValidationUtils

java.lang.Object
org.kuali.rice.krad.datadictionary.validation.ValidationUtils

public class ValidationUtils extends Object
ValidationUtils provides static utility methods for validation processing

Inherited from Kuali Student and adapted extensively

Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Constructor Details

    • ValidationUtils

      public ValidationUtils()
  • Method Details

    • buildPath

      public static String buildPath(String attributePath, String attributeName)
      constructs a path by appending the attribute name to the provided path
      Parameters:
      attributePath - - a string representation of specifically which attribute (at some depth) is being accessed
      attributeName - - the attribute name
      Returns:
      the path
    • getLastPathIndex

      public static int getLastPathIndex(String attributePath)
      Used to get the rightmost index value of an attribute path.
      Parameters:
      attributePath -
      Returns:
      the right index of value of attribute path, -1 if path has no index
    • compareValues

      public static boolean compareValues(Object fieldValue, Object whenValue, org.kuali.rice.core.api.data.DataType dataType, String operator, boolean isCaseSensitive, org.kuali.rice.core.api.datetime.DateTimeService dateTimeService)
      compares the value provided by the user and the one specified by the WhenConstraint
      Parameters:
      fieldValue - the value found in the field specified by a CaseConstraint's propertyName
      whenValue - the value specified by a WhenConstraint
      dataType - the data type of the field which caseConstraint's propertyName refers to
      operator - the relationship to check between the fieldValue and the whenValue
      isCaseSensitive - whether string comparison will be carried out in a case sensitive fashion
      dateTimeService - used to convert strings to dates
      Returns:
      true if the value matches the constraint
    • getInteger

      public static Integer getInteger(Object o)
      converts the provided object into an integer
      Parameters:
      o - - the object to convert
      Returns:
      the integer value
    • getLong

      public static Long getLong(Object o)
      converts the provided object into a long
      Parameters:
      o - - the object to convert
      Returns:
      the long value
    • getFloat

      public static Float getFloat(Object o)
      converts the provided object into an float
      Parameters:
      o - - the object to convert
      Returns:
      the float value
    • getDouble

      public static Double getDouble(Object o)
      converts the provided object into a double
      Parameters:
      o - - the object to convert
      Returns:
      the double value
    • getDate

      public static Date getDate(Object object, org.kuali.rice.core.api.datetime.DateTimeService dateTimeService) throws IllegalArgumentException
      determines whether the provided object is a date and tries to converts non-date values
      Parameters:
      object - - the object to convert/cast into a date
      dateTimeService - - used to convert strings to dates
      Returns:
      a date object
      Throws:
      IllegalArgumentException
    • getString

      public static String getString(Object o)
      converts the provided object into a string
      Parameters:
      o - - the object to convert
      Returns:
      the string value
    • getBoolean

      public static Boolean getBoolean(Object o)
      converts the provided object into a boolean
      Parameters:
      o - - the object to convert
      Returns:
      the boolean value
    • hasText

      public static boolean hasText(String string)
      checks whether the string contains non-whitespace characters
      Parameters:
      string -
      Returns:
      true if the string contains at least one none-whitespace character, false otherwise
    • isNullOrEmpty

      public static boolean isNullOrEmpty(Object value)
      Checks whether the provided object is null, or if a String, List, Set or Map is empty.
      Parameters:
      value - - the object to check
      Returns:
      true if the object is null or if a String, List, Set, or Map is empty, false otherwise
    • convertToDataType

      public static Object convertToDataType(Object value, org.kuali.rice.core.api.data.DataType dataType, org.kuali.rice.core.api.datetime.DateTimeService dateTimeService) throws AttributeValidationException
      attempts to convert the provided value to the given dataType
      Parameters:
      value - - the object to convert
      dataType - - the data type to convert into
      dateTimeService - - used to convert strings to dates
      Returns:
      the converted value if null or successful, otherwise throws an exception
      Throws:
      AttributeValidationException
    • isGreaterThan

      public static <T> ValidationUtils.Result isGreaterThan(T value, Comparable<T> limit)
      checks whether the provided value is greater than the limit given
      Type Parameters:
      T -
      Parameters:
      value - - the object to check
      limit - - the limit to use
      Returns:
      one of the values in ValidationUtils.Result
    • isGreaterThanOrEqual

      public static <T> ValidationUtils.Result isGreaterThanOrEqual(T value, Comparable<T> limit)
      checks whether the provided value is greater than or equal to the limit given
      Type Parameters:
      T -
      Parameters:
      value - - the object to check
      limit - - the limit to use
      Returns:
      one of the values in ValidationUtils.Result
    • isLessThan

      public static <T> ValidationUtils.Result isLessThan(T value, Comparable<T> limit)
      checks whether the provided value is less than the limit given
      Type Parameters:
      T -
      Parameters:
      value - - the object to check
      limit - - the limit to use
      Returns:
      one of the values in ValidationUtils.Result
    • isLessThanOrEqual

      public static <T> ValidationUtils.Result isLessThanOrEqual(T value, Comparable<T> limit)
      checks whether the provided value is greater than the limit given
      Type Parameters:
      T -
      Parameters:
      value - - the object to check
      limit - - the limit to use
      Returns:
      one of the values in ValidationUtils.Result
    • getPathTokens

      public static String[] getPathTokens(String fieldPath)
      converts a path into an array of its path components
      Parameters:
      fieldPath - - a string representation of specifically which attribute (at some depth) is being accessed
      Returns:
      the array of path components