Class VoucherCodeGenerationOrderCreatedListener


  • public class VoucherCodeGenerationOrderCreatedListener
    extends Object
    An event listener that triggers when order is successfully created. Responsible for validating Order.getVouchers(), generating voucher codes, and sending a VoucherGenerationCompletionEvent message.
    Author:
    Sunny Yu
    • 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
      • processMessage

        protected void processMessage​(org.springframework.messaging.Message<OrderCreatedEvent> message)
        Processes the given Message.
        Parameters:
        message - the Message to process
      • process

        protected void process​(@NonNull
                               @NonNull OrderCreatedEvent event)
        Processes the received message by validating Order.getVouchers(), generating voucher codes, and then sending a VoucherGenerationCompletionEvent 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)
        Validates Order.getVouchers() using OfferProvider.
        Parameters:
        order - the Order that contains all the Vouchers
        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 for Order.getVouchers() based on the given OfferAndOfferCodeUsageValidationResult.
        Parameters:
        order - the Order that contains all the Vouchers
        result - the OfferAndOfferCodeUsageValidationResult 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 sets Voucher.getGeneratedCampaignCode() using CampaignProvider for valid Vouchers in which Voucher.isValidationSuccessful() is true.
        Parameters:
        order - the Order that contains the Vouchers
        contextInfo - context information surrounding sandboxing and multitenant state
      • processVoucherCodeGenerationResult

        protected void processVoucherCodeGenerationResult​(com.broadleafcommerce.order.client.domain.Order order,
                                                          CodeGenerationResult generationResult,
                                                          String voucherCampaignId,
                                                          List<com.broadleafcommerce.order.common.domain.Voucher> vouchersForCampaign)
        Processes the given CodeGenerationResult for the given Order and vouchers for the same campaign
        Parameters:
        order - the Order that contains the given Vouchers
        generationResult - the CodeGenerationResult to process
        voucherCampaignId - the id of the voucher campaign that the given CodeGenerationResult and Vouchers are associated with
        vouchersForCampaign - the Vouchers that the CodeGenerationResult was for and associated with the same campaign
        Throws:
        IllegalStateException - if the CodeGenerationResult is successful but generated voucher codes are not enough for Order.getVouchers()
      • sendVoucherCodeCreatedMessage

        protected void sendVoucherCodeCreatedMessage​(com.broadleafcommerce.order.client.domain.Order order,
                                                     @Nullable
                                                     com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
        Parameters:
        order - the Order that the vouchers were created for
        contextInfo - context information surrounding sandboxing and multitenant state
      • getIdempotentMessageService

        protected com.broadleafcommerce.common.messaging.service.IdempotentMessageConsumptionService getIdempotentMessageService()
      • getTypeFactory

        protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory()
      • getOrderProvider

        protected OrderProvider<com.broadleafcommerce.order.client.domain.Order> getOrderProvider()