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 Summary
ConstructorsConstructorDescriptionJpaCustomizedOfferRepository(com.broadleafcommerce.data.tracking.core.TrackableBehaviorUtil behaviorUtil, com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaFiltersCriteriaBuilder criteriaBuilder) -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected voidapplyRsqlCriteria(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) protected jakarta.persistence.criteria.PredicatebuildAutomaticOrCodeOrCustomerOffersPredicate(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) protected jakarta.persistence.criteria.Subquery<String>buildSharedCodesSubquery(jakarta.persistence.criteria.CriteriaQuery<JpaOffer> criteria, jakarta.persistence.criteria.CriteriaBuilder builder) protected jakarta.persistence.criteria.PredicatebuildTrackingOffersPredicate(Iterable<String> trackingIds, jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder, jakarta.persistence.criteria.Root<D> topRoot, Map<String, Object> params) protected jakarta.persistence.criteria.Subquery<String>buildTrackingSubquery(jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder) protected jakarta.persistence.criteria.Subquery<String>buildUserTargetSubquery(jakarta.persistence.criteria.CriteriaQuery<D> criteria, jakarta.persistence.criteria.CriteriaBuilder builder, int userTargetsSize) findAllCustomerOffers(Iterable<? extends UserTarget> userTargets, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Read all offers that have no user targets or contain the provided user targets.org.springframework.data.domain.Page<D>findAllGlobal(cz.jirutka.rsql.parser.ast.Node filters, String query, org.springframework.data.domain.Pageable pageable, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all offers in a tenant context that are active and not associated with an application.findAllOfferIdsForFullCache(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all contextIds for offer in the system based on full cache configuration.Read a list of distinct tenants for all offersfindAutomaticOffers(com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all offers whereOffer.isAutomaticallyConsidered()is true excluding any offers whose getActiveEndDate() is more than 30 days ago.findByOfferCodesCodeIn(Iterable<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads all offers whereOffer.offerCodesintersects with the provided codes.findByTrackingIds(Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all offers whereOffer.getCampaignTrackingIds()intersects with the provided tracking ids.findOffersMatchingSharedCodes(com.broadleafcommerce.data.tracking.core.context.ContextInfo context, List<String> sharedCodes) Read all offers whereOffer#sharedCode()matches one of the passed in codes excluding those with getActiveEndDate() more than 30 days ago.findVoucherOffers(Iterable<? extends UserTarget> userTargets, Iterable<String> offerIds, Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Read all voucher offers whereOffer.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.protected OfferCachePropertiesDeprecated, for removal: This API element is subject to removal in a future version.protected jakarta.persistence.EntityManagerprotected JpaPromotionQueryHelperprotected JpaOfferRepository<D>protected com.broadleafcommerce.common.jpa.RepositoryEntityTypeManagerprotected InstantnormalizeEndDateForAllAutomatic(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidsetCacheProperties(OfferCacheProperties cacheProperties) voidsetJpaPromotionQueryHelper(JpaPromotionQueryHelper jpaPromotionQueryHelper) voidsetRepository(JpaOfferRepository<D> repository) voidsetRepositoryEntityTypeManager(com.broadleafcommerce.common.jpa.RepositoryEntityTypeManager repositoryEntityTypeManager) voidsetRsqlQueryTransformers(List<com.broadleafcommerce.data.tracking.core.service.RsqlQueryTransformer> rsqlQueryTransformers) voidsetRsqlVisitor(com.broadleafcommerce.data.tracking.jpa.filtering.fetch.rsql.JpaCriteriaBuilderRsqlVisitor rsqlVisitor) intupdateMaxUsageStatus(String offerContextId, String status, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Update the status (seeMaxUsageStatusType) for an offer, and respond if the status was actually changed.
-
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:
afterPropertiesSetin interfaceorg.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:CustomizedOfferRepositoryReads all offers whereOffer.offerCodesintersects with the provided codes.- Specified by:
findByOfferCodesCodeInin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
codes- codes the returnedOffer(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:CustomizedOfferRepositoryRead all contextIds for offer in the system based on full cache configuration. SeeOfferCacheProperties.getFullOfferCacheType()for more information on how the configuration will influence the results of this method.- Specified by:
findAllOfferIdsForFullCachein interfaceCustomizedOfferRepository<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:CustomizedOfferRepositoryRead all offers whereOffer.isAutomaticallyConsidered()is true excluding any offers whose getActiveEndDate() is more than 30 days ago.- Specified by:
findAutomaticOffersin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
context- Context information around sandbox and multitenant state.- Returns:
- all offers where
Offer.isAutomaticallyConsidered()is true
-
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:CustomizedOfferRepositoryRead all offers whereOffer.getCampaignTrackingIds()intersects with the provided tracking ids.- Specified by:
findByTrackingIdsin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
trackingIds- Tracking ids to filter bycontext- 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:CustomizedOfferRepositoryRead all voucher offers whereOffer.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:
findVoucherOffersin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
userTargets- The targets to match offers againstofferIds- offer ids the returnedOffer(s) are associated with.trackingIds- tracking ids the returnedOffer(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:CustomizedOfferRepositoryRead all offers that have no user targets or contain the provided user targets.- Specified by:
findAllCustomerOffersin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
userTargets- The targets to match offers againstcontextInfo- 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:CustomizedOfferRepositoryUpdate the status (seeMaxUsageStatusType) for an offer, and respond if the status was actually changed.- Specified by:
updateMaxUsageStatusin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
offerContextId- The contextId of the offer to updatestatus- The status to set (seeMaxUsageStatusType)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
Description copied from interface:CustomizedOfferRepositoryRead a list of distinct tenants for all offers- Specified by:
findAllTenantsin interfaceCustomizedOfferRepository<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:CustomizedOfferRepositoryRead all offers in a tenant context that are active and not associated with an application.- Specified by:
findAllGlobalin interfaceCustomizedOfferRepository<D extends JpaOffer>- Parameters:
filters- Any RSQL filters to apply for refining the queryquery- The query string to filter bypageable- The paging informationcontext- Context information around sandbox and multitenant state.- Returns:
- A page of offers that are active and not associated with an application
-
buildUserTargetSubquery
-
buildTrackingSubquery
-
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
-
applyRsqlCriteria
-
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, usegetManagedType()instead. -
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
-
setCacheProperties
-
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
-
setRepository
-
getJpaPromotionQueryHelper
-
setJpaPromotionQueryHelper
-
getManagedType()instead.