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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidprotected MediaModelcreateMedia(MultiCodeCouponModel coupon, int quantity) extractClearTextAndCipherText(MultiCodeCouponModel coupon, String couponCode) returns a string pair containing the clear text and the cipher text part of the given coupon code.extractCouponPrefix(String couponCode) tries to find the prefix substring of the given coupon code.generates the alphabet used for a coupon.Generates a code for the given multi code coupon.generateCouponCodes(MultiCodeCouponModel multiCodeCoupon, int quantity) Generates codes for the given multi-code coupon.generates a base64 encoded String representing the signature of the multi code coupon.protected Optional<MediaModel>generateMediaForMultiCodeCoupon(MultiCodeCouponModel multiCodeCoupon, int quantity) protected Stringvalidates the configured algorithm used for the cipher part of the coupon codeprotected intgetAndValidateAlphabetLength(String globalCharacterSet) validates the coupon alphabet length and returns itprotected Stringvalidates that the global character set doesn't contain the defined code separators and that all characters are single-byte characters.protected Integerprotected intreturns the amount of cipher-text characters to be created for the given coupon.protected CouponCodeCipherTextGenerationStrategyprotected intreturns the amount of clear-text characters to be created for the given coupon.protected CouponCodeClearTextGenerationStrategyprotected Stringprotected ConfigurationServiceprotected CouponCodesGeneratorprotected KeyGeneratorprotected intgetLengthFor(MultiCodeCouponModel coupon, boolean clearText) protected MediaFolderModelprotected MediaServiceprotected ModelServicebooleanisValidCodeSeparator(String codeSeparator) verifies if the given string is a valid code separatorprotected StringremoveCodeSeparators(String codeWithOutPrefix, MultiCodeCouponModel coupon) removes the code separator from the givencodeWithoutPrefix.voidsetCipherTextStrategy(CouponCodeCipherTextGenerationStrategy cipherTextStrategy) voidsetClearTextStrategy(CouponCodeClearTextGenerationStrategy clearTextStrategy) voidsetCodeSeparatorPattern(String codeSeparatorPattern) voidsetConfigurationService(ConfigurationService configurationService) voidsetCouponCodesGenerator(CouponCodesGenerator couponCodesGenerator) voidsetKeyGenerator(KeyGenerator keyGenerator) voidsetMediaService(MediaService mediaService) voidsetModelService(ModelService modelService) protected booleanvalidateCouponFormat(MultiCodeCouponModel coupon, String couponCode) validates the given coupon code with regards to its format (i.e.protected booleanverifyCipherText(MultiCodeCouponModel coupon, String couponCode) booleanverifyCouponCode(MultiCodeCouponModel coupon, String couponCode) verifies if the givencouponCodeis valid for the givencoupon.protected booleanverifyUsedCouponCodeNumber(MultiCodeCouponModel coupon, org.apache.commons.lang3.tuple.Pair<String, String> pair)
-
Field Details
-
UNEXPECTED_ERROR_MSG
- See Also:
-
-
Constructor Details
-
DefaultCouponCodeGenerationService
public DefaultCouponCodeGenerationService()
-
-
Method Details
-
afterPropertiesSet
public void afterPropertiesSet()- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-
generateCouponSignature
Description copied from interface:CouponCodeGenerationServicegenerates 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:
generateCouponSignaturein interfaceCouponCodeGenerationService- Returns:
- base64 encoded String representing the signature of the multi code coupon
-
generateCouponAlphabet
Description copied from interface:CouponCodeGenerationServicegenerates the alphabet used for a coupon.- Specified by:
generateCouponAlphabetin interfaceCouponCodeGenerationService- Returns:
- alphabet string used for a coupon
-
generateCouponCode
Description copied from interface:CouponCodeGenerationServiceGenerates a code for the given multi code coupon. Note: This method doesn't save the given coupon, but modifies it (by incrementing thecouponCodeNumberattribute)- Specified by:
generateCouponCodein interfaceCouponCodeGenerationService- Parameters:
coupon- multi code coupon- Returns:
- generated coupon code
- Throws:
CouponCodeGenerationException
-
generateCouponCodes
Description copied from interface:CouponCodeGenerationServiceGenerates codes for the given multi-code coupon. Returns a MediaModel containing a csv file with the generated codes. Note that the returned file containsquantitycoupon 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:
generateCouponCodesin 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 Optional<MediaModel> generateMediaForMultiCodeCoupon(MultiCodeCouponModel multiCodeCoupon, int quantity) -
createMedia
-
getMediaFolderForCouponCodes
-
extractCouponPrefix
Description copied from interface:CouponCodeGenerationServicetries to find the prefix substring of the given coupon code.- Specified by:
extractCouponPrefixin 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
Description copied from interface:CouponCodeGenerationServiceverifies if the givencouponCodeis valid for the givencoupon.- Specified by:
verifyCouponCodein interfaceCouponCodeGenerationService- Parameters:
coupon- Coupon against which check will be firedcouponCode- Coupon code to verify- Returns:
- true if the couponCode is valid, otherwise false
-
validateCouponFormat
validates the given coupon code with regards to its format (i.e. correct prefix, separators, coupon parts). -
verifyCipherText
- 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
Description copied from interface:CouponCodeGenerationServiceverifies if the given string is a valid code separator- Specified by:
isValidCodeSeparatorin interfaceCouponCodeGenerationService- 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
removes the code separator from the givencodeWithoutPrefix. 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
returns the amount of cipher-text characters to be created for the given coupon. -
getClearTextLength
returns the amount of clear-text characters to be created for the given coupon. -
getLengthFor
-
getAndValidateAlphabetLength
validates the coupon alphabet length and returns it -
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
validates the configured algorithm used for the cipher part of the coupon code -
getConfigurationService
-
setConfigurationService
-
getClearTextStrategy
-
setClearTextStrategy
-
getCipherTextStrategy
-
setCipherTextStrategy
-
getModelService
-
setModelService
-
getMediaService
-
setMediaService
-
getCodeSeparatorPattern
-
setCodeSeparatorPattern
-
getCouponCodesGenerator
-
setCouponCodesGenerator
-
getBatchSize
-
getKeyGenerator
-
setKeyGenerator
-