Class DefaultCouponCodeGenerationService

java.lang.Object
de.hybris.platform.couponservices.services.impl.DefaultCouponCodeGenerationService
All Implemented Interfaces:
CouponCodeGenerationService, org.springframework.beans.factory.InitializingBean

public class DefaultCouponCodeGenerationService extends Object implements CouponCodeGenerationService, org.springframework.beans.factory.InitializingBean
The default coupon code generation service.
  • Field Details

  • Constructor Details

    • DefaultCouponCodeGenerationService

      public DefaultCouponCodeGenerationService()
  • Method Details

    • afterPropertiesSet

      public void afterPropertiesSet()
      Specified by:
      afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
    • generateCouponSignature

      public String generateCouponSignature()
      Description copied from interface: CouponCodeGenerationService
      generates a base64 encoded String representing the signature of the multi code coupon. The signature is used to generate the cipher-text part of the coupon code which incorporates the signed first half of the coupon code.
      Specified by:
      generateCouponSignature in interface CouponCodeGenerationService
      Returns:
      base64 encoded String representing the signature of the multi code coupon
    • generateCouponAlphabet

      public String generateCouponAlphabet()
      Description copied from interface: CouponCodeGenerationService
      generates the alphabet used for a coupon.
      Specified by:
      generateCouponAlphabet in interface CouponCodeGenerationService
      Returns:
      alphabet string used for a coupon
    • generateCouponCode

      public String generateCouponCode(MultiCodeCouponModel coupon)
      Description copied from interface: CouponCodeGenerationService
      Generates a code for the given multi code coupon. Note: This method doesn't save the given coupon, but modifies it (by incrementing the couponCodeNumber attribute)
      Specified by:
      generateCouponCode in interface CouponCodeGenerationService
      Parameters:
      coupon - multi code coupon
      Returns:
      generated coupon code
      Throws:
      CouponCodeGenerationException
    • generateCouponCodes

      public Optional<MediaModel> generateCouponCodes(MultiCodeCouponModel multiCodeCoupon, int quantity)
      Description copied from interface: CouponCodeGenerationService
      Generates codes for the given multi-code coupon. Returns a MediaModel containing a csv file with the generated codes. Note that the returned file contains quantity coupon codes or less. It contains less codes if the requested quantity cannot be generated (e.g. if the limit of codes has been reached). If no coupon codes could be generated an Optional.empty() is returned.
      Specified by:
      generateCouponCodes in interface CouponCodeGenerationService
      Parameters:
      multiCodeCoupon - Multi code coupon instance
      quantity - number of coupon codes to be generated
      Returns:
      MediaModel containing a csv file with the generated codes. If no coupon codes could be generated an Optional.empty() is returned.
    • generateMediaForMultiCodeCoupon

      protected Optional<MediaModel> generateMediaForMultiCodeCoupon(MultiCodeCouponModel multiCodeCoupon, int quantity)
    • createMedia

      protected MediaModel createMedia(MultiCodeCouponModel coupon, int quantity)
    • getMediaFolderForCouponCodes

      protected MediaFolderModel getMediaFolderForCouponCodes()
    • extractCouponPrefix

      public String extractCouponPrefix(String couponCode)
      Description copied from interface: CouponCodeGenerationService
      tries to find the prefix substring of the given coupon code.
      Specified by:
      extractCouponPrefix in interface CouponCodeGenerationService
      Parameters:
      couponCode - coupon code to extract prefix substring
      Returns:
      the (assumed) prefix of the given coupon code or null if none could be determined
    • verifyCouponCode

      public boolean verifyCouponCode(MultiCodeCouponModel coupon, String couponCode)
      Description copied from interface: CouponCodeGenerationService
      verifies if the given couponCode is valid for the given coupon.
      Specified by:
      verifyCouponCode in interface CouponCodeGenerationService
      Parameters:
      coupon - Coupon against which check will be fired
      couponCode - Coupon code to verify
      Returns:
      true if the couponCode is valid, otherwise false
    • validateCouponFormat

      protected boolean validateCouponFormat(MultiCodeCouponModel coupon, String couponCode)
      validates the given coupon code with regards to its format (i.e. correct prefix, separators, coupon parts).
    • verifyCipherText

      protected boolean verifyCipherText(MultiCodeCouponModel coupon, String couponCode)
      Returns:
      true if generated ciphertext matches given ciphertext , false otherwise
    • verifyUsedCouponCodeNumber

      protected boolean verifyUsedCouponCodeNumber(MultiCodeCouponModel coupon, org.apache.commons.lang3.tuple.Pair<String,String> pair)
      Returns:
      true if used coupon code number is greater than 0 and less than CouponCodeNumber on multi code coupon,false otherwise
    • isValidCodeSeparator

      public boolean isValidCodeSeparator(String codeSeparator)
      Description copied from interface: CouponCodeGenerationService
      verifies if the given string is a valid code separator
      Specified by:
      isValidCodeSeparator in interface CouponCodeGenerationService
      Parameters:
      codeSeparator - Code separator
      Returns:
      true if the codeSeperator is valid, otherwise false
    • extractClearTextAndCipherText

      protected org.apache.commons.lang3.tuple.Pair<String,String> extractClearTextAndCipherText(MultiCodeCouponModel coupon, String couponCode)
      returns a string pair containing the clear text and the cipher text part of the given coupon code.
      Returns:
      a string pair or null if the parts cannot be determined
    • removeCodeSeparators

      protected String removeCodeSeparators(String codeWithOutPrefix, MultiCodeCouponModel coupon)
      removes the code separator from the given codeWithoutPrefix. Note: Expects the given code to be without its prefix.
      Throws:
      IllegalArgumentException - if the given code doesn't match with the required length of the given coupon's configuration
    • getCipherTextLength

      protected int getCipherTextLength(MultiCodeCouponModel coupon)
      returns the amount of cipher-text characters to be created for the given coupon.
    • getClearTextLength

      protected int getClearTextLength(MultiCodeCouponModel coupon)
      returns the amount of clear-text characters to be created for the given coupon.
    • getLengthFor

      protected int getLengthFor(MultiCodeCouponModel coupon, boolean clearText)
    • getAndValidateAlphabetLength

      protected int getAndValidateAlphabetLength(String globalCharacterSet)
      validates the coupon alphabet length and returns it
    • getAndValidateGlobalCharacterSet

      protected String getAndValidateGlobalCharacterSet()
      validates that the global character set doesn't contain the defined code separators and that all characters are single-byte characters.
      Returns:
      the validated global character set
      Throws:
      CouponCodeGenerationException - if the validation fails
    • getAndValidateAlgorithm

      protected String getAndValidateAlgorithm()
      validates the configured algorithm used for the cipher part of the coupon code
    • getConfigurationService

      protected ConfigurationService getConfigurationService()
    • setConfigurationService

      public void setConfigurationService(ConfigurationService configurationService)
    • getClearTextStrategy

      protected CouponCodeClearTextGenerationStrategy getClearTextStrategy()
    • setClearTextStrategy

      public void setClearTextStrategy(CouponCodeClearTextGenerationStrategy clearTextStrategy)
    • getCipherTextStrategy

      protected CouponCodeCipherTextGenerationStrategy getCipherTextStrategy()
    • setCipherTextStrategy

      public void setCipherTextStrategy(CouponCodeCipherTextGenerationStrategy cipherTextStrategy)
    • getModelService

      protected ModelService getModelService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getMediaService

      protected MediaService getMediaService()
    • setMediaService

      public void setMediaService(MediaService mediaService)
    • getCodeSeparatorPattern

      protected String getCodeSeparatorPattern()
    • setCodeSeparatorPattern

      public void setCodeSeparatorPattern(String codeSeparatorPattern)
    • getCouponCodesGenerator

      protected CouponCodesGenerator getCouponCodesGenerator()
    • setCouponCodesGenerator

      public void setCouponCodesGenerator(CouponCodesGenerator couponCodesGenerator)
    • getBatchSize

      protected Integer getBatchSize()
    • getKeyGenerator

      protected KeyGenerator getKeyGenerator()
    • setKeyGenerator

      public void setKeyGenerator(KeyGenerator keyGenerator)