Class DefaultOfferService<P extends Offer>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.promotion.offer.service.DefaultOfferService<P>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
,OfferService<P>
,EventListener
,org.springframework.context.ApplicationListener<PromotionCacheInvalidationEvent>
public class DefaultOfferService<P extends Offer>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
implements OfferService<P>, org.springframework.context.ApplicationListener<PromotionCacheInvalidationEvent>
- Author:
- Nathan Moore (nathanmoore).
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultOfferService
(OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
buildCodeResponsesForFilters
(Set<P> all, EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.data.tracking.core.context.ContextInfo>
buildInfos
(String tenant, String application) protected void
cacheAllOffers
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) If applicable, cache all active offer in the database into cache memory store for efficient retrieval.convertFromDomain
(List<com.broadleafcommerce.data.tracking.core.Trackable> offers, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse
createCodeResponse
(OfferNotAppliedReasonEnum notUsedReason) boolean
existsById
(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns whether the offer with the given id exists in the data storeboolean
existsByIdAndActive
(String id, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns whether the offer with the given id exists and is active in the data store.protected List<com.broadleafcommerce.data.tracking.core.context.ContextInfo>
protected com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication>
protected OfferCacheProperties
protected CampaignService<Campaign>
protected org.springframework.context.MessageSource
protected com.broadleafcommerce.common.extension.TypeFactory
protected OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable>
void
init()
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
normalize
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) void
protected List<com.broadleafcommerce.data.tracking.core.Trackable>
processOfferByIdForCache
(List<String> notCached, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve offers by ids for the purpose of caching.pruneInactiveTrackingIds
(Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readActiveByIds
(Iterable<String> offerIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers filtering where contextId inofferIds
.readAllActiveByCodesIn
(Iterable<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers whereOffer.getOfferCodes()
intersects with the provided codes.readAllByContextIdInOrExternalIdIn
(Iterable<String> contextIds, Iterable<String> externalIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<P>
readAllByName
(String name, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) readAllCustomerOffersIn
(Iterable<UserTarget> userTargets, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers whereOffer.userTargets
intersects with the providedUserTarget
s, or the offer has noUserTarget
sreadAutomaticAndCodeAndCustomerOffersIn
(Iterable<String> offerIdsToFilterOn, Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) readAutomaticAndCodeAndCustomerOffersIn
(Iterable<String> offerIdsToFilterOn, Iterable<String> trackingIds, EnhancedOrder order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers whereOffer.isAutomaticallyConsidered()
is true or the offers match the passed in offerIds or contain the passed in campaign trackingIds.readAutomaticOffers
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) readByIds
(Iterable<String> offerIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all offers filtering where contextId inofferIds
.readByTrackingIds
(Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers having one or more matches to the requested tracking ids.readVoucherOffersIn
(Iterable<UserTarget> userTargets, Iterable<String> offerIds, Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all voucher offers based on the provided user targets, codes, or tracking ids.void
setApplicationRepository
(com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication> applicationRepository) void
setCacheProperties
(OfferCacheProperties cacheProperties) void
setCampaignService
(CampaignService<Campaign> campaignService) void
setMessageSource
(org.springframework.context.MessageSource messageSource) void
setOfferFactory
(com.broadleafcommerce.common.extension.TypeFactory offerFactory) Call to launch an async process to warm the full offer cache, if enabled.Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService
getRsqlHelper, readAll, readAll, readAll, readAll
Methods inherited from class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService
convertFromPersistentDomain, convertToPersistentDomain, create, createAll, createAllAllowingPartialSuccess, delete, getHelper, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, update, updateAll, updateAllAllowingPartialSuccess, updateSort
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
create, createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replace, replaceAll, replaceAllAllowingPartialSuccess, update, updateAll, updateAllAllowingPartialSuccess, updateSort
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Field Details
-
CACHE_BY_IDS
- See Also:
-
CACHE_BY_AUTOMATIC
- See Also:
-
CACHE_BY_TRACKING
- See Also:
-
CACHE_BY_USER_TARGETS
- See Also:
-
CACHE_BY_VOUCHER
- See Also:
-
-
Constructor Details
-
DefaultOfferService
public DefaultOfferService(OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> repository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager, com.broadleafcommerce.data.tracking.core.filtering.fetch.FilterParser<cz.jirutka.rsql.parser.ast.Node> parser)
-
-
Method Details
-
init
@PostConstruct public void init() -
onApplicationEvent
-
readAutomaticAndCodeAndCustomerOffersIn
public Stream<P> readAutomaticAndCodeAndCustomerOffersIn(Iterable<String> offerIdsToFilterOn, Iterable<String> trackingIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
readAutomaticAndCodeAndCustomerOffersIn
in interfaceOfferService<P extends Offer>
-
readAutomaticAndCodeAndCustomerOffersIn
public Stream<P> readAutomaticAndCodeAndCustomerOffersIn(Iterable<String> offerIdsToFilterOn, Iterable<String> trackingIds, @Nullable EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all active offers whereOffer.isAutomaticallyConsidered()
is true or the offers match the passed in offerIds or contain the passed in campaign trackingIds.- Specified by:
readAutomaticAndCodeAndCustomerOffersIn
in interfaceOfferService<P extends Offer>
- Parameters:
offerIdsToFilterOn
- offerIds the returnedOffer
(s) are associated with.trackingIds
- tracking ids the returnedOffer
(s) are associated with.order
- the order for this requestcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- the offers matching the given criteria
-
buildCodeResponsesForFilters
protected void buildCodeResponsesForFilters(Set<P> all, EnhancedOrder order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
pruneInactiveTrackingIds
-
readActiveByIds
public List<P> readActiveByIds(Iterable<String> offerIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all active offers filtering where contextId inofferIds
.- Specified by:
readActiveByIds
in interfaceOfferService<P extends Offer>
- Parameters:
offerIds
- The context ids to filter oncontextInfo
- Context information around sandbox and multitenant state.- Returns:
- All active offers filtering where contextId in
offerIds
.
-
readByIds
public List<P> readByIds(Iterable<String> offerIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all offers filtering where contextId inofferIds
.- Specified by:
readByIds
in interfaceOfferService<P extends Offer>
- Parameters:
offerIds
- The context ids to filter oncontextInfo
- Context information around sandbox and multitenant state.- Returns:
- All active offers filtering where contextId in
offerIds
.
-
readVoucherOffersIn
public Stream<P> readVoucherOffersIn(Iterable<UserTarget> userTargets, Iterable<String> offerIds, Iterable<String> trackingIds, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all voucher offers based on the provided user targets, codes, or tracking ids. Skips the active date narrowing to retrieve offers that may have been validly applied in the past.- Specified by:
readVoucherOffersIn
in interfaceOfferService<P extends Offer>
- Parameters:
userTargets
- users the returnedOffer
(s) should targetofferIds
- offer ids the returnedOffer
(s) are associated with.trackingIds
- tracking ids the returnedOffer
(s) are associated with.contextInfo
- Context information around sandbox and multitenant state.- Returns:
- all voucher offers based on the provided user targets, codes, or tracking ids
-
readAllCustomerOffersIn
public Stream<P> readAllCustomerOffersIn(Iterable<UserTarget> userTargets, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all active offers whereOffer.userTargets
intersects with the providedUserTarget
s, or the offer has noUserTarget
s- Specified by:
readAllCustomerOffersIn
in interfaceOfferService<P extends Offer>
- Parameters:
userTargets
- users the returnedOffer
(s) should targetcontextInfo
- Context information around sandbox and multitenant state.- Returns:
- the offers matching the given criteria
-
readAllByName
public org.springframework.data.domain.Page<P> readAllByName(@Nullable String name, cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
readAllByName
in interfaceOfferService<P extends Offer>
-
readAllActiveByCodesIn
public List<P> readAllActiveByCodesIn(Iterable<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Reads all active offers whereOffer.getOfferCodes()
intersects with the provided codes.- Specified by:
readAllActiveByCodesIn
in interfaceOfferService<P extends Offer>
- Parameters:
codes
- codes the returnedOffer
(s) are associated with.contextInfo
- Context information around sandbox and multitenant state.- Returns:
- all active
Offer
s associated to the provided codes.
-
readAllByContextIdInOrExternalIdIn
public List<P> readAllByContextIdInOrExternalIdIn(Iterable<String> contextIds, Iterable<String> externalIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
readAllByContextIdInOrExternalIdIn
in interfaceOfferService<P extends Offer>
-
existsById
public boolean existsById(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Returns whether the offer with the given id exists in the data store- Specified by:
existsById
in interfaceOfferService<P extends Offer>
- Parameters:
id
- the id of the offer to findcontextInfo
- context information surrounding sandboxing and multi tenant state- Returns:
- whether the offer with the given id exists in the data store
-
existsByIdAndActive
public boolean existsByIdAndActive(String id, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferService
Returns whether the offer with the given id exists and is active in the data store.- Specified by:
existsByIdAndActive
in interfaceOfferService<P extends Offer>
- Parameters:
id
- the id of the offer to findcontextInfo
- context information surrounding sandboxing and multi tenant state- Returns:
- whether the offer with the given id exists and is active in the data store
-
getRepositoryDomain
- Specified by:
getRepositoryDomain
in interfaceOfferService<P extends Offer>
-
convertFromDomain
-
readByTrackingIds
public List<P> readByTrackingIds(Iterable<String> trackingIds, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Reads all active offers having one or more matches to the requested tracking ids. This is a specialized call in the flow of#readAutomaticAndCodeAndCustomerOffersIn(Iterable, Iterable, Iterable, EnhancedOrder, ContextInfo)
that fulfills utilizing cache. From that same method, if cache is disabled, this method will not be called and a more optimized, single query is emitted to cover all the offer relationship filters.- Specified by:
readByTrackingIds
in interfaceOfferService<P extends Offer>
- Parameters:
trackingIds
- Tracking ids the returnedOffer
(s) are associated withcontextInfo
- Context information around sandbox and multitenant state- Returns:
- Active offers having one or more matches to the requested tracking ids
-
warmCache
Description copied from interface:OfferService
Call to launch an async process to warm the full offer cache, if enabled. This method may be safely called repeatedly. If it is determined the cache has not been warmed yet, a new thread will spawn to fully populate the cache. Otherwise, the status of the cache warm process will simply be returned. For callers interested in the status, this method may be called repeatedly until the statusFullCacheInitializationStatus.READY
is returned, indicating the cache is fully warm.- Specified by:
warmCache
in interfaceOfferService<P extends Offer>
- Returns:
- The status of the cache warm process.
-
processOfferByIdForCache
protected List<com.broadleafcommerce.data.tracking.core.Trackable> processOfferByIdForCache(List<String> notCached, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Retrieve offers by ids for the purpose of caching. Also, perform any additional processing on the found records, including adding associations to other caches.- Parameters:
notCached
- The offer ids that are considered cache misses and must be looked upcontextInfo
- Context information around sandbox and multitenant state- Returns:
- The repository instances of offers found matching
notCached
.
-
findPossibleInfosForCacheWarmup
protected List<com.broadleafcommerce.data.tracking.core.context.ContextInfo> findPossibleInfosForCacheWarmup() -
buildInfos
-
normalize
@Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo normalize(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
cacheAllOffers
protected void cacheAllOffers(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) If applicable, cache all active offer in the database into cache memory store for efficient retrieval.- Parameters:
contextInfo
- Context information around sandbox and multitenant state
-
readAutomaticOffers
-
createCodeResponse
protected com.broadleafcommerce.promotion.offer.client.web.context.discounts.CodeResponse createCodeResponse(OfferNotAppliedReasonEnum notUsedReason) -
getRepository
@NonNull protected OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> getRepository() -
getCacheProperties
-
setCacheProperties
-
getCampaignService
-
setCampaignService
-
getOfferFactory
protected com.broadleafcommerce.common.extension.TypeFactory getOfferFactory() -
setOfferFactory
@Autowired public void setOfferFactory(com.broadleafcommerce.common.extension.TypeFactory offerFactory) -
getMessageSource
protected org.springframework.context.MessageSource getMessageSource() -
setMessageSource
@Autowired public void setMessageSource(org.springframework.context.MessageSource messageSource) -
getApplicationRepository
protected com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication> getApplicationRepository() -
setApplicationRepository
@Autowired public void setApplicationRepository(com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication> applicationRepository)
-