Interface CodeGenerationService
- All Known Implementing Classes:
DefaultCodeGenerationService
CodeGenerator, such as validation and code generation.- Author:
- Chad Harchar (charchar)
-
Method Summary
Modifier and TypeMethodDescriptiongenerateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theCodeGenerationResultcontaining generated and/or existingOfferCodesfor voucher offers based on the givenVoucherCodeGenerationRequest.generateSingleUseCode(String codeFormat, String forOfferId, String forCampaignId, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theSingleCodeGenerationResultcontaining the generated code and a success indicator if the system was able to generate the code.markInProgressAndGenerateAndGetCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Updates theCodeGeneratorto have a status ofCodeGenerationStatusType.IN_PROCESS, then performs the code generation.default voidmarkInProgressAndGenerateCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Updates theCodeGeneratorto have a status ofCodeGenerationStatusType.IN_PROCESS, then performs the code generation.
-
Method Details
-
markInProgressAndGenerateCodes
default void markInProgressAndGenerateCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Updates theCodeGeneratorto have a status ofCodeGenerationStatusType.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 formatcontextRequest- The context of the request with which to generate codes
-
markInProgressAndGenerateAndGetCodes
CodeGenerationResult markInProgressAndGenerateAndGetCodes(CodeGenerator info, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Updates theCodeGeneratorto have a status ofCodeGenerationStatusType.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 formatcontextRequest- The context of the request with which to generate codes- Returns:
- the
CodeGenerationResultcontaining the generatedOfferCodesand error message based on the givenCodeGenerator
-
generateCodesForVouchers
CodeGenerationResult generateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theCodeGenerationResultcontaining generated and/or existingOfferCodesfor voucher offers based on the givenVoucherCodeGenerationRequest.This will use the existing
CodeGeneratorfor the voucher campaign if exists, otherwise it will create a new one.This method will generate the
OfferCodesand waits for its completion in the same request, therefore it's meant for small batch of code generation only.- Parameters:
voucherCodeGenerationReq- theVoucherCodeGenerationRequestto generate the voucherOfferCodeswithcontextInfo- The context of the request with which to generate codes- Returns:
- the
CodeGenerationResultcontaining generated and/or existingOfferCodesfor voucher offers based on the givenVoucherCodeGenerationRequest.
-
generateSingleUseCode
SingleCodeGenerationResult generateSingleUseCode(String codeFormat, @Nullable String forOfferId, @Nullable String forCampaignId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theSingleCodeGenerationResultcontaining 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()orCodeGenerator.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 generateforOfferId- Optionally associate this code with anOfferforCampaignId- Optionally associate this code with aCampaigncontextInfo- The context of the request with which to generate codes- Returns:
- the
CodeGenerationResultcontaining generated codes and success / failure status - See Also:
-
for information on codeFormat strings
-