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 java.lang.Object implements CouponCodeGenerationService, org.springframework.beans.factory.InitializingBean
The default coupon code generation service.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.String
UNEXPECTED_ERROR_MSG
-
Constructor Summary
Constructors Constructor Description DefaultCouponCodeGenerationService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterPropertiesSet()
protected MediaModel
createMedia(MultiCodeCouponModel coupon, int quantity)
protected org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.String>
extractClearTextAndCipherText(MultiCodeCouponModel coupon, java.lang.String couponCode)
returns a string pair containing the clear text and the cipher text part of the given coupon code.java.lang.String
extractCouponPrefix(java.lang.String couponCode)
tries to find the prefix substring of the given coupon code.java.lang.String
generateCouponAlphabet()
generates the alphabet used for a coupon.java.lang.String
generateCouponCode(MultiCodeCouponModel coupon)
Generates a code for the given multi code coupon.java.util.Optional<MediaModel>
generateCouponCodes(MultiCodeCouponModel multiCodeCoupon, int quantity)
Generates codes for the given multi-code coupon.java.lang.String
generateCouponSignature()
generates a base64 encoded String representing the signature of the multi code coupon.protected java.util.Optional<MediaModel>
generateMediaForMultiCodeCoupon(MultiCodeCouponModel multiCodeCoupon, int quantity)
protected java.lang.String
getAndValidateAlgorithm()
validates the configured algorithm used for the cipher part of the coupon codeprotected int
getAndValidateAlphabetLength(java.lang.String globalCharacterSet)
validates the coupon alphabet length and returns itprotected java.lang.String
getAndValidateGlobalCharacterSet()
validates that the global character set doesn't contain the defined code separators and that all characters are single-byte characters.protected java.lang.Integer
getBatchSize()
protected int
getCipherTextLength(MultiCodeCouponModel coupon)
returns the amount of cipher-text characters to be created for the given coupon.protected CouponCodeCipherTextGenerationStrategy
getCipherTextStrategy()
protected int
getClearTextLength(MultiCodeCouponModel coupon)
returns the amount of clear-text characters to be created for the given coupon.protected CouponCodeClearTextGenerationStrategy
getClearTextStrategy()
protected java.lang.String
getCodeSeparatorPattern()
protected ConfigurationService
getConfigurationService()
protected CouponCodesGenerator
getCouponCodesGenerator()
protected KeyGenerator
getKeyGenerator()
protected int
getLengthFor(MultiCodeCouponModel coupon, boolean clearText)
protected MediaFolderModel
getMediaFolderForCouponCodes()
protected MediaService
getMediaService()
protected ModelService
getModelService()
boolean
isValidCodeSeparator(java.lang.String codeSeparator)
verifies if the given string is a valid code separatorprotected java.lang.String
removeCodeSeparators(java.lang.String codeWithOutPrefix, MultiCodeCouponModel coupon)
removes the code separator from the givencodeWithoutPrefix
.void
setCipherTextStrategy(CouponCodeCipherTextGenerationStrategy cipherTextStrategy)
void
setClearTextStrategy(CouponCodeClearTextGenerationStrategy clearTextStrategy)
void
setCodeSeparatorPattern(java.lang.String codeSeparatorPattern)
void
setConfigurationService(ConfigurationService configurationService)
void
setCouponCodesGenerator(CouponCodesGenerator couponCodesGenerator)
void
setKeyGenerator(KeyGenerator keyGenerator)
void
setMediaService(MediaService mediaService)
void
setModelService(ModelService modelService)
protected boolean
validateCouponFormat(MultiCodeCouponModel coupon, java.lang.String couponCode)
validates the given coupon code with regards to its format (i.e.protected boolean
verifyCipherText(MultiCodeCouponModel coupon, java.lang.String couponCode)
boolean
verifyCouponCode(MultiCodeCouponModel coupon, java.lang.String couponCode)
verifies if the givencouponCode
is valid for the givencoupon
.protected boolean
verifyUsedCouponCodeNumber(MultiCodeCouponModel coupon, org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.String> pair)
-
-
-
Field Detail
-
UNEXPECTED_ERROR_MSG
protected static final java.lang.String UNEXPECTED_ERROR_MSG
- See Also:
- Constant Field Values
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet()
- Specified by:
afterPropertiesSet
in interfaceorg.springframework.beans.factory.InitializingBean
-
generateCouponSignature
public java.lang.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 interfaceCouponCodeGenerationService
- Returns:
- base64 encoded String representing the signature of the multi code coupon
-
generateCouponAlphabet
public java.lang.String generateCouponAlphabet()
Description copied from interface:CouponCodeGenerationService
generates the alphabet used for a coupon.- Specified by:
generateCouponAlphabet
in interfaceCouponCodeGenerationService
- Returns:
- alphabet string used for a coupon
-
generateCouponCode
public java.lang.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 thecouponCodeNumber
attribute)- Specified by:
generateCouponCode
in interfaceCouponCodeGenerationService
- Parameters:
coupon
- multi code coupon- Returns:
- generated coupon code
- Throws:
CouponCodeGenerationException
-
generateCouponCodes
public java.util.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 containsquantity
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 anOptional.empty()
is returned.- Specified by:
generateCouponCodes
in interfaceCouponCodeGenerationService
- Parameters:
multiCodeCoupon
- Multi code coupon instancequantity
- 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 java.util.Optional<MediaModel> generateMediaForMultiCodeCoupon(MultiCodeCouponModel multiCodeCoupon, int quantity)
-
createMedia
protected MediaModel createMedia(MultiCodeCouponModel coupon, int quantity)
-
getMediaFolderForCouponCodes
protected MediaFolderModel getMediaFolderForCouponCodes()
-
extractCouponPrefix
public java.lang.String extractCouponPrefix(java.lang.String couponCode)
Description copied from interface:CouponCodeGenerationService
tries to find the prefix substring of the given coupon code.- Specified by:
extractCouponPrefix
in interfaceCouponCodeGenerationService
- 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, java.lang.String couponCode)
Description copied from interface:CouponCodeGenerationService
verifies if the givencouponCode
is valid for the givencoupon
.- Specified by:
verifyCouponCode
in interfaceCouponCodeGenerationService
- Parameters:
coupon
- Coupon against which check will be firedcouponCode
- Coupon code to verify- Returns:
- true if the couponCode is valid, otherwise false
-
validateCouponFormat
protected boolean validateCouponFormat(MultiCodeCouponModel coupon, java.lang.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, java.lang.String couponCode)
- Returns:
- true if generated ciphertext matches given ciphertext , false otherwise
-
verifyUsedCouponCodeNumber
protected boolean verifyUsedCouponCodeNumber(MultiCodeCouponModel coupon, org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.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(java.lang.String codeSeparator)
Description copied from interface:CouponCodeGenerationService
verifies if the given string is a valid code separator- Specified by:
isValidCodeSeparator
in interfaceCouponCodeGenerationService
- Parameters:
codeSeparator
- Code separator- Returns:
- true if the codeSeperator is valid, otherwise false
-
extractClearTextAndCipherText
protected org.apache.commons.lang3.tuple.Pair<java.lang.String,java.lang.String> extractClearTextAndCipherText(MultiCodeCouponModel coupon, java.lang.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 java.lang.String removeCodeSeparators(java.lang.String codeWithOutPrefix, MultiCodeCouponModel coupon)
removes the code separator from the givencodeWithoutPrefix
. Note: Expects the given code to be without its prefix.- Throws:
java.lang.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(java.lang.String globalCharacterSet)
validates the coupon alphabet length and returns it
-
getAndValidateGlobalCharacterSet
protected java.lang.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 java.lang.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 java.lang.String getCodeSeparatorPattern()
-
setCodeSeparatorPattern
public void setCodeSeparatorPattern(java.lang.String codeSeparatorPattern)
-
getCouponCodesGenerator
protected CouponCodesGenerator getCouponCodesGenerator()
-
setCouponCodesGenerator
public void setCouponCodesGenerator(CouponCodesGenerator couponCodesGenerator)
-
getBatchSize
protected java.lang.Integer getBatchSize()
-
getKeyGenerator
protected KeyGenerator getKeyGenerator()
-
setKeyGenerator
public void setKeyGenerator(KeyGenerator keyGenerator)
-
-