Class DefaultCodeGeneratorService<P extends CodeGenerator>

java.lang.Object
com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P>
com.broadleafcommerce.promotion.offer.service.DefaultCodeGeneratorService<P>
All Implemented Interfaces:
com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P>, CodeGeneratorService<P>

public class DefaultCodeGeneratorService<P extends CodeGenerator> extends com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P> implements CodeGeneratorService<P>
Author:
Chad Harchar (charchar)
  • Constructor Details

    • DefaultCodeGeneratorService

      public DefaultCodeGeneratorService(CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable> codeGeneratorRepository, CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> campaignRepository, com.broadleafcommerce.data.tracking.core.service.CrudEntityHelper helper, com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager entityValidatorManager)
  • Method Details

    • updateQuietly

      public P updateQuietly(@NonNull String id, @NonNull P updateRequest, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CodeGeneratorService
      An alternative to CrudEntityHelper.update(String, Object, ContextInfo, TrackableRepository) that does not call CrudEntityHelper.notify(Trackable, ContextInfo, NotificationStateRepository).
      Specified by:
      updateQuietly in interface CodeGeneratorService<P extends CodeGenerator>
      Parameters:
      id - the context id of the CodeGenerator to update
      updateRequest - the CodeGenerator instance containing the new values to patch onto the existing instance
      context - context surrounding sandboxing and multitenant state
      Returns:
      the fully updated instance
    • findByCampaignId

      @NonNull public org.springframework.data.domain.Page<P> findByCampaignId(@NonNull String campaignId, org.springframework.data.domain.Pageable page, @NonNull Class<P> payloadType, com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      findByCampaignId in interface CodeGeneratorService<P extends CodeGenerator>
    • readByCampaignIdAndVoucherCodeGenerator

      @NonNull public Optional<P> readByCampaignIdAndVoucherCodeGenerator(String campaignId, boolean isVoucherCodeGenerator, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CodeGeneratorService
      Finds an active CodeGenerator that is for the given campaign id and is for voucher offers.
      Specified by:
      readByCampaignIdAndVoucherCodeGenerator in interface CodeGeneratorService<P extends CodeGenerator>
      Parameters:
      campaignId - the campaign id that the code generator is for
      isVoucherCodeGenerator - whether this code generator is for voucher offers
      context - context information surrounding sandboxing and multi tenant state
      Returns:
      an active code generator that is for the given campaign id and is for voucher offers
    • create

      public P create(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Specified by:
      create in interface com.broadleafcommerce.data.tracking.core.service.CrudEntityService<P extends CodeGenerator>
      Overrides:
      create in class com.broadleafcommerce.data.tracking.core.service.BaseCrudEntityService<P extends CodeGenerator>
    • createWithoutPersistenceNotification

      @SuppressNotification("PERSISTENCE") public P createWithoutPersistenceNotification(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
      Description copied from interface: CodeGeneratorService
      Creates a CodeGenerator without the persistence notification. This is used when you want to manually generate the CampaignCodes instead of going through the CodeGenerationPersistenceHandler.
      Specified by:
      createWithoutPersistenceNotification in interface CodeGeneratorService<P extends CodeGenerator>
      Parameters:
      businessInstance - the instance of CodeGenerator
      context - context surrounding sandboxing and multitenant state
      Returns:
      the created instance of CodeGenerator
    • initializeCodeFieldsIfMissing

      public void initializeCodeFieldsIfMissing(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • initializeCodePrefix

      protected void initializeCodePrefix(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • initializeCodeFormat

      public void initializeCodeFormat(P businessInstance, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context)
    • 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:
    • 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:
    • getCodeGeneratorRepository

      @NonNull protected CodeGeneratorRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCodeGeneratorRepository()
    • getCampaignRepository

      @Deprecated @NonNull protected CampaignRepository<com.broadleafcommerce.data.tracking.core.Trackable> getCampaignRepository()
      Deprecated.
      since 1.4, use getCampaignService() instead
    • getValidator

      @NonNull protected com.broadleafcommerce.data.tracking.core.mapping.validation.EntityValidatorManager getValidator()
    • setCampaignService

      @Autowired public void setCampaignService(CampaignService<Campaign> campaignService)
    • getCampaignService

      @NonNull protected CampaignService<Campaign> getCampaignService()
    • setAvailableCharHelper

      @Autowired public void setAvailableCharHelper(CodeFormatAvailableCharHelper availableCharHelper)
    • getAvailableCharHelper

      @NonNull protected CodeFormatAvailableCharHelper getAvailableCharHelper()
    • setCodeGeneratorPreValidator

      @Autowired public void setCodeGeneratorPreValidator(CodeGeneratorPreValidator codeGeneratorPreValidator)
    • getCodeGeneratorPreValidator

      @NonNull protected CodeGeneratorPreValidator getCodeGeneratorPreValidator()