Class DefaultOfferAndOfferCodeUsabilityService
java.lang.Object
com.broadleafcommerce.promotion.offer.service.DefaultOfferAndOfferCodeUsabilityService
- All Implemented Interfaces:
OfferAndOfferCodeUsabilityService
public class DefaultOfferAndOfferCodeUsabilityService
extends Object
implements OfferAndOfferCodeUsabilityService
- Author:
- Chad Harchar (charchar)
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CampaignService<Campaign>
protected final OfferAuditDetailService<OfferAuditDetail>
protected final OfferCodeService<OfferCode>
protected final OfferService<Offer>
protected final OfferSummaryService<OfferAuditSummary>
protected final SharedCodeSummaryService<SharedCodeAuditSummary>
protected final com.broadleafcommerce.common.extension.TypeFactory
-
Constructor Summary
ConstructorDescriptionDefaultOfferAndOfferCodeUsabilityService
(OfferCodeService<OfferCode> offerCodeService, OfferService<Offer> offerService, CampaignService<Campaign> campaignService, SharedCodeSummaryService<SharedCodeAuditSummary> sharedCodeSummaryService, OfferSummaryService<OfferAuditSummary> offerSummaryService, OfferAuditDetailService<OfferAuditDetail> offerAuditDetailService, com.broadleafcommerce.common.extension.TypeFactory typeFactory) -
Method Summary
Modifier and TypeMethodDescriptionprotected com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo
buildCodeUsabilityInfo
(List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, String code) protected void
buildOfferCodeUsage
(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo info, OfferCode offerCode, int usagesRemaining, int usagesRemainingPerUser, boolean usable) protected com.broadleafcommerce.promotion.offer.client.web.context.OfferUsabilityInfo
buildOfferUsabilityInfo
(Offer offer) protected void
buildUsabilityInfoForCode
(OffersAndOfferCodesUsabilityInfo usabilityInfo, OfferCode code, boolean canUse) protected void
checkOfferCustomerUsageUsability
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends OfferCode> offerCodesForCode, List<OfferAuditDetail> offerAuditDetails, Instant endDate, Offer offer) protected void
checkOfferMaxUsageUsability
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends OfferCode> offerCodesForCode, List<OfferAuditSummary> offerAuditSummaries, Offer offer) protected boolean
checkTotalDiscountedBalance
(Offer offer, javax.money.MonetaryAmount totalAlreadyDiscounted) protected void
determineCodeUsability
(OffersAndOfferCodesUsabilityInfo usabilityInfos) protected String
determineCodeUsabilityType
(List<? extends Offer> offers, OfferCode offerCode) protected int
determineMaxUsesPerCustomer
(List<OfferAuditDetail> offerAuditDetails, Instant endDate, Offer offer) protected String
getCustomerTargetValue
(com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext) Retrieves the value to set for theUserTarget.getTargetValue()
on the audit detail(s).getOfferAndOfferCodeUsabilityInfo
(List<String> codes, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Checks the providedcodes
against the offer codes and offers to determine whether the code is usable.getOfferAndOfferCodeUsabilityInfo
(List<String> codes, List<? extends Offer> offers, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Checks the providedcodes
against the offer codes and provided offers to determine whether the code is usable.protected OffersAndOfferCodesUsabilityInfo
getOfferAndOfferCodeUsabilityInfo
(List<String> codes, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) protected OfferCacheProperties
protected OfferMessagingProperties
protected OfferMaxUseStatusManager
protected boolean
hasAnyUsagesAvailableForUser
(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo) void
init()
protected OffersAndOfferCodesUsabilityInfo
initilizeOfferAndOfferCodeUsabilityInfos
(List<String> codes, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected boolean
isAnonymousUser
(com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext) protected void
markCodesUnavailableToUser
(@NonNull OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends OfferCode> codesWithMaxUsagesPerUser) protected void
markOfferUnavailableToUser
(@NonNull OffersAndOfferCodesUsabilityInfo usabilityInfo, @NonNull List<? extends Offer> maxUsagesPerUserOffers, List<? extends OfferCode> offerCodesForCode) protected String
prioritizeCodeUsabilityType
(String result, String codeUsabilityType) If any OfferCode is usable for the provided code string, prioritize the "USABLE" type.protected AuditVerificationFlags
resolveAuditVerificationFlags
(com.broadleafcommerce.data.tracking.core.context.ContextInfo ctx) void
setOfferCacheProperties
(OfferCacheProperties offerCacheProperties) void
setOfferMessagingProperties
(OfferMessagingProperties offerMessagingProperties) void
setStatusManager
(OfferMaxUseStatusManager statusManager) protected void
updateOfferCodeUsage
(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo, OfferCode offerCode, int usagesRemaining, boolean usable) protected void
updateOfferCodeUsagePerUser
(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo, OfferCode offerCode, int usesRemainingPerUser, boolean usable) protected void
verifyUsabilityForCodesEmailRegex
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
verifyUsabilityForCustomerUseOfferCodes
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
verifyUsabilityForCustomerUseOffers
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
verifyUsabilityForMaxUseOffers
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
verifyUsabilityForMultiUseOfferCodes
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) protected void
verifyUsabilityForOfferCodesHook
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hookpoint to use to add additional, custom verification logic for offer code usability besides what is provided out of box.protected void
verifyUsabilityForOffersHook
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hookpoint to use to add additional, custom verification logic for offer usability besides what is provided out of box.protected void
verifyUsabilityForSingleUseOfferCodes
(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
-
Field Details
-
offerCodeService
-
offerService
-
campaignService
-
offerSummaryService
-
offerAuditDetailService
-
typeFactory
protected final com.broadleafcommerce.common.extension.TypeFactory typeFactory
-
-
Constructor Details
-
Method Details
-
init
@PostConstruct public void init() -
getOfferAndOfferCodeUsabilityInfo
@NonNull public OffersAndOfferCodesUsabilityInfo getOfferAndOfferCodeUsabilityInfo(@NonNull List<String> codes, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferAndOfferCodeUsabilityService
Checks the providedcodes
against the offer codes and offers to determine whether the code is usable.- Specified by:
getOfferAndOfferCodeUsabilityInfo
in interfaceOfferAndOfferCodeUsabilityService
- Parameters:
codes
- the codes for which to check usabilitycustomerContext
- context information for the customercontext
- context information around sandbox and multitenant state- Returns:
- a
OffersAndOfferCodesUsabilityInfo
which contains information to determine whether or not the codes can be used
-
getOfferAndOfferCodeUsabilityInfo
@NonNull public OffersAndOfferCodesUsabilityInfo getOfferAndOfferCodeUsabilityInfo(@NonNull List<String> codes, @NonNull List<? extends Offer> offers, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Description copied from interface:OfferAndOfferCodeUsabilityService
Checks the providedcodes
against the offer codes and provided offers to determine whether the code is usable.- Specified by:
getOfferAndOfferCodeUsabilityInfo
in interfaceOfferAndOfferCodeUsabilityService
- Parameters:
codes
- the code for which to check usabilityoffers
- the list of offers to check usabilitycustomerContext
- context information for the customercontext
- context information around sandbox and multitenant state- Returns:
- a
OffersAndOfferCodesUsabilityInfo
which contains information to determine whether or not the offers and codes can be used
-
getOfferAndOfferCodeUsabilityInfo
@NonNull protected OffersAndOfferCodesUsabilityInfo getOfferAndOfferCodeUsabilityInfo(@NonNull List<String> codes, @NonNull List<? extends Offer> offers, @NonNull List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) -
verifyUsabilityForOfferCodesHook
protected void verifyUsabilityForOfferCodesHook(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hookpoint to use to add additional, custom verification logic for offer code usability besides what is provided out of box. This is run beforedetermineCodeUsability(com.broadleafcommerce.promotion.offer.domain.OffersAndOfferCodesUsabilityInfo)
but after default verification methods.- Parameters:
usabilityInfo
- Usability info compiled to this point.offers
- Offers pre-filtered by max uses.offerCodes
- Offer Codes pre-filtered by max uses.customerContext
- The customer context including username.contextInfo
- Additional multitenant and sandbox info.
-
verifyUsabilityForOffersHook
protected void verifyUsabilityForOffersHook(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Hookpoint to use to add additional, custom verification logic for offer usability besides what is provided out of box. This is run beforedetermineCodeUsability(com.broadleafcommerce.promotion.offer.domain.OffersAndOfferCodesUsabilityInfo)
but after default verification methods.- Parameters:
usabilityInfo
- Usability info compiled to this point.offers
- Offers pre-filtered by max uses.offerCodes
- Offer Codes pre-filtered by max uses.customerContext
- The customer context including username.contextInfo
- Additional multitenant and sandbox info.
-
resolveAuditVerificationFlags
protected AuditVerificationFlags resolveAuditVerificationFlags(@Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo ctx) -
initilizeOfferAndOfferCodeUsabilityInfos
-
buildCodeUsabilityInfo
-
prioritizeCodeUsabilityType
If any OfferCode is usable for the provided code string, prioritize the "USABLE" type.By default, the other
CodeUsabilityTypes
are not prioritized against each other.- Parameters:
result
- theCodeUsabilityType
returned up to this pointcodeUsabilityType
- the currentCodeUsabilityType
to check against- Returns:
- the
CodeUsabilityType
for the string code
-
buildOfferUsabilityInfo
protected com.broadleafcommerce.promotion.offer.client.web.context.OfferUsabilityInfo buildOfferUsabilityInfo(Offer offer) -
determineCodeUsabilityType
-
verifyUsabilityForMaxUseOffers
protected void verifyUsabilityForMaxUseOffers(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
checkOfferMaxUsageUsability
protected void checkOfferMaxUsageUsability(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends OfferCode> offerCodesForCode, List<OfferAuditSummary> offerAuditSummaries, Offer offer) -
checkTotalDiscountedBalance
protected boolean checkTotalDiscountedBalance(Offer offer, javax.money.MonetaryAmount totalAlreadyDiscounted) -
verifyUsabilityForSingleUseOfferCodes
protected void verifyUsabilityForSingleUseOfferCodes(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
verifyUsabilityForMultiUseOfferCodes
protected void verifyUsabilityForMultiUseOfferCodes(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
verifyUsabilityForCustomerUseOfferCodes
protected void verifyUsabilityForCustomerUseOfferCodes(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
hasAnyUsagesAvailableForUser
protected boolean hasAnyUsagesAvailableForUser(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo) -
verifyUsabilityForCustomerUseOffers
protected void verifyUsabilityForCustomerUseOffers(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends Offer> offers, List<? extends OfferCode> offerCodesForCode, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
isAnonymousUser
protected boolean isAnonymousUser(@Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext) -
getCustomerTargetValue
protected String getCustomerTargetValue(com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext) Retrieves the value to set for theUserTarget.getTargetValue()
on the audit detail(s). This defaults to the user's email.- Parameters:
customerContext
- TheCustomerContext
associated with the API request.- Returns:
- the value to set for the
UserTarget.getTargetValue()
on the audit detail(s).
-
checkOfferCustomerUsageUsability
protected void checkOfferCustomerUsageUsability(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<? extends OfferCode> offerCodesForCode, List<OfferAuditDetail> offerAuditDetails, Instant endDate, Offer offer) -
determineMaxUsesPerCustomer
protected int determineMaxUsesPerCustomer(List<OfferAuditDetail> offerAuditDetails, Instant endDate, Offer offer) -
updateOfferCodeUsage
protected void updateOfferCodeUsage(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo, OfferCode offerCode, int usagesRemaining, boolean usable) -
updateOfferCodeUsagePerUser
protected void updateOfferCodeUsagePerUser(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo codeUsabilityInfo, OfferCode offerCode, int usesRemainingPerUser, boolean usable) -
buildOfferCodeUsage
protected void buildOfferCodeUsage(com.broadleafcommerce.promotion.offer.client.web.context.CodeUsabilityInfo info, OfferCode offerCode, int usagesRemaining, int usagesRemainingPerUser, boolean usable) -
determineCodeUsability
-
verifyUsabilityForCodesEmailRegex
protected void verifyUsabilityForCodesEmailRegex(OffersAndOfferCodesUsabilityInfo usabilityInfo, List<Offer> offers, List<? extends OfferCode> offerCodes, @Nullable com.broadleafcommerce.promotion.offer.client.web.context.CustomerContext customerContext, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) -
buildUsabilityInfoForCode
protected void buildUsabilityInfoForCode(OffersAndOfferCodesUsabilityInfo usabilityInfo, OfferCode code, boolean canUse) -
getOfferCacheProperties
-
setOfferCacheProperties
@Autowired(required=false) public void setOfferCacheProperties(OfferCacheProperties offerCacheProperties) -
getPatternCache
-
getStatusManager
-
setStatusManager
-
getOfferMessagingProperties
-
setOfferMessagingProperties
@Autowired public void setOfferMessagingProperties(OfferMessagingProperties offerMessagingProperties)
-