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 Details

    • offerCodePersister

      protected OfferCodePersister offerCodePersister
    • offerDao

      protected org.broadleafcommerce.core.offer.dao.OfferDao offerDao
    • advOfferCodeDao

      protected AdvOfferCodeDao advOfferCodeDao
    • systemPropertiesService

      protected org.broadleafcommerce.common.config.service.SystemPropertiesService systemPropertiesService
    • availableCharHelper

      protected CodeFormatAvailableCharHelper availableCharHelper
    • adminSecurityService

      @Qualifier("blAdminSecurityService") @Autowired(required=false) protected org.broadleafcommerce.openadmin.server.security.service.AdminSecurityService adminSecurityService
  • Constructor Details

    • CodeGeneratorServiceImpl

      public CodeGeneratorServiceImpl()
  • Method Details

    • validateCodeGenerationInfo

      public void validateCodeGenerationInfo(OfferCodeGenerationInfo info)
      Description copied from interface: CodeGeneratorService
      Validates 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:
      validateCodeGenerationInfo in interface CodeGeneratorService
      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:
      generateSmallAmountOfCodes in interface CodeGeneratorService
      Parameters:
      info -
    • generateCodes

      public void generateCodes(OfferCodeGenerationInfo info)
      Description copied from interface: CodeGeneratorService
      Generates codes for an offer based on the passed in codeGenerationInfo.
      Specified by:
      generateCodes in interface CodeGeneratorService
      See Also:
    • startCodeGeneration

      public void startCodeGeneration(OfferCodeGenerationInfo codeGenerationInfo)
      Description copied from interface: CodeGeneratorService
      Generates codes for an offer based on the passed in codeGenerationInfo.
      Specified by:
      startCodeGeneration in interface CodeGeneratorService
      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

      protected String determineCodeFormat(OfferCodeGenerationInfo info)
      If a code format was not specified, then create one using the prefix and alphanumeric characters for the specified length.
      Parameters:
      info -
    • createCode

      protected String createCode(String codeFormat, 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:
    • createOfferCodeGenerationInfo

      public OfferCodeGenerationInfo createOfferCodeGenerationInfo()
      Specified by:
      createOfferCodeGenerationInfo in interface CodeGeneratorService
    • saveOfferCodeGenerationInfo

      public OfferCodeGenerationInfo saveOfferCodeGenerationInfo(OfferCodeGenerationInfo info)
      Specified by:
      saveOfferCodeGenerationInfo in interface CodeGeneratorService
    • 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:
      consumeEvent in interface com.broadleafcommerce.jobsevents.service.SystemEventConsumer
    • getEventType

      public String getEventType()
      Specified by:
      getEventType in interface com.broadleafcommerce.jobsevents.service.SystemEventConsumer
    • findOfferCodeGenerationInfoById

      public OfferCodeGenerationInfo findOfferCodeGenerationInfoById(Long ocgiId)
      Specified by:
      findOfferCodeGenerationInfoById in interface CodeGeneratorService
    • findBatchOfferCodeByCodeGenerationId

      public List<org.broadleafcommerce.core.offer.domain.OfferCode> findBatchOfferCodeByCodeGenerationId(Long firstId, int count, Long ocgiId)
      Specified by:
      findBatchOfferCodeByCodeGenerationId in interface CodeGeneratorService
    • findBatchOfferCodeByCodeGenerationId

      public List<org.broadleafcommerce.core.offer.domain.OfferCode> findBatchOfferCodeByCodeGenerationId(int recordNumber, int count, Long ocgiId)
      Specified by:
      findBatchOfferCodeByCodeGenerationId in interface CodeGeneratorService
    • clear

      public void clear()
      Specified by:
      clear in interface CodeGeneratorService
    • findNumberOfOfferCodesForCodeGroup

      public Long findNumberOfOfferCodesForCodeGroup(Long codeGroupId)
      Specified by:
      findNumberOfOfferCodesForCodeGroup in interface CodeGeneratorService