java.lang.Object
com.broadleafcommerce.catalog.provider.jpa.repository.asset.support.JpaAssetCriteriaUtils

public final class JpaAssetCriteriaUtils extends Object
Support class with convenience methods for criteria-building functionality common to custom JPA repository implementations.
Author:
Samarth Dhruva (samarthd)
  • Method Summary

    Modifier and Type
    Method
    Description
    static javax.persistence.criteria.Predicate
    buildAltTextLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    Builds a criteria that restricts results to only include entities whose alt-text (after applying an uppercase conversion) is like the given formattedSearchString.
    static javax.persistence.criteria.Predicate
    buildTitleLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    Builds a criteria that restricts results to only include entities whose title (after applying an uppercase conversion) is like the given formattedSearchString.
    static javax.persistence.criteria.Predicate
    buildUrlLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
    Builds a criteria that restricts results to only include entities whose URL (after applying an uppercase conversion) is like the given formattedSearchString.
    static String
    formatForSearch(String searchString)
    Accepts a search string and formats it for use in contains-ignore-case criteria.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • formatForSearch

      public static String formatForSearch(String searchString)
      Accepts a search string and formats it for use in contains-ignore-case criteria.

      Surrounds the given string with % wildcards and applies an uppercase conversion.

      TODO: also add logic to escape wildcards (and escape characters themselves)

      Parameters:
      searchString - the string to format for search
      Returns:
      the given string after applying an uppercase conversion and surrounding it with wildcard characters
    • buildUrlLikeFilter

      public static javax.persistence.criteria.Predicate buildUrlLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
      Builds a criteria that restricts results to only include entities whose URL (after applying an uppercase conversion) is like the given formattedSearchString.
      Parameters:
      formattedSearchString - the pre-formatted search string as prepared in formatForSearch(String)
      assetEntity - the asset entity on which the filter should be created
      criteriaBuilder - the criteria builder used to generate parameters/predicates
      parameterValues - a map of parameter names to argument values that will be used to run the query. Any parameter values required to perform the query should be added to this map.
      Returns:
      a criteria that restricts results to only include entities whose URL (after applying an uppercase conversion) is like the given formattedSearchString
    • buildTitleLikeFilter

      public static javax.persistence.criteria.Predicate buildTitleLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
      Builds a criteria that restricts results to only include entities whose title (after applying an uppercase conversion) is like the given formattedSearchString.
      Parameters:
      formattedSearchString - the pre-formatted search string as prepared in formatForSearch(String)
      assetEntity - the asset entity on which the filter should be created
      criteriaBuilder - the criteria builder used to generate parameters/predicates
      parameterValues - a map of parameter names to argument values that will be used to run the query. Any parameter values required to perform the query should be added to this map.
      Returns:
      a criteria that restricts results to only include entities whose title (after applying an uppercase conversion) is like the given formattedSearchString
    • buildAltTextLikeFilter

      public static javax.persistence.criteria.Predicate buildAltTextLikeFilter(String formattedSearchString, javax.persistence.criteria.Root<?> assetEntity, javax.persistence.criteria.CriteriaBuilder criteriaBuilder, Map<String,Object> parameterValues)
      Builds a criteria that restricts results to only include entities whose alt-text (after applying an uppercase conversion) is like the given formattedSearchString.
      Parameters:
      formattedSearchString - the pre-formatted search string as prepared in formatForSearch(String)
      assetEntity - the asset entity on which the filter should be created
      criteriaBuilder - the criteria builder used to generate parameters/predicates
      parameterValues - a map of parameter names to argument values that will be used to run the query. Any parameter values required to perform the query should be added to this map.
      Returns:
      a criteria that restricts results to only include entities whose alt-text (after applying an uppercase conversion) is like the given formattedSearchString