Interface CodeGenerationService

All Known Implementing Classes:
DefaultCodeGenerationService

public interface CodeGenerationService
Performs operations on a CodeGenerator, such as validation and code generation.
Author:
Chad Harchar (charchar)
  • Method Details

    • markInProgressAndGenerateCodes

      default void markInProgressAndGenerateCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest)
      Updates the CodeGenerator to have a status of CodeGenerationStatusType.IN_PROCESS, then performs the code generation.
      Parameters:
      info - The CodeGenerator that holds the information needed in order to generate the expected number of codes with the expected format
      contextRequest - The context of the request with which to generate codes
    • markInProgressAndGenerateAndGetCodes

      CodeGenerationResult markInProgressAndGenerateAndGetCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest)
      Updates the CodeGenerator to have a status of CodeGenerationStatusType.IN_PROCESS, then performs the code generation.
      Parameters:
      info - The CodeGenerator that holds the information needed in order to generate the expected number of codes with the expected format
      contextRequest - The context of the request with which to generate codes
      Returns:
      the CodeGenerationResult containing the generated OfferCodes and error message based on the given CodeGenerator
    • generateCodesForVouchers

      CodeGenerationResult generateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Returns the CodeGenerationResult containing generated and/or existing OfferCodes for voucher offers based on the given VoucherCodeGenerationRequest.

      This will use the existing CodeGenerator for the voucher campaign if exists, otherwise it will create a new one.

      This method will generate the OfferCodes and waits for its completion in the same request, therefore it's meant for small batch of code generation only.

      Parameters:
      voucherCodeGenerationReq - the VoucherCodeGenerationRequest to generate the voucher OfferCodes with
      contextInfo - The context of the request with which to generate codes
      Returns:
      the CodeGenerationResult containing generated and/or existing OfferCodes for voucher offers based on the given VoucherCodeGenerationRequest.
    • generateSingleUseCode

      SingleCodeGenerationResult generateSingleUseCode(String codeFormat, @Nullable String forOfferId, @Nullable String forCampaignId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
      Returns the SingleCodeGenerationResult containing the generated code and a success indicator if the system was able to generate the code. A failure indicates that the codeFormat was insufficient to generate a random code as a collision with already persisted codes occurred even after two tries.

      This method is designed to produce a single random code and to persist that code to a campaign or offer. It can also be used to generate a unique code for other purposes (like a unique Offer.getSharedCode()

      This method will persist the offer code if either the CodeGenerator.getCampaignId() or CodeGenerator.getOfferId() parameter are passed in. Otherwise, it will just return the code after performing a uniqueness check. If both are passed in, the campaignId is ignored.

      Parameters:
      codeFormat - the String representing the code format to generate
      forOfferId - Optionally associate this code with an Offer
      forCampaignId - Optionally associate this code with a Campaign
      contextInfo - The context of the request with which to generate codes
      Returns:
      the CodeGenerationResult containing generated codes and success / failure status
      See Also:
      • for information on codeFormat strings