Class JpaCustomizedOfferRepository<D extends JpaOffer>

java.lang.Object
com.broadleafcommerce.promotion.offer.provider.jpa.repository.JpaCustomizedOfferRepository<D>
All Implemented Interfaces:
CustomizedOfferRepository<D>, org.springframework.beans.factory.InitializingBean

public class JpaCustomizedOfferRepository<D extends JpaOffer> extends Object implements CustomizedOfferRepository<D>, org.springframework.beans.factory.InitializingBean
Author:
Chad Harchar (charchar)
  • Constructor Details

    • JpaCustomizedOfferRepository

      public JpaCustomizedOfferRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder)
  • Method Details

    • afterPropertiesSet

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

      public List<D> findByOfferCodesCodeIn(Iterable<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Reads all offers where Offer.offerCodes intersects with the provided codes.
      Specified by:
      findByOfferCodesCodeIn in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      codes - codes the returned Offer(s) are associated with.
      context - Context information around sandbox and multitenant state.
      Returns:
      all Offers associated to the provided codes.
    • findAllOfferIdsForFullCache

      public List<String> findAllOfferIdsForFullCache(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Read all contextIds for offer in the system based on full cache configuration. See OfferCacheProperties.getFullOfferCacheType() for more information on how the configuration will influence the results of this method.
      Specified by:
      findAllOfferIdsForFullCache in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      context - Context information around sandbox and multitenant state.
      Returns:
      All contextIds for offers in the system limited by the cache type configuration.
    • findAutomaticOffers

      public Stream<D> findAutomaticOffers(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Read all offers where Offer.isAutomaticallyConsidered() is true excluding any offers whose getActiveEndDate() is more than 30 days ago.
      Specified by:
      findAutomaticOffers in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      context - Context information around sandbox and multitenant state.
      Returns:
      all offers where Offer.isAutomaticallyConsidered() is true
    • findOffersMatchingSharedCodes

      public Stream<D> findOffersMatchingSharedCodes(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context, List<String> sharedCodes)
      Description copied from interface: CustomizedOfferRepository
      Read all offers where Offer#sharedCode() matches one of the passed in codes excluding those with getActiveEndDate() more than 30 days ago.
      Specified by:
      findOffersMatchingSharedCodes in interface CustomizedOfferRepository<D extends JpaOffer>
      sharedCodes - List of offer codes to find matching offers.
      Returns:
      all offers where Offer.sharedCode matches one of the passed in sharedCodes
    • normalizeEndDateForAllAutomatic

      protected Instant normalizeEndDateForAllAutomatic(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
    • findByTrackingIds

      public List<D> findByTrackingIds(Iterable<String> trackingIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Read all offers where Offer.getCampaignTrackingIds() intersects with the provided tracking ids.
      Specified by:
      findByTrackingIds in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      trackingIds - Tracking ids to filter by
      context - Context information around sandbox and multitenant state.
      Returns:
      All matched offers
    • findVoucherOffers

      public Stream<D> findVoucherOffers(Iterable<? extends UserTarget> userTargets, Iterable<String> offerIds, Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Read all voucher offers where Offer.isAutomaticallyConsidered() is true, Offer.getCampaignTrackingIds() intersects with the provided tracking ids, Offer.getOfferCodes() intersects with the provided codes, or offers that contain the provided user targets. Skips active date narrowing to fetch voucher offers for validation against submitted orders.
      Specified by:
      findVoucherOffers in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      userTargets - The targets to match offers against
      offerIds - offer ids the returned Offer(s) are associated with.
      trackingIds - tracking ids the returned Offer(s) are associated with.
      context - Context information around sandbox and multitenant state.
      Returns:
      all voucher offers where Offer.isAutomaticallyConsidered() is true, or the offer is associated with the provided codes, tracking ids, or user targets.
    • findAllCustomerOffers

      public Stream<D> findAllCustomerOffers(Iterable<? extends UserTarget> userTargets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CustomizedOfferRepository
      Read all offers that have no user targets or contain the provided user targets.
      Specified by:
      findAllCustomerOffers in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      userTargets - The targets to match offers against
      contextInfo - Context information around sandbox and multitenant state.
      Returns:
      all offers that have no user targets or contain the provided user targets.
    • updateMaxUsageStatus

      public int updateMaxUsageStatus(String offerContextId, String status, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Description copied from interface: CustomizedOfferRepository
      Update the status (see MaxUsageStatusType) for an offer, and respond if the status was actually changed.
      Specified by:
      updateMaxUsageStatus in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      offerContextId - The contextId of the offer to update
      status - The status to set (see MaxUsageStatusType)
      contextInfo - Context containing tenant related information (specifically tenantId and applicationId) to use to further discriminate the change
      Returns:
      The number of records updated, if any. It is expected this method is called under load, so the response is a useful measure to detect when the value is actually updated. This is in contrast to other possible duplicate and ineffectual attempts.
    • findAllTenants

      public Set<String> findAllTenants()
      Description copied from interface: CustomizedOfferRepository
      Read a list of distinct tenants for all offers
      Specified by:
      findAllTenants in interface CustomizedOfferRepository<D extends JpaOffer>
      Returns:
      List of distinct tenants
    • findAllGlobal

      public org.springframework.data.domain.Page<D> findAllGlobal(cz.jirutka.rsql.parser.ast.Node filters, @Nullable String query, @Nullable org.springframework.data.domain.Pageable pageable, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CustomizedOfferRepository
      Read all offers in a tenant context that are active and not associated with an application.
      Specified by:
      findAllGlobal in interface CustomizedOfferRepository<D extends JpaOffer>
      Parameters:
      filters - Any RSQL filters to apply for refining the query
      query - The query string to filter by
      pageable - The paging information
      context - Context information around sandbox and multitenant state.
      Returns:
      A page of offers that are active and not associated with an application
    • buildUserTargetSubquery

      protected jakarta.persistence.criteria.Subquery<String> buildUserTargetSubquery(jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder, int userTargetsSize)
    • buildSharedCodesSubquery

      protected jakarta.persistence.criteria.Subquery<String> buildSharedCodesSubquery(jakarta.persistence.criteria.CriteriaQuery<JpaOffer> criteria, jakarta.persistence.criteria.CriteriaBuilder builder)
    • buildTrackingSubquery

      protected jakarta.persistence.criteria.Subquery<String> buildTrackingSubquery(jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder)
    • buildAutomaticOrCodeOrCustomerOffersPredicate

      protected jakarta.persistence.criteria.Predicate buildAutomaticOrCodeOrCustomerOffersPredicate(Iterable<? extends UserTarget> userTargets, Iterable<String> offerIdsToFilterOn, Iterable<String> trackingIds, jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> topRoot, Map<String,Object> params)
    • buildTrackingOffersPredicate

      protected jakarta.persistence.criteria.Predicate buildTrackingOffersPredicate(Iterable<String> trackingIds, jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> topRoot, Map<String,Object> params)
    • applyRsqlCriteria

      protected 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)
    • getEntityClass

      @Deprecated(forRemoval=true, since="3.0.3, 3.1.0") @NotNull protected @NotNull Class<D> getEntityClass()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Method had a hardcoded entity reference that prevents from accepting extended entities, use getManagedType() instead.
    • getManagedType

      protected Class<D> getManagedType()
    • setRsqlQueryTransformers

      @Autowired public void setRsqlQueryTransformers(@Nullable List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers)
    • setRsqlVisitor

      @Autowired public void setRsqlVisitor(@Nullable com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor)
    • getCacheProperties

      @Nullable protected OfferCacheProperties getCacheProperties()
    • setCacheProperties

      @Autowired(required=false) public void setCacheProperties(OfferCacheProperties cacheProperties)
    • getEntityManager

      protected jakarta.persistence.EntityManager getEntityManager()
    • setRepositoryEntityTypeManager

      @Autowired @Lazy public void setRepositoryEntityTypeManager(com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager)
    • getRepositoryEntityTypeManager

      protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager getRepositoryEntityTypeManager()
    • getRepository

      protected JpaOfferRepository<D> getRepository()
    • setRepository

      @Autowired @Lazy public void setRepository(JpaOfferRepository<D> repository)
    • getJpaPromotionQueryHelper

      protected JpaPromotionQueryHelper getJpaPromotionQueryHelper()
    • setJpaPromotionQueryHelper

      @Autowired public void setJpaPromotionQueryHelper(JpaPromotionQueryHelper jpaPromotionQueryHelper)