Class DefaultCodeGenerationService
- java.lang.Object
-
- com.broadleafcommerce.promotion.campaign.service.DefaultCodeGenerationService
-
- All Implemented Interfaces:
CodeGenerationService
public class DefaultCodeGenerationService extends Object implements CodeGenerationService
- Author:
- Chad Harchar (charchar)
-
-
Field Summary
Fields Modifier and Type Field Description protected CodeFormatAvailableCharHelperavailableCharHelperprotected com.broadleafcommerce.common.extension.TypeFactorycampaignFactoryprotected CampaignService<Campaign>campaignServiceprotected CampaignCodeGenerationPropertiescodeGenerationPropertiesprotected CampaignCodeService<CampaignCode>codeServiceprotected CodeGeneratorService<CodeGenerator>service
-
Constructor Summary
Constructors Constructor Description DefaultCodeGenerationService(com.broadleafcommerce.common.extension.TypeFactory campaignFactory, CodeFormatAvailableCharHelper availableCharHelper, CodeGeneratorService<CodeGenerator> service, CampaignCodeService<CampaignCode> codeService, CampaignService<Campaign> campaignService)
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected 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 ofCampaignCodesbased on the givenCodeGenerator.CodeGenerationResultgenerateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)Returns theCodeGenerationResultcontaining generated and/or existingCampaignCodesfor 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 existingCampaignCodesbased 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 CodeFormatAvailableCharHelpergetAvailableCharHelper()protected intgetBatchSize()Returns the batch size for generating new offer codes.protected intgetBatchSize(CodeGenerator generator)protected intgetBatchSizeForVouchers()Returns the batch size for generating new offer codes for voucher offers.protected com.broadleafcommerce.common.extension.TypeFactorygetCampaignFactory()protected CampaignService<Campaign>getCampaignService()protected CampaignCodeGenerationPropertiesgetCodeGenerationProperties()protected intgetCodeMultiplier()Affects the "guessability" of codes when a code format has not been provided.protected CampaignCodeService<CampaignCode>getCodeService()protected CodeGeneratorService<CodeGenerator>getService()CodeGenerationResultmarkInProgressAndGenerateAndGetCodes(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)CodeGeneratorsaveCampaignCodeGenerationInfo(CodeGenerator info)protected voidsetBatchSize(int batchSize)Deprecated.Since 1.6, useCampaignCodeGenerationProperties.getBatchSize()instead.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, wait
-
Methods inherited from interface com.broadleafcommerce.promotion.campaign.service.CodeGenerationService
markInProgressAndGenerateCodes
-
-
-
-
Field Detail
-
campaignFactory
protected final com.broadleafcommerce.common.extension.TypeFactory campaignFactory
-
availableCharHelper
protected final CodeFormatAvailableCharHelper availableCharHelper
-
service
protected final CodeGeneratorService<CodeGenerator> service
-
codeService
protected final CampaignCodeService<CampaignCode> codeService
-
campaignService
protected final CampaignService<Campaign> campaignService
-
codeGenerationProperties
protected CampaignCodeGenerationProperties codeGenerationProperties
-
-
Constructor Detail
-
DefaultCodeGenerationService
public DefaultCodeGenerationService(com.broadleafcommerce.common.extension.TypeFactory campaignFactory, CodeFormatAvailableCharHelper availableCharHelper, CodeGeneratorService<CodeGenerator> service, CampaignCodeService<CampaignCode> codeService, CampaignService<Campaign> campaignService)
-
-
Method Detail
-
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 generatedCampaignCodesand error message based on the givenCodeGenerator
-
generateCodesForVouchers
public CodeGenerationResult generateCodesForVouchers(VoucherCodeGenerationRequest voucherCodeGenerationReq, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo)
Description copied from interface:CodeGenerationServiceReturns theCodeGenerationResultcontaining generated and/or existingCampaignCodesfor 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
CampaignCodesand 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 voucherCampaignCodeswithcontextInfo- The context of the request with which to generate codes- Returns:
- the
CodeGenerationResultcontaining generated and/or existingCampaignCodesfor 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 ofCampaignCodesbased on the givenCodeGenerator.The
CampaignCodesare generated in batches based onCampaignCodeGenerationProperties.- Parameters:
generator- theCodeGeneratorto generate theCampaignCodeswithcontextRequest- the context of the request with which to generate codes- Returns:
- a list of
CampaignCodesgenerated from the givenCodeGenerator
-
getBatchSize
protected int getBatchSize(CodeGenerator generator)
-
createCodeGeneratorBucket
protected CodeGeneratorBucket createCodeGeneratorBucket(CodeGenerator generator, int batchSize)
Provide ability to override CodeGeneratorBucket- Parameters:
generator-batchSize-- Returns:
-
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, 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 theCampaignCodesfromcontextInfo- context surrounding sandboxing and multitenant state- Returns:
- a
CodeGenerationResultcontaining a list of generatedCampaignCodesbased 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 existingCampaignCodesbased on the givenVoucherCodeGenerationRequest.If there's an existing
CodeGeneratorwithVoucherCodeGenerationRequest.getVoucherCampaignId(), then it will be used to retrieve the availableCampaignCodes. Otherwise, a newCodeGeneratorwill be created based on the givenVoucherCodeGenerationRequest.getCodeGenerator().If there's sufficient amount of existing
CampaignCodesforCodeGenerator.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 existingCampaignCodesbased 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
protected String createCode(String codeFormat, CodeGeneratorBucket bucket, Random r)
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:
-
saveCampaignCodeGenerationInfo
public CodeGenerator saveCampaignCodeGenerationInfo(CodeGenerator info)
-
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 protected void setBatchSize(int batchSize)
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
protected CodeFormatAvailableCharHelper getAvailableCharHelper()
-
getService
protected CodeGeneratorService<CodeGenerator> getService()
-
getCodeService
protected CampaignCodeService<CampaignCode> getCodeService()
-
getCampaignService
protected CampaignService<Campaign> getCampaignService()
-
getCodeGenerationProperties
protected CampaignCodeGenerationProperties getCodeGenerationProperties()
-
setCodeGenerationProperties
@Autowired public void setCodeGenerationProperties(CampaignCodeGenerationProperties codeGenerationProperties)
-
-