Class DefaultCodeGenerationService
- All Implemented Interfaces:
CodeGenerationService
- Author:
- Chad Harchar (charchar)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final CodeFormatAvailableCharHelperprotected final com.broadleafcommerce.common.extension.TypeFactoryprotected final CampaignService<Campaign>protected CampaignCodeGenerationPropertiesprotected final OfferCodeService<OfferCode>protected final CodeGeneratorService<CodeGenerator> -
Constructor Summary
ConstructorsConstructorDescriptionDefaultCodeGenerationService(com.broadleafcommerce.common.extension.TypeFactory campaignFactory, CodeFormatAvailableCharHelper availableCharHelper, CodeGeneratorService<CodeGenerator> service, OfferCodeService<OfferCode> offerCodeService, CampaignService<Campaign> campaignService) -
Method Summary
Modifier and TypeMethodDescriptionprotected intcreateBatchOfCodes(String originalCodeFormat, CodeGeneratorBucket bucket, int numberToCreate, Set<String> currentCodeSet) protected StringcreateCode(String codeFormat, CodeGeneratorBucket bucket, Random r) Uses the code format (e.g.protected CodeGeneratorBucketcreateCodeGeneratorBucket(CodeGenerator generator, int batchSize) Provide ability to override CodeGeneratorBucketprotected CodeGenerationResultgenerateCodes(CodeGenerator generator, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Generates and returns a list ofoffer codesbased on the givenCodeGenerator.generateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theCodeGenerationResultcontaining generated and/or existingOfferCodesfor voucher offers based on the givenVoucherCodeGenerationRequest.protected CodeGenerationResultgenerateOrUseAvailableCodes(VoucherCodeGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns aCodeGenerationResultcontaining a list of generated and/or existingoffer codesbased on the givenVoucherCodeGenerationRequest.protected CodeGenerationResultgenerateVoucherCodes(VoucherCodeGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Delegates togenerateOrUseAvailableCodes(VoucherCodeGenerationRequest, ContextInfo)to get aCodeGenerationResult, then updatesCodeGenerationResult.getGeneratedCodes()based onVoucherCodeGenerationRequest.getCodeGenerator().protected CodeFormatAvailableCharHelperprotected intReturns the batch size for generating new offer codes.protected intgetBatchSize(CodeGenerator generator) protected intReturns the batch size for generating new offer codes for voucher offers.protected com.broadleafcommerce.common.extension.TypeFactoryprotected CampaignService<Campaign>protected CampaignCodeGenerationPropertiesprotected intAffects the "guessability" of codes when a code format has not been provided.protected OfferCodeService<OfferCode>protected CodeGeneratorService<CodeGenerator>markInProgressAndGenerateAndGetCodes(CodeGenerator codeGenerationInfo, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Updates theCodeGeneratorto have a status ofCodeGenerationStatusType.IN_PROCESS, then performs the code generation.protected voidprocessCodeGeneratorError(CodeGenerationResult generationResult, CodeGenerator codeGenerator, int codesCreated, String errorMessage, Exception exception, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) protected voidsetBatchSize(int batchSize) Deprecated.voidsetCodeGenerationProperties(CampaignCodeGenerationProperties codeGenerationProperties) protected CodeGeneratorupdateCodesGenerated(CodeGenerator info, int codesCreated, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.broadleafcommerce.promotion.offer.service.CodeGenerationService
markInProgressAndGenerateCodes
-
Field Details
-
campaignFactory
protected final com.broadleafcommerce.common.extension.TypeFactory campaignFactory -
availableCharHelper
-
service
-
offerCodeService
-
campaignService
-
codeGenerationProperties
-
-
Constructor Details
-
DefaultCodeGenerationService
public DefaultCodeGenerationService(com.broadleafcommerce.common.extension.TypeFactory campaignFactory, CodeFormatAvailableCharHelper availableCharHelper, CodeGeneratorService<CodeGenerator> service, OfferCodeService<OfferCode> offerCodeService, CampaignService<Campaign> campaignService)
-
-
Method Details
-
markInProgressAndGenerateAndGetCodes
public CodeGenerationResult markInProgressAndGenerateAndGetCodes(CodeGenerator codeGenerationInfo, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Description copied from interface:CodeGenerationServiceUpdates theCodeGeneratorto have a status ofCodeGenerationStatusType.IN_PROCESS, then performs the code generation.- Specified by:
markInProgressAndGenerateAndGetCodesin interfaceCodeGenerationService- Parameters:
codeGenerationInfo- 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
public CodeGenerationResult generateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Description copied from interface:CodeGenerationServiceReturns 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.- Specified by:
generateCodesForVouchersin interfaceCodeGenerationService- 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.
-
generateCodes
protected CodeGenerationResult generateCodes(CodeGenerator generator, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Generates and returns a list ofoffer codesbased on the givenCodeGenerator.The
offer codesare generated in batches based onCampaignCodeGenerationProperties.- Parameters:
generator- theCodeGeneratorto generate theoffer codeswithcontextRequest- the context of the request with which to generate codes- Returns:
- a list of
offer codesgenerated from the givenCodeGenerator
-
getBatchSize
-
createCodeGeneratorBucket
Provide ability to override CodeGeneratorBucket- Parameters:
generator- theCodeGeneratorto generate theoffer codeswithbatchSize- the number of records to process within an iteration- Returns:
- the new
CodeGeneratorBucketconfiguration
-
processCodeGeneratorError
protected void processCodeGeneratorError(CodeGenerationResult generationResult, CodeGenerator codeGenerator, int codesCreated, String errorMessage, @Nullable Exception exception, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) -
generateVoucherCodes
protected CodeGenerationResult generateVoucherCodes(VoucherCodeGenerationRequest request, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Delegates togenerateOrUseAvailableCodes(VoucherCodeGenerationRequest, ContextInfo)to get aCodeGenerationResult, then updatesCodeGenerationResult.getGeneratedCodes()based onVoucherCodeGenerationRequest.getCodeGenerator().- Parameters:
request- theVoucherCodeGenerationRequestto generate theoffer codesfromcontextInfo- context surrounding sandboxing and multitenant state- Returns:
- a
CodeGenerationResultcontaining a list of generatedoffer codesbased on the givenVoucherCodeGenerationRequest
-
generateOrUseAvailableCodes
protected CodeGenerationResult generateOrUseAvailableCodes(VoucherCodeGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns aCodeGenerationResultcontaining a list of generated and/or existingoffer codesbased on the givenVoucherCodeGenerationRequest.If there's an existing
CodeGeneratorwithVoucherCodeGenerationRequest.getVoucherCampaignId(), then it will be used to retrieve the availableoffer codes. Otherwise, a newCodeGeneratorwill be created based on the givenVoucherCodeGenerationRequest.getCodeGenerator().If there's sufficient amount of existing
offer codesforCodeGenerator.getNumberOfCodesToGenerate(), then they will be used. Otherwise, more will be generated untilCodeGenerator.getNumberOfCodesToGenerate()is met.- Parameters:
request- theVoucherCodeGenerationRequestto get theCodeGeneratorfromcontextInfo- context surrounding sandboxing and multitenant state- Returns:
- a
CodeGenerationResultcontaining a list of generated or existingoffer codesbased on the givenVoucherCodeGenerationRequest
-
updateCodesGenerated
protected CodeGenerator updateCodesGenerated(CodeGenerator info, int codesCreated, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) -
createBatchOfCodes
protected int createBatchOfCodes(String originalCodeFormat, CodeGeneratorBucket bucket, int numberToCreate, Set<String> currentCodeSet) - Parameters:
originalCodeFormat-bucket-numberToCreate-currentCodeSet-- Returns:
-
createCode
Uses the code format (e.g. ###-@@@@-###) to randomly create the code. The fixedChars parameter represents the part of the code that has been locked in for example to representing the "bucket" characters currently being generated.- Parameters:
codeFormat-r-- Returns:
-
getBatchSize
protected int getBatchSize()Returns the batch size for generating new offer codes. A separate transaction will be created for each batch of codes.- Returns:
- the batch size for generating new offer codes
-
getBatchSizeForVouchers
protected int getBatchSizeForVouchers()Returns the batch size for generating new offer codes for voucher offers. A separate transaction will be created for each batch of codes.- Returns:
- the batch size for generating new offer codes for voucher offers
-
setBatchSize
Deprecated.Since 1.6, useCampaignCodeGenerationProperties.getBatchSize()instead.Returns the batch size for generating new offer codes. A separate transaction will be created for each batch of codes. -
getCodeMultiplier
protected int getCodeMultiplier()Affects the "guessability" of codes when a code format has not been provided. For example, if 100 codes are being generated, the default will insure that the codes are generated at least from a pool of 100000 possible codes.- Returns:
-
getCampaignFactory
protected com.broadleafcommerce.common.extension.TypeFactory getCampaignFactory() -
getAvailableCharHelper
-
getService
-
getOfferCodeService
-
getCampaignService
-
getCodeGenerationProperties
-
setCodeGenerationProperties
@Autowired public void setCodeGenerationProperties(CampaignCodeGenerationProperties codeGenerationProperties)
-
CampaignCodeGenerationProperties.getBatchSize()instead.