Class JpaCustomizedAssetRepository<D extends JpaAsset>

java.lang.Object
com.broadleafcommerce.asset.provider.jpa.repository.JpaCustomizedAssetRepository<D>
All Implemented Interfaces:
CustomizedAssetRepository<D>, org.springframework.beans.factory.InitializingBean

public class JpaCustomizedAssetRepository<D extends JpaAsset> extends Object implements CustomizedAssetRepository<D>, org.springframework.beans.factory.InitializingBean
Default implementation of CustomizedAssetRepository for JPA.
Author:
Nathan Moore (nathanmoore).
  • Constructor Summary

    Constructors
    Constructor
    Description
    JpaCustomizedAssetRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    applyRsqlCriteria(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<D> nativeQuery, Map<String,Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates)
    Processes the given filters to build and apply the necessary Predicate for RSQL.
    findByUrlAndStorageType(String url, String storageType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    Finds the asset whose url and storage type match the provided values.
    protected Class<D>
     
    protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper
     
    protected AssetRepository<D>
     
    protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer>
     
    protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor
     
    org.springframework.data.domain.Page<D>
    searchAll(String searchString, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable pageInfo, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    If searchString is provided, then this method will search for assets whose Asset.url, Asset.title, Asset.altText, or Asset.tags contain it.
    void
     

    Methods inherited from class java.lang.Object

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

    • JpaCustomizedAssetRepository

      public JpaCustomizedAssetRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder, com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • searchAll

      @Policy(operationTypes=READ) public org.springframework.data.domain.Page<D> searchAll(@Nullable String searchString, @NonNull cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable pageInfo, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CustomizedAssetRepository
      If searchString is provided, then this method will search for assets whose Asset.url, Asset.title, Asset.altText, or Asset.tags contain it.

      If no searchString is provided, then this method will simply return all assets.

      This method also supports RSQL filtration via filters.

      Specified by:
      searchAll in interface CustomizedAssetRepository<D extends JpaAsset>
      Parameters:
      searchString - (optional) a string which should be found in Asset.url, Asset.title, Asset.altText, or Asset.tags
      filters - additional filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      pageInfo - information about which page of results to return from the database
      contextInfo - context information surrounding sandboxing/multitenant state
      Returns:
      the assets matching the given search/filter arguments if provided, otherwise all assets
    • applyRsqlCriteria

      protected LinkedRSQLQueryDetails applyRsqlCriteria(cz.jirutka.rsql.parser.ast.Node filters, jakarta.persistence.criteria.CriteriaBuilder criteriaBuilder, jakarta.persistence.criteria.CriteriaQuery<D> nativeQuery, Map<String,Object> nativeQueryParams, List<jakarta.persistence.criteria.Predicate> nativePredicates)
      Processes the given filters to build and apply the necessary Predicate for RSQL.
      Parameters:
      filters - RSQL filters to apply in the query. Should be EmptyNode if no additional filters should be applied.
      criteriaBuilder - the criteria builder used to generate parameters/predicates. Only used as an argument to populate the CriteriaContext in CriteriaContext.withBuilder(CriteriaBuilder).
      nativeQuery - the native query for the original request. Only used as an argument to populate the CriteriaContext in CriteriaContext.withCriteriaQuery(AbstractQuery).
      nativeQueryParams - the parameter values for the nativeQuery. Only used as an argument to populate the CriteriaContext in CriteriaContext.withNarrowingParams(Map).
      nativePredicates - the list of predicates that will be applied on nativeQuery. If the filters are not for linked fields, then the Predicate will be added to this list.
      Returns:
      the CriteriaContext.getLinkedQuery() and CriteriaContext.getLinkedNarrowingParams() that were produced during processing. While the wrapper object will not be null, any/all of its fields can be (for example, if the filters were not on linked fields). These values are useful for ultimately being supplied to JpaNarrowingHelper.JpaCriterias.
    • findByUrlAndStorageType

      @Policy(operationTypes=READ) @NonNull public Optional<D> findByUrlAndStorageType(@NonNull String url, @Nullable String storageType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CustomizedAssetRepository
      Finds the asset whose url and storage type match the provided values.

      This is a custom repository method because there is a scenario where an asset in the tenant and an asset in a standard application can have the same URL. This scenario arises in the event that a standard-application asset is uploaded, and then on the tenant an asset with the same URL is uploaded. Due to the mechanism by which application discrimination works, the tenant asset upload will succeed because the standard-application asset will not be visible in the tenant context, and therefore will not be recognized as a duplicate.

      This ultimately means that "findByUrlAndStorageType" can potentially return more than one result, which is undesirable. The target behavior should be that if an asset with the given URL is found in both the tenant and standard-application contexts, the standard-application asset should be returned.

      Specified by:
      findByUrlAndStorageType in interface CustomizedAssetRepository<D extends JpaAsset>
      Parameters:
      url - the url which should match with Asset.url
      storageType - (optional) the storage type which should match with Asset.storageType. If left null, results will not be filtered by storage type.
      contextInfo - context information around sandboxing and multitenant state
      Returns:
      an optional containing the asset whose url and storage type (optional) match the provided values, empty otherwise
    • getManagedType

      protected Class<D> getManagedType()
    • getRepository

      protected AssetRepository<D> getRepository()
    • setRepository

      @Autowired @Lazy public void setRepository(AssetRepository<D> repository)
    • getRsqlQueryTransformers

      @NonNull protected List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> getRsqlQueryTransformers()
    • getRsqlVisitor

      @NonNull protected com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor getRsqlVisitor()
    • getNarrowingHelper

      protected com.broadleafcommerce.data.tracking.jpa.filtering.narrow.JpaNarrowingHelper getNarrowingHelper()