Class LookupUtils

java.lang.Object
org.kuali.rice.krad.lookup.LookupUtils

public class LookupUtils extends Object
Provides static utility methods for use within the lookup framework.
Author:
Kuali Rice Team (rice.collab@kuali.org)
  • Method Details

    • retrieveLookupParameterValue

      public static String retrieveLookupParameterValue(UifFormBase form, javax.servlet.http.HttpServletRequest request, Class<?> lookupObjectClass, String propertyName, String parameterName)
      Retrieves the value for the given parameter name to send as a lookup parameter.
      Parameters:
      form - form instance to retrieve values from
      request - request object to retrieve parameters from
      lookupObjectClass - data object class associated with the lookup, used to check whether the value needs to be encyrpted
      propertyName - name of the property associated with the parameter, used to check whether the value needs to be encrypted
      parameterName - name of the parameter to retrieve the value for
      Returns:
      String parameter value or empty string if no value was found
    • getBaseLookupUrl

      public static String getBaseLookupUrl()
      Retrieves the default KRAD base lookup URL, used to build lookup URLs in code
      Returns:
      String base lookup URL (everything except query string)
    • forceUppercase

      public static String forceUppercase(Class<?> dataObjectClass, String fieldName, String fieldValue)
      Uses the DataDictionary to determine whether to force uppercase the value, and if it should, then it does the uppercase, and returns the upper-cased value.
      Parameters:
      dataObjectClass - parent DO class that the fieldName is a member of
      fieldName - name of the field to be forced to uppercase
      fieldValue - value of the field that may be uppercased
      Returns:
      the correctly uppercased fieldValue if it should be uppercased, otherwise fieldValue is returned unchanged
    • forceUppercase

      public static Map<String,String> forceUppercase(Class<?> dataObjectClass, Map<String,String> fieldValues)
      Uses the DataDictionary to determine whether to force uppercase the values, and if it should, then it does the uppercase, and returns the upper-cased Map of fieldname/fieldValue pairs.
      Parameters:
      dataObjectClass - parent DO class that the fieldName is a member of
      fieldValues - a Mapinvalid input: '<'String,String> where the key is the fieldName and the value is the fieldValue
      Returns:
      the same Map is returned, with the appropriate values uppercased (if any)
    • getSearchResultsLimit

      public static Integer getSearchResultsLimit(Class dataObjectClass, LookupForm lookupForm)
      Parses and returns the lookup result set limit, checking first for the limit for the specific view, then the class being looked up, and then the global application limit if there isn't a limit specific to this data object class.
      Parameters:
      dataObjectClass - class to get limit for
      lookupForm - lookupForm to use. May be null if the form is unknown. If lookupForm is null, only the dataObjectClass will be used to find the search results set limit
      Returns:
      result set limit
    • getApplicationSearchResultsLimit

      public static Integer getApplicationSearchResultsLimit()
      Retrieves the default application search limit configured through a system parameter.
      Returns:
      default result set limit of the application
    • getApplicationMultipleValueSearchResultsLimit

      public static Integer getApplicationMultipleValueSearchResultsLimit()
      Retrieves the default application multiple value search limit configured through a system parameter.
      Returns:
      default multiple value result set limit of the application
    • getActiveDateTimestampForCriteria

      public static Timestamp getActiveDateTimestampForCriteria(Map searchValues)
      Determines what Timestamp should be used for active queries on effective dated records. Determination made as follows:
      • Use activeAsOfDate value from search values Map if value is not empty
      • If search value given, try to convert to sql date, if conversion fails, try to convert to Timestamp
      • If search value empty, use current Date
      • If Timestamp value not given, create Timestamp from given Date setting the time as 1 second before midnight
      Parameters:
      searchValues - map containing search key/value pairs
      Returns:
      timestamp to be used for active criteria
    • preprocessDateFields

      public static Map<String,String> preprocessDateFields(Map<String,String> searchCriteria)
      Changes from/to dates into the range operators the lookupable dao expects ("..",">" etc) this method modifies the passed in map and returns an updated search criteria map.
      Parameters:
      searchCriteria - map of criteria currently set for which the date criteria will be adjusted
      Returns:
      map updated search criteria
    • hasExternalBusinessObjectProperty

      public static boolean hasExternalBusinessObjectProperty(Class<?> boClass, Map<String,String> fieldValues) throws IllegalAccessException, InstantiationException
      Checks whether any of the fieldValues being passed refer to a property within an ExternalizableBusinessObject.
      Parameters:
      boClass - business object class of the lookup
      fieldValues - map of the lookup criteria values
      Returns:
      true if externalizable business object are contained, false otherwise
      Throws:
      IllegalAccessException
      InstantiationException
    • isExternalBusinessObjectProperty

      public static boolean isExternalBusinessObjectProperty(Object sampleBo, String propertyName)
      Check whether the given property represents a property within an EBO starting with the sampleBo object given. This is used to determine if a criteria needs to be applied to the EBO first, before sending to the normal lookup DAO.
      Parameters:
      sampleBo - business object of the property to be tested
      propertyName - property name to be tested
      Returns:
      true if the property is within an externalizable business object.
    • removeExternalizableBusinessObjectFieldValues

      public static Map<String,String> removeExternalizableBusinessObjectFieldValues(Class<?> boClass, Map<String,String> fieldValues) throws IllegalAccessException, InstantiationException
      Returns a map stripped of any properties which refer to ExternalizableBusinessObjects. These values may not be passed into the lookup service, since the objects they refer to are not in the local database.
      Parameters:
      boClass - business object class of the lookup
      fieldValues - map of lookup criteria from which to remove the externalizable business objects
      Returns:
      map of lookup criteria without externalizable business objects
      Throws:
      IllegalAccessException
      InstantiationException
    • getExternalizableBusinessObjectFieldValues

      public static Map<String,String> getExternalizableBusinessObjectFieldValues(String eboPropertyName, Map<String,String> fieldValues)
      Return the EBO fieldValue entries explicitly for the given eboPropertyName. (I.e., any properties with the given property name as a prefix.
      Parameters:
      eboPropertyName - the externalizable business object property name to retrieve
      fieldValues - map of lookup criteria return map of lookup criteria for the given eboPropertyName
    • getExternalizableBusinessObjectProperties

      public static List<String> getExternalizableBusinessObjectProperties(Class<?> boClass, Map<String,String> fieldValues) throws IllegalAccessException, InstantiationException
      Get the complete list of all properties referenced in the fieldValues that are ExternalizableBusinessObjects.

      This is a list of the EBO object references themselves, not of the properties within them.

      Parameters:
      boClass - business object class of the lookup
      fieldValues - map of lookup criteria from which to return the externalizable business objects
      Returns:
      map of lookup criteria that are externalizable business objects
      Throws:
      IllegalAccessException
      InstantiationException
    • getExternalizableBusinessObjectClass

      public static Class<? extends ExternalizableBusinessObject> getExternalizableBusinessObjectClass(Class<?> boClass, String propertyName) throws IllegalAccessException, InstantiationException
      Given an property on the main BO class, return the defined type of the ExternalizableBusinessObject. This will be used by other code to determine the correct module service to call for the lookup.
      Parameters:
      boClass - business object class of the lookup
      propertyName - property of which the externalizable business object type is to be determined
      Returns:
      externalizable business object type
      Throws:
      IllegalAccessException
      InstantiationException
    • adjustCriteriaForNestedEBOs

      public static Map<String,String> adjustCriteriaForNestedEBOs(Class<?> dataObjectClass, Map<String,String> searchCriteria, boolean unbounded) throws InstantiationException, IllegalAccessException
      Looks for criteria against nested EBOs and performs a search against that EBO and updates the criteria.
      Parameters:
      searchCriteria - map of criteria currently set
      unbounded - indicates whether the complete result should be returned. When set to false the result is limited (if necessary) to the max search result limit configured.
      Returns:
      Map of adjusted criteria for nested EBOs
      Throws:
      InstantiationException
      IllegalAccessException
    • scrubQueryCharacters

      public static String scrubQueryCharacters(String criteriaValue)
      Removes query characters (such as wildcards) from the given string value.
      Parameters:
      criteriaValue - string to clean
      Returns:
      string with query characters removed
    • generateMultiValueKey

      public static String generateMultiValueKey(Object lineDataObject, List<String> fieldConversionKeys)
      Generates a key string in case of multivalue return. The values are extracted from the list of properties on the lineDataObject. If fieldConversionKeys is empty return the identifier string for the lineDataObject
      Parameters:
      lineDataObject - Object from which to extract values
      fieldConversionKeys - List of keys whose values have to be concatenated
      Returns:
      string representing the multivalue key
    • refreshLookupResultSelections

      public static void refreshLookupResultSelections(LookupForm form)
      Merges the lookup result selections that are part of the request with the selectedLookupResultsCache maintained in the session.
      Parameters:
      form - lookup form instance containing the selected results and lookup configuration