Class CodeGeneratorServiceImpl
java.lang.Object
com.broadleafcommerce.jobsevents.service.AbstractSystemEventConsumer
com.broadleafcommerce.advancedoffer.codes.service.CodeGeneratorServiceImpl
- All Implemented Interfaces:
CodeGeneratorService,com.broadleafcommerce.jobsevents.service.EntityManagerFactoryAwareSystemEventConsumer,com.broadleafcommerce.jobsevents.service.SystemEventConsumer,org.springframework.core.Ordered
@Service("blCodeGeneratorService")
public class CodeGeneratorServiceImpl
extends com.broadleafcommerce.jobsevents.service.AbstractSystemEventConsumer
implements CodeGeneratorService
Service that takes in an Offer Id and generates codes.
- Author:
- bpolster
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.broadleafcommerce.openadmin.server.security.service.AdminSecurityServiceprotected AdvOfferCodeDaoprotected CodeFormatAvailableCharHelperprotected OfferCodePersisterprotected org.broadleafcommerce.core.offer.dao.OfferDaoprotected org.broadleafcommerce.common.config.service.SystemPropertiesServiceFields inherited from class com.broadleafcommerce.jobsevents.service.AbstractSystemEventConsumer
entityManagerFactoryFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCEFields inherited from interface com.broadleafcommerce.jobsevents.service.SystemEventConsumer
DEFAULT_PRECEDENCE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected intcalculateRequiredCodeLength(int numberOfCodes, int charSetSize) Returns the size of the code that you must create in order to support the passed in number of Codes.voidclear()voidconsumeEvent(com.broadleafcommerce.jobsevents.domain.SystemEvent event) protected intcreateBatchOfCodes(String originalCodeFormat, CodeGeneratorBucket bucket, int numberToCreate, Set<String> currentCodeSet) protected StringcreateCode(String codeFormat, Random r) Uses the code format (e.g. ###-@@@@-###) to randomly create the code.protected StringIf a code format was not specified, then create one using the prefix and alphanumeric characters for the specified length.List<org.broadleafcommerce.core.offer.domain.OfferCode>findBatchOfferCodeByCodeGenerationId(int recordNumber, int count, Long ocgiId) List<org.broadleafcommerce.core.offer.domain.OfferCode>findBatchOfferCodeByCodeGenerationId(Long firstId, int count, Long ocgiId) findNumberOfOfferCodesForCodeGroup(Long codeGroupId) findOfferCodeGenerationInfoById(Long ocgiId) voidGenerates codes for an offer based on the passed in codeGenerationInfo.List<org.broadleafcommerce.core.offer.domain.OfferCode>This method is used to generate <= 100 codes.protected intReturns the batch size for generating new offer codes.intprotected intAffects the "guessability" of codes when a code format has not been provided.protected intprotected voidsetBatchSize(int batchSize) Returns the batch size for generating new offer codes.voidstartCodeGeneration(OfferCodeGenerationInfo codeGenerationInfo) Generates codes for an offer based on the passed in codeGenerationInfo.protected OfferCodeGenerationInfoupdateCodesGenerated(OfferCodeGenerationInfo info, int codesCreated) voidValidates that the codeFormat for the codeGenerationInfo is large enough to hold the number of codes desired ensuring that the codes are not easily guessable.Methods inherited from class com.broadleafcommerce.jobsevents.service.AbstractSystemEventConsumer
getEntityManagerFactory, getOrder, setEntityManagerFactory
-
Field Details
-
offerCodePersister
-
offerDao
protected org.broadleafcommerce.core.offer.dao.OfferDao offerDao -
advOfferCodeDao
-
systemPropertiesService
protected org.broadleafcommerce.common.config.service.SystemPropertiesService systemPropertiesService -
availableCharHelper
-
adminSecurityService
@Qualifier("blAdminSecurityService") @Autowired(required=false) protected org.broadleafcommerce.openadmin.server.security.service.AdminSecurityService adminSecurityService
-
-
Constructor Details
-
CodeGeneratorServiceImpl
public CodeGeneratorServiceImpl()
-
-
Method Details
-
validateCodeGenerationInfo
Description copied from interface:CodeGeneratorServiceValidates that the codeFormat for the codeGenerationInfo is large enough to hold the number of codes desired ensuring that the codes are not easily guessable.- Specified by:
validateCodeGenerationInfoin interfaceCodeGeneratorService- See Also:
-
generateSmallAmountOfCodes
public List<org.broadleafcommerce.core.offer.domain.OfferCode> generateSmallAmountOfCodes(OfferCodeGenerationInfo info) This method is used to generate <= 100 codes. Use @{link generateCodes} if > 100 codes are needed.- Specified by:
generateSmallAmountOfCodesin interfaceCodeGeneratorService- Parameters:
info-
-
generateCodes
Description copied from interface:CodeGeneratorServiceGenerates codes for an offer based on the passed in codeGenerationInfo.- Specified by:
generateCodesin interfaceCodeGeneratorService- See Also:
-
startCodeGeneration
Description copied from interface:CodeGeneratorServiceGenerates codes for an offer based on the passed in codeGenerationInfo.- Specified by:
startCodeGenerationin interfaceCodeGeneratorService- See Also:
-
updateCodesGenerated
protected OfferCodeGenerationInfo updateCodesGenerated(OfferCodeGenerationInfo info, int codesCreated) -
createBatchOfCodes
protected int createBatchOfCodes(String originalCodeFormat, CodeGeneratorBucket bucket, int numberToCreate, Set<String> currentCodeSet) - Parameters:
originalCodeFormat-bucket-numberToCreate-currentCodeSet-- Returns:
-
calculateRequiredCodeLength
protected int calculateRequiredCodeLength(int numberOfCodes, int charSetSize) Returns the size of the code that you must create in order to support the passed in number of Codes.- Parameters:
numberOfCodes-- Returns:
-
determineCodeFormat
If a code format was not specified, then create one using the prefix and alphanumeric characters for the specified length.- Parameters:
info-
-
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:
-
createOfferCodeGenerationInfo
- Specified by:
createOfferCodeGenerationInfoin interfaceCodeGeneratorService
-
saveOfferCodeGenerationInfo
- Specified by:
saveOfferCodeGenerationInfoin interfaceCodeGeneratorService
-
getCodeGenerationBatchSize
public int getCodeGenerationBatchSize() -
getMaxSmallBatchRetry
protected int getMaxSmallBatchRetry() -
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:
-
setBatchSize
protected void setBatchSize(int batchSize) 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:
-
consumeEvent
public void consumeEvent(com.broadleafcommerce.jobsevents.domain.SystemEvent event) - Specified by:
consumeEventin interfacecom.broadleafcommerce.jobsevents.service.SystemEventConsumer
-
getEventType
- Specified by:
getEventTypein interfacecom.broadleafcommerce.jobsevents.service.SystemEventConsumer
-
findOfferCodeGenerationInfoById
- Specified by:
findOfferCodeGenerationInfoByIdin interfaceCodeGeneratorService
-
findBatchOfferCodeByCodeGenerationId
public List<org.broadleafcommerce.core.offer.domain.OfferCode> findBatchOfferCodeByCodeGenerationId(Long firstId, int count, Long ocgiId) - Specified by:
findBatchOfferCodeByCodeGenerationIdin interfaceCodeGeneratorService
-
findBatchOfferCodeByCodeGenerationId
public List<org.broadleafcommerce.core.offer.domain.OfferCode> findBatchOfferCodeByCodeGenerationId(int recordNumber, int count, Long ocgiId) - Specified by:
findBatchOfferCodeByCodeGenerationIdin interfaceCodeGeneratorService
-
clear
public void clear()- Specified by:
clearin interfaceCodeGeneratorService
-
findNumberOfOfferCodesForCodeGroup
- Specified by:
findNumberOfOfferCodesForCodeGroupin interfaceCodeGeneratorService
-