Class DefaultCodeGenerationService
- All Implemented Interfaces:
CodeGenerationService
- Author:
- Chad Harchar (charchar)
-
Field Summary
Modifier and TypeFieldDescriptionprotected final CodeFormatAvailableCharHelper
protected final com.broadleafcommerce.common.extension.TypeFactory
protected final CampaignService<Campaign>
protected CampaignCodeGenerationProperties
protected final OfferCodeService<OfferCode>
protected final CodeGeneratorService<CodeGenerator>
-
Constructor Summary
ConstructorDescriptionDefaultCodeGenerationService
(com.broadleafcommerce.common.extension.TypeFactory campaignFactory, CodeFormatAvailableCharHelper availableCharHelper, CodeGeneratorService<CodeGenerator> service, OfferCodeService<OfferCode> offerCodeService, CampaignService<Campaign> campaignService) -
Method Summary
Modifier and TypeMethodDescriptionprotected int
createBatchOfCodes
(String originalCodeFormat, CodeGeneratorBucket bucket, int numberToCreate, Set<String> currentCodeSet) protected String
createCode
(String codeFormat, CodeGeneratorBucket bucket, Random r) Uses the code format (e.g.protected CodeGeneratorBucket
createCodeGeneratorBucket
(CodeGenerator generator, int batchSize) Provide ability to override CodeGeneratorBucketprotected CodeGenerationResult
generateCodes
(CodeGenerator generator, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) Generates and returns a list ofoffer codes
based on the givenCodeGenerator
.generateCodesForVouchers
(VoucherCodeGenerationRequest voucherCodeGenerationReq, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns theCodeGenerationResult
containing generated and/or existingOfferCodes
for voucher offers based on the givenVoucherCodeGenerationRequest
.protected CodeGenerationResult
generateOrUseAvailableCodes
(VoucherCodeGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns aCodeGenerationResult
containing a list of generated and/or existingoffer codes
based on the givenVoucherCodeGenerationRequest
.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()
.protected CodeFormatAvailableCharHelper
protected int
Returns the batch size for generating new offer codes.protected int
getBatchSize
(CodeGenerator generator) protected int
Returns the batch size for generating new offer codes for voucher offers.protected com.broadleafcommerce.common.extension.TypeFactory
protected CampaignService<Campaign>
protected CampaignCodeGenerationProperties
protected int
Affects 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 theCodeGenerator
to have a status ofCodeGenerationStatusType.IN_PROCESS
, then performs the code generation.protected void
processCodeGeneratorError
(CodeGenerationResult generationResult, CodeGenerator codeGenerator, int codesCreated, String errorMessage, Exception exception, com.broadleafcommerce.data.tracking.core.context.ContextRequest contextRequest) protected void
setBatchSize
(int batchSize) Deprecated.void
setCodeGenerationProperties
(CampaignCodeGenerationProperties codeGenerationProperties) protected CodeGenerator
updateCodesGenerated
(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.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:CodeGenerationService
Updates theCodeGenerator
to have a status ofCodeGenerationStatusType.IN_PROCESS
, then performs the code generation.- Specified by:
markInProgressAndGenerateAndGetCodes
in 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
CodeGenerationResult
containing the generatedOfferCodes
and 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:CodeGenerationService
Returns theCodeGenerationResult
containing generated and/or existingOfferCodes
for voucher offers based on the givenVoucherCodeGenerationRequest
.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.- Specified by:
generateCodesForVouchers
in interfaceCodeGenerationService
- Parameters:
voucherCodeGenerationReq
- theVoucherCodeGenerationRequest
to generate the voucherOfferCodes
withcontextInfo
- The context of the request with which to generate codes- Returns:
- the
CodeGenerationResult
containing generated and/or existingOfferCodes
for 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 codes
based on the givenCodeGenerator
.The
offer codes
are generated in batches based onCampaignCodeGenerationProperties
.- Parameters:
generator
- theCodeGenerator
to generate theoffer codes
withcontextRequest
- the context of the request with which to generate codes- Returns:
- a list of
offer codes
generated from the givenCodeGenerator
-
getBatchSize
-
createCodeGeneratorBucket
Provide ability to override CodeGeneratorBucket- Parameters:
generator
- theCodeGenerator
to generate theoffer codes
withbatchSize
- the number of records to process within an iteration- Returns:
- the new
CodeGeneratorBucket
configuration
-
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
- theVoucherCodeGenerationRequest
to generate theoffer codes
fromcontextInfo
- context surrounding sandboxing and multitenant state- Returns:
- a
CodeGenerationResult
containing a list of generatedoffer codes
based on the givenVoucherCodeGenerationRequest
-
generateOrUseAvailableCodes
protected CodeGenerationResult generateOrUseAvailableCodes(VoucherCodeGenerationRequest request, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Returns aCodeGenerationResult
containing a list of generated and/or existingoffer codes
based on the givenVoucherCodeGenerationRequest
.If there's an existing
CodeGenerator
withVoucherCodeGenerationRequest.getVoucherCampaignId()
, then it will be used to retrieve the availableoffer codes
. Otherwise, a newCodeGenerator
will be created based on the givenVoucherCodeGenerationRequest.getCodeGenerator()
.If there's sufficient amount of existing
offer codes
forCodeGenerator.getNumberOfCodesToGenerate()
, then they will be used. Otherwise, more will be generated untilCodeGenerator.getNumberOfCodesToGenerate()
is met.- Parameters:
request
- theVoucherCodeGenerationRequest
to get theCodeGenerator
fromcontextInfo
- context surrounding sandboxing and multitenant state- Returns:
- a
CodeGenerationResult
containing a list of generated or existingoffer codes
based 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.