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
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultOfferCodeService(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 voidcacheAllOfferCodes(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 booleancampaignCodeIsValid(@NonNull Map<String, Campaign> campaignMap, @NonNull OfferCode offerCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo info) protected OfferconvertOfferFromPersistentDomain(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 outOfferCodesthat 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 duplicatesOfferCodesbyCampaign.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 OfferCachePropertiesprotected com.broadleafcommerce.common.extension.cache.CacheStateManagerprotected 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.TypeFactoryvoidinit()protected com.broadleafcommerce.data.tracking.core.context.ContextInfonormalize(com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidpersistCodesAndReturn(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) intpersistCodesAndReturnNumber(CodeGenerator info, Set<String> currentCodeSet, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected voidpopulateCodeGeneratorDetailsToCode(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 theOfferCodesbycode.readAllByCodes(Set<String> codes, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Finds all of theOfferCodesbycodes.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.ErrorsrejectDuplicateCode(P duplicate) protected voidremoveDuplicatesFromList(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 voidsaveAllNonDuplicates(String codeGeneratorId, List<P> offerCodeList, Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) voidsetApplicationRepository(com.broadleafcommerce.data.tracking.jpa.tenant.repository.JpaCommonApplicationRepository<com.broadleafcommerce.data.tracking.jpa.tenant.domain.application.JpaApplication> applicationRepository) voidsetCacheProperties(OfferCacheProperties cacheProperties) voidsetCacheStateManager(com.broadleafcommerce.common.extension.cache.CacheStateManager cacheStateManager) voidsetCampaignService(CampaignService<Campaign> campaignService) voidsetOfferService(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, readAllMethods 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, updateSortMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService
createAll, createAllAllowingPartialSuccess, delete, readAll, readAll, readAll, readAllByContextId, readByContextId, replaceAll, replaceAllAllowingPartialSuccess, updateAll, updateAllAllowingPartialSuccess, updateSortMethods inherited from interface com.broadleafcommerce.promotion.offer.service.OfferCodeService
findAllUnassignedByGeneratorId, readByContextIdAndActiveMethods 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:
findOffersAndOfferCodesByCodesin 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:
findByCampaignIdin 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:
findByOfferIdin 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:OfferCodeServiceFinds all of theOfferCodesbycode.- Specified by:
readAllByCodein interfaceOfferCodeService<P extends OfferCode>- Parameters:
code- Code to matchcontextInfo- Additional sandbox and multitenant state data- Returns:
- all of the
OfferCodesbycode
-
readAllByCodes
@NonNull public List<P> readAllByCodes(@NonNull Set<String> codes, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:OfferCodeServiceFinds all of theOfferCodesbycodes.- Specified by:
readAllByCodesin interfaceOfferCodeService<P extends OfferCode>- Parameters:
codes- Codes to matchcontextInfo- Additional sandbox and multitenant state data- Returns:
- all of the
OfferCodesbycode
-
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:
saveAllin 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:
persistCodesAndReturnNumberin 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:
persistCodesAndReturnin 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:OfferCodeServiceReads the offer codes for the specified campaign id matching the given filters.- Specified by:
readAllByCampaignIdin 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:OfferCodeServiceReads the offer codes for the specified offer id matching the given filters.- Specified by:
readAllByOfferIdin 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:OfferCodeServiceSearch 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 ofOfferCodeand 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:
findExistingByCodesIncludeExpiredForCampaignIdin 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
OfferCodesbyOfferCode.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:OfferCodeServiceSearch 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 ofOfferCodeand 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:
findExistingByCodesIncludingInactivein interfaceOfferCodeService<P extends OfferCode>- Parameters:
codes- The set of codes to matchcontext- Request context information around sandbox and multitenant state- Returns:
- all
OfferCodesbyOfferCode.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:OfferCodeServiceFinds all duplicatesOfferCodesbyCampaign.getId(). Typically, this will be used to check for duplicate campaign codes of campaign.- Specified by:
findAllDuplicatesForCodesInCampaignin interfaceOfferCodeService<P extends OfferCode>- Parameters:
campaignId- the campaign idcontext- Request context information around sandbox and multitenant state- Returns:
- all duplicates
OfferCodesbyCampaign.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:
findAllByGeneratorIdAndAssignedin 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
OfferCodesbyOfferCode.getGeneratorId()
-
warmCache
Description copied from interface:OfferCodeServiceCall 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.READYis returned, indicating the cache is fully warm.
This method should only be called prior to the service accepting traffic. It is most useful as part of a readiness probe, for example, as part of a kubernetes pod readiness check.- Specified by:
warmCachein 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 outOfferCodesthat are tied to an invalid campaign.- Parameters:
offerCodes- theOfferCodesto check againstcontextInfo- context information surrounding sandboxing and multitenant state- Returns:
- originally given list of
OfferCodesif 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)
-