Class VoucherCodeGenerationOrderCreatedListener
- java.lang.Object
-
- com.broadleafcommerce.orderoperation.service.messaging.ordercreated.VoucherCodeGenerationOrderCreatedListener
-
public class VoucherCodeGenerationOrderCreatedListener extends Object
An event listener that triggers when order is successfully created. Responsible for validatingOrder.getVouchers()
, generating voucher codes, and sending aVoucherGenerationCompletionEvent
message.- Author:
- Sunny Yu
-
-
Constructor Summary
Constructors Constructor Description VoucherCodeGenerationOrderCreatedListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, VoucherGenerationCompletionProducer voucherGenerationCompletionProducer, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OfferProvider offerProvider, CampaignProvider campaignProvider, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected CodeGenerator
buildCodeGeneratorRequest(String campaignId, int numberToGenerate, String emailRegex)
Builds aCodeGenerator
based on the givenCodeGenerator.getCampaignId()
,CodeGenerator.getNumberOfCodesToGenerate()
, andCodeGenerator.getEmailRegEx()
.protected String
buildEmailRegex(String email)
Builds an email regular expression forCodeGenerator.getEmailRegEx()
.protected VoucherCodeGenerationRequest
buildVoucherCodeGenerationRequest(CodeGenerator codeGenerator, String voucherCampaignId)
Builds aVoucherCodeGenerationRequest
based on the givenCodeGenerator
andVoucher.getVoucherCampaignId()
.protected void
generateAndSetVoucherCodes(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Generates and setsVoucher.getGeneratedCampaignCode()
usingCampaignProvider
for validVouchers
in whichVoucher.isValidationSuccessful()
istrue
.protected CampaignProvider
getCampaignProvider()
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService
getIdempotentMessageService()
protected OfferProvider
getOfferProvider()
protected OrderProvider<com.broadleafcommerce.order.client.domain.Order>
getOrderProvider()
protected com.broadleafcommerce.common.extension.TypeFactory
getTypeFactory()
protected VoucherGenerationCompletionProducer
getVoucherGenerationCompletionProducer()
protected void
handleCodeGenerationError(CodeGenerationResult result, String voucherCampaignId, List<com.broadleafcommerce.order.common.domain.Voucher> vouchersForCampaign)
Handles code generation error from the givenCodeGenerationResult
ifCodeGenerationResult.isSuccessful()
isfalse
.protected void
handleVoucherValidationFailures(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.promotion.offer.client.web.context.OfferAndOfferCodeUsageValidationResult result)
Handles voucher validation failures forOrder.getVouchers()
based on the givenOfferAndOfferCodeUsageValidationResult
.void
listen(org.springframework.messaging.Message<OrderCreatedEvent> message)
Event listener entry point.protected void
process(@NonNull OrderCreatedEvent event)
Processes the received message by validatingOrder.getVouchers()
, generating voucher codes, and then sending aVoucherGenerationCompletionEvent
message/protected void
processMessage(org.springframework.messaging.Message<OrderCreatedEvent> message)
Processes the givenMessage
.protected void
processVoucherCodeGenerationResult(com.broadleafcommerce.order.client.domain.Order order, CodeGenerationResult generationResult, String voucherCampaignId, List<com.broadleafcommerce.order.common.domain.Voucher> vouchersForCampaign)
protected void
sendVoucherCodeCreatedMessage(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends aVoucherGenerationCompletionEvent
message.protected boolean
shouldProcessEvent(OrderCreatedEvent event)
Determines whether or not the givenOrderCreatedEvent
should be processed.protected void
validateVouchers(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
ValidatesOrder.getVouchers()
usingOfferProvider
.
-
-
-
Constructor Detail
-
VoucherCodeGenerationOrderCreatedListener
public VoucherCodeGenerationOrderCreatedListener(com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService idempotentMessageService, VoucherGenerationCompletionProducer voucherGenerationCompletionProducer, com.broadleafcommerce.common.extension.TypeFactory typeFactory, OfferProvider offerProvider, CampaignProvider campaignProvider, OrderProvider<com.broadleafcommerce.order.client.domain.Order> orderProvider)
-
-
Method Detail
-
listen
@StreamListener("orderOperationsOrderCreatedInput") public void listen(org.springframework.messaging.Message<OrderCreatedEvent> message)
Event listener entry point. Checks if the message has already been received and, if not, begins processing it.- Parameters:
message
- the message payload event
-
shouldProcessEvent
protected boolean shouldProcessEvent(OrderCreatedEvent event)
Determines whether or not the givenOrderCreatedEvent
should be processed.- Parameters:
event
- theOrderCreatedEvent
to check against- Returns:
- true if the given
OrderCreatedEvent
should be processed, otherwise false
-
processMessage
protected void processMessage(org.springframework.messaging.Message<OrderCreatedEvent> message)
Processes the givenMessage
.- Parameters:
message
- theMessage
to process
-
process
protected void process(@NonNull @NonNull OrderCreatedEvent event)
Processes the received message by validatingOrder.getVouchers()
, generating voucher codes, and then sending aVoucherGenerationCompletionEvent
message/- Parameters:
event
- the message payload event
-
validateVouchers
protected void validateVouchers(com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
ValidatesOrder.getVouchers()
usingOfferProvider
.- Parameters:
order
- theOrder
that contains all theVouchers
contextInfo
- context information surrounding sandboxing and multitenant state
-
handleVoucherValidationFailures
protected void handleVoucherValidationFailures(com.broadleafcommerce.order.client.domain.Order order, com.broadleafcommerce.promotion.offer.client.web.context.OfferAndOfferCodeUsageValidationResult result)
Handles voucher validation failures forOrder.getVouchers()
based on the givenOfferAndOfferCodeUsageValidationResult
.- Parameters:
order
- theOrder
that contains all theVouchers
result
- theOfferAndOfferCodeUsageValidationResult
from the voucher validation
-
generateAndSetVoucherCodes
protected void generateAndSetVoucherCodes(com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Generates and setsVoucher.getGeneratedCampaignCode()
usingCampaignProvider
for validVouchers
in whichVoucher.isValidationSuccessful()
istrue
.- Parameters:
order
- theOrder
that contains theVouchers
contextInfo
- context information surrounding sandboxing and multitenant state
-
buildEmailRegex
protected String buildEmailRegex(String email)
Builds an email regular expression forCodeGenerator.getEmailRegEx()
.- Parameters:
email
- theOrder.getEmailAddress()
- Returns:
- an email regular expression for
CodeGenerator.getEmailRegEx()
-
buildVoucherCodeGenerationRequest
protected VoucherCodeGenerationRequest buildVoucherCodeGenerationRequest(CodeGenerator codeGenerator, String voucherCampaignId)
Builds aVoucherCodeGenerationRequest
based on the givenCodeGenerator
andVoucher.getVoucherCampaignId()
.- Parameters:
codeGenerator
- theCodeGenerator
to generate theCampaignCodes
off ofvoucherCampaignId
- theVoucher.getVoucherCampaignId()
- Returns:
- a
VoucherCodeGenerationRequest
based on the givenCodeGenerator
andVoucher.getVoucherCampaignId()
-
buildCodeGeneratorRequest
protected CodeGenerator buildCodeGeneratorRequest(String campaignId, int numberToGenerate, String emailRegex)
Builds aCodeGenerator
based on the givenCodeGenerator.getCampaignId()
,CodeGenerator.getNumberOfCodesToGenerate()
, andCodeGenerator.getEmailRegEx()
.- Parameters:
campaignId
- theCodeGenerator.getCampaignId()
numberToGenerate
- theCodeGenerator.getNumberOfCodesToGenerate()
emailRegex
- theCodeGenerator.getEmailRegEx()
.- Returns:
- a
CodeGenerator
based on the givenCodeGenerator.getCampaignId()
,CodeGenerator.getNumberOfCodesToGenerate()
, andCodeGenerator.getEmailRegEx()
-
processVoucherCodeGenerationResult
protected void processVoucherCodeGenerationResult(com.broadleafcommerce.order.client.domain.Order order, CodeGenerationResult generationResult, String voucherCampaignId, List<com.broadleafcommerce.order.common.domain.Voucher> vouchersForCampaign)
- Parameters:
order
- theOrder
that contains the givenVouchers
generationResult
- theCodeGenerationResult
to processvoucherCampaignId
- the id of the voucher campaign that the givenCodeGenerationResult
andVouchers
are associated withvouchersForCampaign
- theVouchers
that theCodeGenerationResult
was for and associated with the same campaign- Throws:
IllegalStateException
- if theCodeGenerationResult
is successful but generated voucher codes are not enough forOrder.getVouchers()
-
handleCodeGenerationError
protected void handleCodeGenerationError(CodeGenerationResult result, String voucherCampaignId, List<com.broadleafcommerce.order.common.domain.Voucher> vouchersForCampaign)
Handles code generation error from the givenCodeGenerationResult
ifCodeGenerationResult.isSuccessful()
isfalse
.- Parameters:
result
- theCodeGenerationResult
to handle forvoucherCampaignId
- the id of the voucher campaign that the givenCodeGenerationResult
andVouchers
are associated withvouchersForCampaign
- theVouchers
that theCodeGenerationResult
was for and associated with the same campaign
-
sendVoucherCodeCreatedMessage
protected void sendVoucherCodeCreatedMessage(com.broadleafcommerce.order.client.domain.Order order, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Sends aVoucherGenerationCompletionEvent
message.- Parameters:
order
- theOrder
that the vouchers were created forcontextInfo
- context information surrounding sandboxing and multitenant state
-
getIdempotentMessageService
protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
-
getVoucherGenerationCompletionProducer
protected VoucherGenerationCompletionProducer getVoucherGenerationCompletionProducer()
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
-
getOfferProvider
protected OfferProvider getOfferProvider()
-
getCampaignProvider
protected CampaignProvider getCampaignProvider()
-
getOrderProvider
protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()
-
-