Class DefaultOfferCodeService<P extends OfferCode>
java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
com.broadleafcommerce.promotion.offer.service.DefaultOfferCodeService<P>
- All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>
,com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService<P>
,OfferCodeService<P>
,EventListener
,org.springframework.context.ApplicationListener<PromotionCacheInvalidationEvent>
public class DefaultOfferCodeService<P extends OfferCode>
extends com.broadleafcommerce.data.tracking.core.service.BaseRsqlCrudEntityService<P>
implements OfferCodeService<P>, org.springframework.context.ApplicationListener<PromotionCacheInvalidationEvent>
- Author:
- Karan Jariwala (karan-j-blc)
-
Field Summary
-
Constructor Summary
ConstructorDescriptionDefaultOfferCodeService
(OfferCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable> offerCodeRepository, CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository, OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> offerRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory campaignFactory) -
Method Summary
Modifier and TypeMethodDescriptionbuildOfferCodeStringList
(List<P> offerCodeList) protected void
cacheAllOfferCodes
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) If applicable, cache all applicable offer codes in the database into cache memory store for efficient retrieval.protected boolean
campaignCodeIsValid
(@NonNull Map<String, Campaign> campaignMap, @NonNull OfferCode offerCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo info) protected Offer
convertOfferFromPersistentDomain
(com.broadleafcommerce.data.tracking.core.Trackable domain, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) create
(P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) createOfferCodeEntities
(CodeGenerator info, Set<String> currentCodeSet) filterOutOfferCodesWithInvalidCampaigns
(@NonNull List<P> offerCodes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Filters outOfferCodes
that are tied to an invalid campaign.findAllByGeneratorIdAndAssigned
(String codeGeneratorId, boolean isAssigned, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) findAllDuplicatesForCodesInCampaign
(@NonNull String campaignId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Finds all duplicatesOfferCodes
byCampaign.getId()
.org.springframework.data.domain.Page<P>
findByCampaignId
(String campaignId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) org.springframework.data.domain.Page<P>
findByOfferId
(String offerId, cz.jirutka.rsql.parser.ast.Node filters, org.springframework.data.domain.Pageable page, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) findDuplicateCodes
(String codeGeneratorId, List<P> offerCodeList, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) findExistingByCodesIncludeExpiredForCampaignId
(Set<String> codes, String campaignId, Instant endAfterDate, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Search all non-expired offer codes or expired but belonging to the specified campaignId.findExistingByCodesIncludingInactive
(List<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Search all non-expired offer codes or expired but belonging to the specified offerId.findOffersAndOfferCodesByCodes
(List<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected List<com.broadleafcommerce.data.tracking.core.context.ContextInfo>
Discover all ContextInfo instances to use when processing viawarmCache()
.protected com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication>
protected OfferCacheProperties
protected com.broadleafcommerce.common.extension.cache.CacheStateManager
protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected CampaignService<Campaign>
protected OfferCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable>
protected OfferService<Offer>
protected com.broadleafcommerce.common.extension.TypeFactory
void
init()
protected com.broadleafcommerce.data.tracking.core.context.ContextInfo
normalize
(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) void
persistCodesAndReturn
(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) int
persistCodesAndReturnNumber
(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
populateCodeGeneratorDetailsToCode
(CodeGenerator codeGenerator, P offerCode) readAllByCampaignId
(String campaignId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads the offer codes for the specified campaign id matching the given filters.readAllByCode
(String code, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all of theOfferCodes
bycode
.readAllByCodes
(Set<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all of theOfferCodes
bycodes
.readAllByCodesIncludingInactive
(Set<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Vehicle for populating the cache duringcacheAllOfferCodes(ContextInfo)
.readAllByOfferId
(String offerId, cz.jirutka.rsql.parser.ast.Node filters, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Reads the offer codes for the specified offer id matching the given filters.protected org.springframework.validation.Errors
rejectDuplicateCode
(P duplicate) protected void
removeDuplicatesFromList
(List<P> offerCodeList, List<P> duplicateOfferCodes) Iterate through the codes we are about to save.replace
(@NonNull String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) List<com.broadleafcommerce.data.tracking.core.Trackable>
saveAll
(@NonNull List<P> businessInstances, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected void
saveAllNonDuplicates
(String codeGeneratorId, List<P> offerCodeList, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) 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
setCacheStateManager
(com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) void
setCampaignService
(CampaignService<Campaign> campaignService) void
setOfferService
(OfferService<Offer> offerService) update
(@NonNull String id, P businessInstance, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Call to launch an async process to warm the full code 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, createAll, createAllAllowingPartialSuccess, delete, getHelper, getRepository, getSortPositionStrategy, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, setSortPositionStrategy, 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
createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSort
Methods inherited from interface com.broadleafcommerce.promotion.offer.service.OfferCodeService
findAllUnassignedByGeneratorId, readByContextIdAndActive
Methods inherited from interface com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityService
readAll, readAll, readAll, readAll
-
Field Details
-
CACHE_BY_CODES
- See Also:
-
-
Constructor Details
-
DefaultOfferCodeService
public DefaultOfferCodeService(OfferCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable> offerCodeRepository, CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository, OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> offerRepository, com.broadleafcommerce.data.tracking.core.service.RsqlCrudEntityHelper helper, com.broadleafcommerce.common.extension.TypeFactory campaignFactory)
-
-
Method Details
-
init
@PostConstruct public void init() -
onApplicationEvent
-
findOffersAndOfferCodesByCodes
@NonNull public Map<P,List<Offer>> findOffersAndOfferCodesByCodes(@NonNull List<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findOffersAndOfferCodesByCodes
in interfaceOfferCodeService<P extends OfferCode>
-
findByCampaignId
@NonNull public org.springframework.data.domain.Page<P> findByCampaignId(@NonNull String campaignId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findByCampaignId
in interfaceOfferCodeService<P extends OfferCode>
-
findByOfferId
@NonNull public org.springframework.data.domain.Page<P> findByOfferId(@NonNull String offerId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable org.springframework.data.domain.Pageable page, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
findByOfferId
in interfaceOfferCodeService<P extends OfferCode>
-
readAllByCode
@NonNull public List<P> readAllByCode(@NonNull String code, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCodeService
Finds all of theOfferCodes
bycode
.- Specified by:
readAllByCode
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
code
- Code to matchcontextInfo
- Additional sandbox and multitenant state data- Returns:
- all of the
OfferCodes
bycode
-
readAllByCodes
@NonNull public List<P> readAllByCodes(@NonNull Set<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCodeService
Finds all of theOfferCodes
bycodes
.- Specified by:
readAllByCodes
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
codes
- Codes to matchcontextInfo
- Additional sandbox and multitenant state data- Returns:
- all of the
OfferCodes
bycode
-
create
-
update
-
replace
-
saveAll
public List<com.broadleafcommerce.data.tracking.core.Trackable> saveAll(@NonNull @NonNull List<P> businessInstances, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) - Specified by:
saveAll
in interfaceOfferCodeService<P extends OfferCode>
-
persistCodesAndReturnNumber
public int persistCodesAndReturnNumber(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
persistCodesAndReturnNumber
in interfaceOfferCodeService<P extends OfferCode>
-
persistCodesAndReturn
public List<P> persistCodesAndReturn(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) - Specified by:
persistCodesAndReturn
in interfaceOfferCodeService<P extends OfferCode>
-
readAllByCampaignId
public Stream<P> readAllByCampaignId(String campaignId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
Reads the offer codes for the specified campaign id matching the given filters.- Specified by:
readAllByCampaignId
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
campaignId
- the campaign idfilters
- additional filters to apply in the querycontext
- Request context information around sandbox and multitenant state- Returns:
- the offer codes for the specified campaign id matching the given filters
-
readAllByOfferId
public Stream<P> readAllByOfferId(String offerId, @Nullable cz.jirutka.rsql.parser.ast.Node filters, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
Reads the offer codes for the specified offer id matching the given filters.- Specified by:
readAllByOfferId
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
offerId
- the offer idfilters
- additional filters to apply in the querycontext
- Request context information around sandbox and multitenant state- Returns:
- the offer codes for the specified offer id matching the given filters
-
findExistingByCodesIncludeExpiredForCampaignId
public List<P> findExistingByCodesIncludeExpiredForCampaignId(Set<String> codes, String campaignId, Instant endAfterDate, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
Search all non-expired offer codes or expired but belonging to the specified campaignId. This is useful to validate that the offer codes can be added or updated. NOTE: This method is used during import ofOfferCode
and due to the varying limitations on how many entries can be in an "in" statement please make sure that the property "broadleaf.dataimport.processor.batch-size" does not exceed this limitation.- Specified by:
findExistingByCodesIncludeExpiredForCampaignId
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
codes
- The set of codes to matchcampaignId
- the campaign idendAfterDate
- Date after which code should be activecontext
- Request context information around sandbox and multitenant state- Returns:
- all
OfferCodes
byOfferCode.getCode()
that are also active or belonging to the specified campaignId - See Also:
-
com.broadleafcommerce.promotion.offer.dataimport.CampaignCodeImportBatchHandler
-
findExistingByCodesIncludingInactive
public List<P> findExistingByCodesIncludingInactive(List<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
Search all non-expired offer codes or expired but belonging to the specified offerId. This is useful to validate that the offer codes can be added or updated. NOTE: This method is used during import ofOfferCode
and due to the varying limitations on how many entries can be in an "in" statement please make sure that the property "broadleaf.dataimport.processor.batch-size" does not exceed this limitation.- Specified by:
findExistingByCodesIncludingInactive
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
codes
- The set of codes to matchcontext
- Request context information around sandbox and multitenant state- Returns:
- all
OfferCodes
byOfferCode.getCode()
that are also active or belonging to the specified offerId - See Also:
-
findAllDuplicatesForCodesInCampaign
public List<P> findAllDuplicatesForCodesInCampaign(@NonNull @NonNull String campaignId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
Finds all duplicatesOfferCodes
byCampaign.getId()
. Typically, this will be used to check for duplicate campaign codes of campaign.- Specified by:
findAllDuplicatesForCodesInCampaign
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
campaignId
- the campaign idcontext
- Request context information around sandbox and multitenant state- Returns:
- all duplicates
OfferCodes
byCampaign.getId()
-
findAllByGeneratorIdAndAssigned
public List<P> findAllByGeneratorIdAndAssigned(String codeGeneratorId, boolean isAssigned, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferCodeService
- Specified by:
findAllByGeneratorIdAndAssigned
in interfaceOfferCodeService<P extends OfferCode>
- Parameters:
codeGeneratorId
- the id of the code generator that these codes were generated fromisAssigned
- whether the offer codes are assignedcontext
- Request context information around sandbox and multitenant state- Returns:
- all the unassigned
OfferCodes
byOfferCode.getGeneratorId()
-
warmCache
Description copied from interface:OfferCodeService
Call to launch an async process to warm the full code 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 interfaceOfferCodeService<P extends OfferCode>
- Returns:
- The status of the cache warm process.
-
rejectDuplicateCode
-
createOfferCodeEntities
-
populateCodeGeneratorDetailsToCode
-
saveAllNonDuplicates
-
findDuplicateCodes
-
buildOfferCodeStringList
-
removeDuplicatesFromList
Iterate through the codes we are about to save. If the code is in the duplicatOfferCodes list then remove it.- Parameters:
offerCodeList
-duplicateOfferCodes
-
-
convertOfferFromPersistentDomain
protected Offer convertOfferFromPersistentDomain(com.broadleafcommerce.data.tracking.core.Trackable domain, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
filterOutOfferCodesWithInvalidCampaigns
protected List<P> filterOutOfferCodesWithInvalidCampaigns(@NonNull @NonNull List<P> offerCodes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Filters outOfferCodes
that are tied to an invalid campaign.- Parameters:
offerCodes
- theOfferCodes
to check againstcontextInfo
- context information surrounding sandboxing and multitenant state- Returns:
- originally given list of
OfferCodes
if none are tied to a campaign, otherwise a filtered list ofOfferCodes
-
campaignCodeIsValid
-
readAllByCodesIncludingInactive
protected List<P> readAllByCodesIncludingInactive(@NonNull Set<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Vehicle for populating the cache duringcacheAllOfferCodes(ContextInfo)
. This allows for possible retrieval of inactive codes as well.- Parameters:
codes
- The codes to cachecontextInfo
- Context information around sandbox and multitenant state- Returns:
- The retrieved codes
-
findPossibleInfosForCacheWarmup
protected List<com.broadleafcommerce.data.tracking.core.context.ContextInfo> findPossibleInfosForCacheWarmup()Discover all ContextInfo instances to use when processing viawarmCache()
.- Returns:
- The discovered ContextInfo cases
-
cacheAllOfferCodes
protected void cacheAllOfferCodes(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) If applicable, cache all applicable offer codes in the database into cache memory store for efficient retrieval. SeeFullCacheType
,OfferCacheProperties.getPriorCodeActiveBufferRange()
, andOfferCacheProperties.getFutureCodeActiveBufferRange()
for more information on configuring what codes are allowed into this cache.- Parameters:
contextInfo
- Context information around sandbox and multitenant state
-
normalize
@Nullable protected com.broadleafcommerce.data.tracking.core.context.ContextInfo normalize(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
getOfferCodeRepository
@NonNull protected OfferCodeRepository<com.broadleafcommerce.data.tracking.core.Trackable> getOfferCodeRepository() -
getCampaignRepository
@NonNull protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCampaignRepository() -
getOfferRepository
@NonNull protected OfferRepository<com.broadleafcommerce.data.tracking.core.Trackable> getOfferRepository() -
getTypeFactory
@NonNull protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getCacheStateManager
@Nullable protected com.broadleafcommerce.common.extension.cache.CacheStateManager getCacheStateManager() -
setCacheStateManager
@Autowired(required=false) public void setCacheStateManager(com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) -
getCacheProperties
-
setCacheProperties
-
getOfferService
-
setOfferService
-
getCampaignService
-
setCampaignService
-
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)
-