com.ibm.commerce.marketing.promotion.code
Class DefaultGenericPromotionCodeManager
- java.lang.Object
-
- com.ibm.commerce.marketing.promotion.code.DefaultGenericPromotionCodeManager
-
- All Implemented Interfaces:
- GenericPromotionCodeManager, XMLizable, java.io.Serializable
public class DefaultGenericPromotionCodeManager extends java.lang.Object implements GenericPromotionCodeManager
This class which implements theGenericPromotionCodeManager
interface provides default implementation of the promotion code manager.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.String
COPYRIGHT
IBM Copyright-
Fields inherited from interface com.ibm.commerce.marketing.promotion.code.GenericPromotionCodeManager
PROMO_CODE_IN_USE, PROMO_CODE_USED
-
-
Constructor Summary
Constructors Constructor and Description DefaultGenericPromotionCodeManager()
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method and Description void
addCodeForOrder(java.lang.String code, OrderKey okey)
Add a promotion code to an ordervoid
addCodeForOrder(java.lang.String code, OrderKey okey, java.util.Date date)
Add a promotion code to an orderstatic void
clearErrorMessageCodeCache()
A static method to clear error message code cache It is used with Promotion Registry flush to ensure no message stay in the cache for too longstatic void
clearErrorMessageTextCache()
A static method to clear error message text cache It is used with Promotion Registry flush to ensure no message stay in the cache for too longvoid
fromXML(org.w3c.dom.Node node)
Transforms the XML node into its corresponding real Object.java.lang.String
getAllMessagesInCache()
A public method to retrieve all the messages currently stored in the cachestatic DefaultGenericPromotionCodeManager
getInstance()
Singleton get instance methodGenericPromotionCodeResolver
getPromotionCodeResolver()
Returns the promotion code resolver used by this promotion code manager.static java.lang.Boolean
isPromotionCodesErrorsLoggingEnabled()
A method to check config flag (enableInvalidPromotionCodesLogging) for the value of whether logging promotion codes errors or not.java.lang.String[]
listCodeForOrder(OrderKey okey)
List all the codes that are used in an ordervoid
logErrorInfoForInvalidCodes(java.lang.String pid, java.lang.String code, java.lang.String msgCode, java.lang.Number numStoreId)
This method logs the promotion code error information into the log under two conditions, either a specific code has been entered incorrectly X times, or if the overall hashmap cache limit Y has been reached.void
printAllErrorMessagesTolog()
A public method to print all current error messages stored in the cache to log However, this does not flush the cache, only prints the current content stored in cachevoid
removeAllCodesForOrder(OrderKey okey)
Removes all promotion codes entered for an ordervoid
removeCodeForOrder(java.lang.String code, OrderKey okey)
Removes a promotion code entered for an ordervoid
resourceBundleLookUp()
This method looks up the values in resource bundle and set the parameters in the class instance and cache to their appropriate translation values.void
setPromotionCodeResolver(GenericPromotionCodeResolver resolver)
This method is used to set the PromotionCodeResolver object.java.lang.String
toXML()
Converts the object into its corresponding XML format representation.java.lang.String
translateKeyToMessage(java.lang.String[] keyValues)
This method looks up the Error Message Code stored in keyValues[2] (which contains either typeInvalid, typeRedemp, typeRedempShopper or typeInactive) and replaces this code with the translated Error Message Code Text message that has been stored in the errorMessageTextCache.java.lang.String
translateKeyToMessage(java.lang.String key, int value)
Deprecated.Use translateKeyToMessage(String[] keyValues) instead.PromotionErrorReport
validatePromotionCode(java.lang.String code, CustomerKey ukey, StoreKey storeKey)
Validates a promotion code.PromotionErrorReport
validatePromotionCode(java.lang.String code, CustomerKey ukey, StoreKey storeKey, java.util.Date date)
Validates a promotion code.
-
-
-
Field Detail
-
COPYRIGHT
public static final java.lang.String COPYRIGHT
IBM Copyright- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultGenericPromotionCodeManager
public DefaultGenericPromotionCodeManager()
Constructor
-
-
Method Detail
-
getInstance
public static DefaultGenericPromotionCodeManager getInstance()
Singleton get instance method- Returns:
- A DefaultGenericPromotionCodeManager instance
-
addCodeForOrder
public void addCodeForOrder(java.lang.String code, OrderKey okey) throws PromotionApplicationException
Add a promotion code to an order- Specified by:
addCodeForOrder
in interfaceGenericPromotionCodeManager
- Parameters:
code
- The promotion code to add to the order.okey
- The OrderKey object.- Throws:
PromotionApplicationException
- is thrown when system enters a problem trying to add a promotion code to an order.
-
addCodeForOrder
public void addCodeForOrder(java.lang.String code, OrderKey okey, java.util.Date date) throws PromotionApplicationException
Add a promotion code to an order- Specified by:
addCodeForOrder
in interfaceGenericPromotionCodeManager
- Parameters:
code
- The promotion code to add to the order.okey
- The OrderKey object.date
- The date on which the code is entered- Throws:
PromotionApplicationException
- is thrown when system enters a problem trying to add a promotion code to an order.
-
listCodeForOrder
public java.lang.String[] listCodeForOrder(OrderKey okey)
List all the codes that are used in an order- Specified by:
listCodeForOrder
in interfaceGenericPromotionCodeManager
- Parameters:
okey
- The OrderKey object.- Returns:
- all the codes that are used in an order
-
removeCodeForOrder
public void removeCodeForOrder(java.lang.String code, OrderKey okey) throws PromotionApplicationException
Removes a promotion code entered for an order- Specified by:
removeCodeForOrder
in interfaceGenericPromotionCodeManager
- Parameters:
code
- The promotion codeokey
- The OrderKey- Throws:
PromotionApplicationException
- is thrown when system enters a problem trying to remove a promotion code from an order.
-
removeAllCodesForOrder
public void removeAllCodesForOrder(OrderKey okey) throws PromotionApplicationException
Removes all promotion codes entered for an order- Specified by:
removeAllCodesForOrder
in interfaceGenericPromotionCodeManager
- Parameters:
okey
- The OrderKey- Throws:
PromotionApplicationException
- is thrown when system enters a problem trying to remove all promotion codes from an order.
-
validatePromotionCode
public PromotionErrorReport validatePromotionCode(java.lang.String code, CustomerKey ukey, StoreKey storeKey) throws PromotionApplicationException
Validates a promotion code. Performs the following tasks:
1. Checks if the code is valid
2. Checks if the promotion identified by this code is active
3. Checks if the promotion identified by this code has reached the redemption limit both overall and for this user in particular.
Not checked are:
1. If the promotion identified by this code is applicable to the current order based on its content
2. If the promotion identified by this code will be eliminated as a result of policy violations.- Specified by:
validatePromotionCode
in interfaceGenericPromotionCodeManager
- Parameters:
code
- the codeukey
- key of the user who entered the promotion codestoreKey
- key of the store where the transaction happens- Returns:
- PromotionErrorReport that indicates any validation errors that might have arisen.
- Throws:
PromotionApplicationException
- if any of the 3 criteria is not satisfied.
-
validatePromotionCode
public PromotionErrorReport validatePromotionCode(java.lang.String code, CustomerKey ukey, StoreKey storeKey, java.util.Date date) throws PromotionApplicationException
Validates a promotion code. Performs the following tasks:
1. Checks if the code is valid
2. Checks if the promotion identified by this code is active or has reached redemption limit and suspended
3. Checks if the promotion identified by this code has reached the redemption limit both overall and for this user in particular.
Not checked are:
1. If the promotion identified by this code is applicable to the current order based on its content
2. If the promotion identified by this code will be eliminated as a result of policy violations.- Specified by:
validatePromotionCode
in interfaceGenericPromotionCodeManager
- Parameters:
code
- the codeukey
- key of the user who entered the promotion codestoreKey
- key of the store where the transaction happensdate
- the date on which the code is entered- Returns:
- PromotionErrorReport that indicates any validation errors that might have arisen.
- Throws:
PromotionApplicationException
- if any of the 3 criteria is not satisfied.
-
logErrorInfoForInvalidCodes
public void logErrorInfoForInvalidCodes(java.lang.String pid, java.lang.String code, java.lang.String msgCode, java.lang.Number numStoreId)
This method logs the promotion code error information into the log under two conditions, either a specific code has been entered incorrectly X times, or if the overall hashmap cache limit Y has been reached. Both X (invalidPromotionCodesCacheEntrySize) and Y (invalidPromotionCodesCacheSize) values, as well as the flag (EnableInvalidPromotionCodesLogging) to turn this functionality on are configurable through wc-admin-component.xml Sample log in trace: [1/22/15 17:41:12:081 EST] 0000003d DefaultGeneri Z Promotion_id: "10006201" Promotion code: "ntc2_6" Error Reason: "The overall redemption limit for the promotion is exceeded." Failed attempts: "5" StoreId: "10001".- Parameters:
pid
- promotion id usedcode
- promotion code usedmsgCode
- promotion message code usednumStoreId
- store id used
-
printAllErrorMessagesTolog
public void printAllErrorMessagesTolog()
A public method to print all current error messages stored in the cache to log However, this does not flush the cache, only prints the current content stored in cache
-
getAllMessagesInCache
public java.lang.String getAllMessagesInCache()
A public method to retrieve all the messages currently stored in the cache- Returns:
- A string that contains all the messages, formatted by one per line
-
translateKeyToMessage
public java.lang.String translateKeyToMessage(java.lang.String key, int value)
Deprecated. Use translateKeyToMessage(String[] keyValues) instead.This method translates the key into message through looking up the error code- Parameters:
key
- Contains promotion id, promotion code and error code, error code is used to look up the actual text of the errorvalue
- Number of times this error has happened in a given interval- Returns:
- The translated message text which consists of promotionId, promotion code used, error reason and number of times it has happened all in one string in the set language
-
translateKeyToMessage
public java.lang.String translateKeyToMessage(java.lang.String[] keyValues)
This method looks up the Error Message Code stored in keyValues[2] (which contains either typeInvalid, typeRedemp, typeRedempShopper or typeInactive) and replaces this code with the translated Error Message Code Text message that has been stored in the errorMessageTextCache. Then, it formats the message to be logged (messageToLog) by passing all the parameters in keyValues (promotion id, promotion code, and error message code text) as (params) and base message (reportBody).- Parameters:
keyValues
- Contains promotion id, promotion code, error code which is used to look up the actual text of the error, store id, and number of times it has been attempted- Returns:
- The translated message text which consists of promotionId, promotion code used, error reason and number of times it has happened all in one string in the set language
-
resourceBundleLookUp
public void resourceBundleLookUp()
This method looks up the values in resource bundle and set the parameters in the class instance and cache to their appropriate translation values. If look up in file fails, set default values in each message type and report
-
clearErrorMessageCodeCache
public static void clearErrorMessageCodeCache()
A static method to clear error message code cache It is used with Promotion Registry flush to ensure no message stay in the cache for too long
-
clearErrorMessageTextCache
public static void clearErrorMessageTextCache()
A static method to clear error message text cache It is used with Promotion Registry flush to ensure no message stay in the cache for too long
-
isPromotionCodesErrorsLoggingEnabled
public static java.lang.Boolean isPromotionCodesErrorsLoggingEnabled()
A method to check config flag (enableInvalidPromotionCodesLogging) for the value of whether logging promotion codes errors or not. If flag is set to true, it also sets the overall cache size and each single error size limit to print to log The flag is default to false.- Returns:
- value of the flag whether it is enabled for error logging
-
getPromotionCodeResolver
public GenericPromotionCodeResolver getPromotionCodeResolver()
Description copied from interface:GenericPromotionCodeManager
Returns the promotion code resolver used by this promotion code manager.- Specified by:
getPromotionCodeResolver
in interfaceGenericPromotionCodeManager
- Returns:
- a generic promotion code resolver this promotion code manager uses to resolve promotion codes
- See Also:
com.ibm.commerce.marketing.promotion.GenericPromotionCodeManager#getPromotionCodeResolver();
-
fromXML
public void fromXML(org.w3c.dom.Node node) throws DeXMLizationException
Description copied from interface:XMLizable
Transforms the XML node into its corresponding real Object.- Specified by:
fromXML
in interfaceXMLizable
- Parameters:
node
- The node that represents an XMLizable object- Throws:
DeXMLizationException
- when this process fails- See Also:
XMLizable.fromXML(Node)
-
toXML
public java.lang.String toXML() throws XMLizationException
Description copied from interface:XMLizable
Converts the object into its corresponding XML format representation.- Specified by:
toXML
in interfaceXMLizable
- Returns:
- The string format of the XML that represents this XMLizable object
- Throws:
XMLizationException
- when this process fails- See Also:
XMLizable.toXML()
-
setPromotionCodeResolver
public void setPromotionCodeResolver(GenericPromotionCodeResolver resolver)
This method is used to set the PromotionCodeResolver object.- Parameters:
resolver
- The PromotionCodeResolver to set
-
-