com.ibm.commerce.marketing.promotion.code

Class DefaultGenericPromotionCodeManager

  • java.lang.Object
    • com.ibm.commerce.marketing.promotion.code.DefaultGenericPromotionCodeManager
    • 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

      • listCodeForOrder

        public java.lang.String[] listCodeForOrder(OrderKey okey)
        List all the codes that are used in an order
        Specified by:
        listCodeForOrder in interface GenericPromotionCodeManager
        Parameters:
        okey - The OrderKey object.
        Returns:
        all the codes that are used in 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 interface GenericPromotionCodeManager
        Parameters:
        code - the code
        ukey - key of the user who entered the promotion code
        storeKey - 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 interface GenericPromotionCodeManager
        Parameters:
        code - the code
        ukey - key of the user who entered the promotion code
        storeKey - key of the store where the transaction happens
        date - 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 used
        code - promotion code used
        msgCode - promotion message code used
        numStoreId - 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 error
        value - 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
      • setPromotionCodeResolver

        public void setPromotionCodeResolver(GenericPromotionCodeResolver resolver)
        This method is used to set the PromotionCodeResolver object.
        Parameters:
        resolver - The PromotionCodeResolver to set