com.ibm.commerce.marketing.promotion.runtime

Class PromotionContext

  • java.lang.Object
    • com.ibm.commerce.marketing.promotion.runtime.PromotionContext
  • All Implemented Interfaces:
    java.lang.Cloneable


    public class PromotionContext
    extends java.lang.Object
    implements java.lang.Cloneable
    The class contains the current state of promotion engine invocation and its control information which decides what the promotion engine should do and how to do it. This is a transient object that only exists when the promotion engine is called to evaluate whether promotions are applicable to an order. It captures the state of the promotion engine during the process.
    • Field Detail

      • COPYRIGHT

        public static final java.lang.String COPYRIGHT
        IBM Copyright
        See Also:
        Constant Field Values
    • Constructor Detail

      • PromotionContext

        public PromotionContext(PromotionEngine aEngine,
                                PromotionExecutionAgenda aAgenda,
                                PromotionArgument aArgument)
        Constructor
        Parameters:
        aEngine - promotion engine in which the invocation is being made.
        aAgenda - PromotionExecutionAgenda for this invocation
        aArgument - PromotionArgument for this invocation in/out parameter
    • Method Detail

      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException
        See Also:
        Object.clone()
      • hasNextPromotion

        public boolean hasNextPromotion()
        Returns true if there are more promotions to be evaluated in the promotion evaluation sequence
        Returns:
        true if more promotions need to be evaluated, false otherwise.
      • getPromotionCurrentlyUnderEvaluation

        public Promotion getPromotionCurrentlyUnderEvaluation()
        Returns the current promotion under evaluation
        Returns:
        the current promotion under evaluation
      • nextPromotion

        public Promotion nextPromotion()
        Returns next promotion in the promotion evaluation sequence. Clears the current result as a side effect
        Returns:
        next promotion in the promotion evaluation sequence.
      • markPromotionAsNotApplicable

        public void markPromotionAsNotApplicable(Promotion promotion)
        Temporarily marks a promotion as no longer applicable to the current order. Note that this change can be reversed when the PromotionControlBlock is rolled back. Changes will be made permanent when PCB is committed.
        Parameters:
        promotion - to be marked as no longer applicable
      • getApplicablePolicies

        public java.util.Enumeration getApplicablePolicies(Promotion promotion)
        Returns a list of promotion policies applicable to a promotion according to the PromotionExecutionAgenda.
        Parameters:
        promotion - the promotion
        Returns:
        an enumeration of policies
      • getGovernedPromotions

        public java.util.Enumeration getGovernedPromotions(PromotionPolicy policy)
        Returns a list of promotions governed by a promotion policy according to the PromotionExecutionAgenda.
        Parameters:
        policy - The policy
        Returns:
        An enumeration of promotions governed by this policy.
      • getLineItemsCanBeTargetedByCurrentPromotion

        public LineItemSet getLineItemsCanBeTargetedByCurrentPromotion()
        Returns a LineItemSet of associated order items that can be targeted by the current promotion.
        Returns:
        a LineItemSet of associated order items that can be targeted by the current promotion.
      • getLineItemsCanBeAffectedByCurrentPromotion

        public LineItemSet getLineItemsCanBeAffectedByCurrentPromotion()
        Returns a LineItemSet of associated order items that can be affected by the current promotion.
        Returns:
        a LineItemSet of associated order items that can be affected by the current promotion.
      • getLineItemsCanNotBeTargetedByCurrentPromotion

        public LineItemSet getLineItemsCanNotBeTargetedByCurrentPromotion()
        Returns a LineItemSet of associated order items that can no longer be targeted by the current promotion.
        Returns:
        a LineItemSet of associated order items that can no longer be targeted by the current promotion.
      • getLineItemsCanNotBeAffectedByCurrentPromotion

        public LineItemSet getLineItemsCanNotBeAffectedByCurrentPromotion()
        Returns a LineItemSet of associated order items that can no longer be affected by the current promotion.
        Returns:
        a LineItemSet of associated order items that can no longer be affected by the current promotion.
      • markLineItemsNotToBeTargetedByPromotionAtGlobalLevel

        public void markLineItemsNotToBeTargetedByPromotionAtGlobalLevel(LineItemSet items)
        Temporarily marks a set of order items as no longer targetable by any promotion. Note that this change can be reversed when the PromotionControlBlock is rolled back. Changes will be made permanent when PCB is committed.
        Parameters:
        items - that will be marked as no longer targetable by any promotion
      • markLineItemsNotToBeAffectedByPromotionAtGlobalLevel

        public void markLineItemsNotToBeAffectedByPromotionAtGlobalLevel(LineItemSet items)
        Temporarily marks a set of order items as can no longer be affected by any promotion. Note that this change can be reversed when the PromotionControlBlock is rolled back. Changes will be made permanent when PCB is committed.
        Parameters:
        items - that will be marked as no longer targetable by any promotion
      • markLineItemsNotToBeTargetedByPromotionAtCurrentGroupLevel

        public void markLineItemsNotToBeTargetedByPromotionAtCurrentGroupLevel(LineItemSet items)
        Temporarily marks line items to be not targetable by promotions in the same group as the promotion currently under evaluation.
        Parameters:
        items - items to be marked as non-targetable
      • markLineItemsNotToBeAffectedByPromotionAtCurrentGroupLevel

        public void markLineItemsNotToBeAffectedByPromotionAtCurrentGroupLevel(LineItemSet items)
        Temporarily marks line items to be ineligible to receive any adjustments. This is because the application of any other promotions in the same group is currently under evaluation.
        Parameters:
        items - items to be marked as ineligible to be affected.
      • getEngine

        public PromotionEngine getEngine()
        Returns the engine.
        Returns:
        PromotionEngine
      • isCodeEnteredFor

        public boolean isCodeEnteredFor(Promotion promotion)
        Checks if promotion code is entered for a promotion or not
        Parameters:
        promotion - the promotion
        Returns:
        true, if a correct code is entered for this promotion, false otherwise.
      • getCodeFor

        public java.lang.String getCodeFor(Promotion promotion)
        Returns the first code entered for a promotion
        Parameters:
        promotion - the promotion
        Returns:
        the first promotion code entered for this promotion, null if no code is entered for this promotion
      • getCodesFor

        public java.util.List getCodesFor(Promotion promotion)
        Returns a list of all promotion codes entered for a promotion
        Parameters:
        promotion - the promotion
        Returns:
        a list of promotion codes entered for this promotion, null if no codes were entered for this promotion.
      • getAppliedCodesFor

        public java.util.List getAppliedCodesFor(Promotion promotion)
        Returns a subset of promotion codes entered for a promotion. The number of codes returned is based on the CodeCouponPerOrderLimit set for the Promotion. If the limit is smaller than the number of promotion codes entered, then the codes entered that are within the limit are returned. If the number of codes entered is less than the limit, then all promotion codes entered are returned.
        Parameters:
        promotion - the promotion
        Returns:
        a list of promotion codes entered for this promotion, null if no codes were entered for this promotion.
      • getCurrentResults

        public PromotionExecutionRecord[] getCurrentResults()
        Returns the currentResults.
        Returns:
        an array of PromotionExecutionRecord each representing one promotion applied once.
      • setCurrentResults

        public void setCurrentResults(PromotionExecutionRecord[] aCurrentResults)
        Sets the currentResult.
        Parameters:
        aCurrentResults - The currentResult to set
      • getArgument

        public PromotionArgument getArgument()
        Returns the argument.
        Returns:
        PromotionArgument
      • setArgument

        public void setArgument(PromotionArgument aArgument)
        Sets the argument.
        Parameters:
        aArgument - The argument to set
      • addPromotionExecutionRecordToArgument

        public void addPromotionExecutionRecordToArgument(PromotionExecutionRecord record)
        Appends a promotion execution record to PromotionArgument. Only qualified promotion execution records can be added to promotion argument.
        Parameters:
        record - The promotion execution record to be appended
      • addPromotionExecutionRecord

        public void addPromotionExecutionRecord(PromotionExecutionRecord record)
        Append a promotion execution record to the list of current promotion execution records. Any promotion execution record on the current promotion record will have to pass all promotion policies before it is added to the promotion argument. That is, actually applicable to the current order.
        Parameters:
        record - the promotion execution to be appended to the list of current results.
      • getCodeToPromotionMap

        public java.util.Hashtable getCodeToPromotionMap()
        Returns the codeToPromotionMap.
        Returns:
        the codeToPromotionMap Hashtable
      • getFullCodeToPromotionMap

        public java.util.Hashtable getFullCodeToPromotionMap()
        Returns the codeToPromotionMap containing the promotion key as the key and a list of codes as the value.
        Returns:
        the codeToPromotionMap Hashtable
      • getSequence

        public java.util.Vector getSequence()
        Returns the sequence.
        Returns:
        the sequence Vector
      • setCodeToPromotionMap

        public void setCodeToPromotionMap(java.util.Hashtable aCodeToPromotionMap)
        Sets the codeToPromotionMap.
        Parameters:
        aCodeToPromotionMap - The codeToPromotionMap to set
      • setFullCodeToPromotionMap

        public void setFullCodeToPromotionMap(java.util.Hashtable aCodeToPromotionMap)
        Sets the full codeToPromotionMap where the key is the promotion key, and the value is a list of promotion codes for that promotion.
        Parameters:
        aCodeToPromotionMap -
      • setSequence

        public void setSequence(java.util.Vector aSequence)
        Sets the sequence.
        Parameters:
        aSequence - The sequence to set
      • setMask

        public void setMask(boolean[] aMask)
        Sets the mask.
        Parameters:
        aMask - The mask to set
      • getRedemptionCountForThisPromotionInCurrentOrder

        public int getRedemptionCountForThisPromotionInCurrentOrder(Promotion promotion)
        Returns the number of times a promotion has been redeemed in this order
        Parameters:
        promotion - the promotion
        Returns:
        the number of times the promotion has been redeemed in this order
      • getRedemptionCountForThisPromotionForCurrentShopper

        public int getRedemptionCountForThisPromotionForCurrentShopper(Promotion promotion)
        Returns the number of times a promotion has been redeemed by a shopper
        Parameters:
        promotion - the promotion
        Returns:
        the number of times this promotion has been redeemed by the shopper who owns the current order.
      • getRedemptionCountForThisPromotion

        public int getRedemptionCountForThisPromotion(Promotion promotion)
        Returns the number of times a promotion has been redeemed
        Parameters:
        promotion - the promotion
        Returns:
        the number of times it has been redeemed.
      • getGroups

        public com.ibm.commerce.marketing.promotion.group.PromotionGroup[] getGroups()
        Returns all the promotion groups be evaluated in this invocation
        Returns:
        all the promotion groups be evaluated in this invocation
      • commitPCB

        public void commitPCB(PromotionContext context)
        Commits all the changes in the current promotion execution control block.
        Parameters:
        context - the context for this invocation
      • rollbackPCB

        public void rollbackPCB(PromotionContext context)
        Rolls back all the changes in the current promotion execution control block.
        Parameters:
        context - the context for this invocation
      • initPCB

        public void initPCB(PromotionContext context)
        Initializes the promotion execution control block
        Parameters:
        context - the context for this invocation
      • getCouponToPromotionMap

        public java.util.Hashtable getCouponToPromotionMap()
        Returns the map between promotions and coupons
        Returns:
        a hashtable where promotions are used as keys and the coupons this shopper has applied towards this order are values.
      • setCouponToPromotionMap

        public void setCouponToPromotionMap(java.util.Hashtable hashtable)
        Sets the promotion to coupon map.
        Parameters:
        hashtable - map of promotion and coupons
      • getCouponFor

        public com.ibm.commerce.marketing.promotion.coupon.Coupon[] getCouponFor(Promotion promotion)
        Returns an array of coupons entered for a promotion
        Parameters:
        promotion - the promotion
        Returns:
        an array of coupons entered for a promotion
      • isCouponAddedFor

        public boolean isCouponAddedFor(Promotion promotion)
        Checks to see if coupon has been added for a promotion
        Parameters:
        promotion - the promotion
        Returns:
        true if coupon for this promotion has been applied to order, false otherwise
      • allocateCoupon

        public com.ibm.commerce.marketing.promotion.coupon.Coupon allocateCoupon(Promotion promotion)
        Allocates an available coupon for a promotion. If the flag for AllowMultipleCouponRedemptions was turned on, then it allocates an unused coupon from the promotion If the flag was turned off, then it allocates the first coupon from the promotion
        Parameters:
        promotion - the promotion
        Returns:
        an available coupon, null if no coupon is available
      • useCoupon

        public void useCoupon(com.ibm.commerce.marketing.promotion.coupon.Coupon coupon)
        This method adds a coupon to the list of usedCoupons to track the coupons used in this order
        Parameters:
        coupon - coupon to add to the list
      • releaseCoupon

        public void releaseCoupon(com.ibm.commerce.marketing.promotion.coupon.Coupon coupon)
        Releases a coupon to the pool of available coupons
        Parameters:
        coupon - the coupon to be released
      • getOrderQualifyingTotal

        public java.math.BigDecimal getOrderQualifyingTotal(int types)
        Returns the current order qualifying total for a combination of any of the four values: price, shipping, shipping tax, and tax. It calls the getOrderQualifyingTotal(int) method of OrderQualifyingTotal class.
        Parameters:
        types - the bit pattern of the types of monetary values that need to be returned
        Returns:
        order qualifying total
      • getRunningTotalFor

        public java.math.BigDecimal getRunningTotalFor(AssociatedOrderItem anItem,
                                                       int type)
        Returns the running total for an order item or a portion of it as identified by the AssociatedOrderItem parameter. The running total contains subTotal, shipping charge, shipping tax or tax.
        Parameters:
        anItem - the AssociatedOrderItem
        type - the type of running total to return
        Returns:
        the running total
      • getRunningTotalFor

        public java.math.BigDecimal getRunningTotalFor(AssociatedOrderItem[] items,
                                                       int type)
        Returns the running total for an array of order items or portions of them as identified by the AssociatedOrderItem array parameter. The running total contains subTotal, shipping charge, shipping tax or tax.
        Parameters:
        items - the array of AssociatedOrderItems
        type - the type of running total to return
        Returns:
        the running total
      • getRunningTotalFor

        public java.math.BigDecimal getRunningTotalFor(LineItemSet set,
                                                       int type)
        Returns the running total for everything in a LineItemSet. The running total contains subTotal, shipping charge, shipping tax or tax. If the type is 1 then it returns SUBTOTAL If the type is 2 then it returns SHIPPING If the type is 4 then it returns SHIPPING_TAX If the type is 8 then it returns TAX
        Parameters:
        set - the LineItemSet
        type - the type of running total to return
        Returns:
        the running total
      • getOrderRunningTotal

        public java.math.BigDecimal getOrderRunningTotal(int type)
        Returns the running total for the order with which this OrderRunningTotalController was initialized. The running total contains subTotal, shipping charge, shipping tax or tax.
        Parameters:
        type - the type of running total to return
        Returns:
        the running total
      • getRunningTotalFor

        public java.math.BigDecimal getRunningTotalFor(OrderItem item,
                                                       int type)
        Returns the running total for an order item. The running total contains subTotal, shipping charge, shipping tax or tax.
        Parameters:
        item - order item
        type - the type of running total to return
        Returns:
        the running total
      • tentativelyApplyMonetaryAdjustment

        public int tentativelyApplyMonetaryAdjustment(PromotionExecutionRecord record)
        Calculates monetary adjustments as a result of applying a promotion, updates the running total accordingly.
        Parameters:
        record - the PromotionExecutionRecord, which represents one promotion that applied once.
        Returns:
        0, if no adjustment has been applied. 1, if some monetary adjustments have been applied, no other types of adjustment is present. 2, if no monetary adjustments are applied, but some other adjustments are present. 3, if some monetary adjustment have been applied, and other adjustments are present.
      • getOrder

        public Order getOrder()
        Returns the order to which promotions will be applied
        Returns:
        the order to which promotions will be applied
      • getOrderAsALineItemSet

        public LineItemSet getOrderAsALineItemSet()
        Returns the original order as an LineItemSet
        Returns:
        the original order as an LineItemSet
      • getCurrencyConverter

        public PriceConverter getCurrencyConverter()
        Returns a currency converter
        Returns:
        a currency converter
      • getRounding

        public Rounding getRounding()
        Returns a rounding
        Returns:
        a rounding
      • getStoreKey

        public StoreKey getStoreKey()
        Returns the key of the store
        Returns:
        key of the store
      • setOrder

        public void setOrder(Order aOrder)
        Sets the order to which promotions will be applied
        Parameters:
        aOrder - to set the order to which promotions will be applied
      • setCurrencyConverter

        public void setCurrencyConverter(PriceConverter converter)
        Sets the currency converter
        Parameters:
        converter - to set the current converter
      • setRounding

        public void setRounding(Rounding newRounding)
        Sets the currency rounding tool
        Parameters:
        newRounding - the customized rounding tool.
      • setStoreKey

        public void setStoreKey(StoreKey key)
        Sets the store key
        Parameters:
        key - the store key
      • getOrderCurrency

        public java.lang.String getOrderCurrency()
        Returns the currency of the order
        Returns:
        currency of the order
      • getRunningTotalObject

        public OrderRunningTotal getRunningTotalObject()
        Returns the running total object on the context object
        Returns:
        the running total object
      • getQualifyingTotalObject

        public OrderQualifyingTotal getQualifyingTotalObject()
        Returns the qualifying total object on the context object
        Returns:
        the qualifying total object
      • isPricePresent

        public boolean isPricePresent()
        Indicates if price is calculated when this template is invoked.
        Returns:
        true if price is already calculated, false otherwise.
      • isShippingChargePresent

        public boolean isShippingChargePresent()
        Indicates if shipping charge is calculated when this template is invoked.
        Returns:
        true if shipping charge is already calculated, false otherwise.
      • isShippingTaxPresent

        public boolean isShippingTaxPresent()
        Indicates if shipping tax is calculated when this template is invoked.
        Returns:
        true if shipping tax is already calculated, false otherwise.
      • isTaxPresent

        public boolean isTaxPresent()
        Indicates if tax is calculated when this template is invoked.
        Returns:
        True if tax is already calculated, false otherwise.
      • listAllPromotions

        public java.util.Enumeration listAllPromotions()
        Lists all promotions in the execution agenda
        Returns:
        An enumeration of all promotions to be evaluated
      • listAllPromotionPolicies

        public java.util.Enumeration listAllPromotionPolicies()
        Lists all promotion policies in the execution agenda
        Returns:
        An enumeration of all promotion policies
      • appendPromotionErrorReport

        public void appendPromotionErrorReport(PromotionErrorReport report)
        Appends a promotion error report to a list of error reports
        Parameters:
        report - the error report to be added
      • getPromotionErrorReports

        public PromotionErrorReport[] getPromotionErrorReports()
        Returns all the promotion error reports accumulated so far.
        Returns:
        an array of promotion error reports
      • addProtectedContextAttribute

        public ProtectedContextAttribute addProtectedContextAttribute(java.lang.String name,
                                                                      ProtectedContextAttribute attr)
        Adds a named protected context attribute. A protected context attribute is a named attribute in the context object. This attribute is subject to change as a promotion is applied to the current order. The changes need to be rolled back if later on the applied promotion is determined to be in violation with any promotion policies and therefore eliminated. An un-protected context attribute is a named attribute of the context object that any changes made to it is final and no rollback is possible.
        Parameters:
        name - The name of the protected context attribute.
        attr - The attribute object.
        Returns:
        Previous attribute by that same name, null if no previous object exists.
      • getProtectedContextAttribute

        public ProtectedContextAttribute getProtectedContextAttribute(java.lang.String name)
        Returns a protected context attribute object.
        Parameters:
        name - The name of the protected context attribute object.
        Returns:
        The object itself, null if no protected context attribute by the name exists.
      • addUnprotectedContextAttribute

        public java.lang.Object addUnprotectedContextAttribute(java.lang.String name,
                                                               java.lang.Object attr)
        Adds a named un-protected context attribute.
        Parameters:
        name - of the un-protected context attribute
        attr - the attribute object
        Returns:
        previous attribute by that same name, null if no previous object exists
      • getUnprotectedContextAttribute

        public java.lang.Object getUnprotectedContextAttribute(java.lang.String name)
        Returns an un-protected context attribute object.
        Parameters:
        name - the name of the un-protected context attribute object
        Returns:
        the object itself, null if no un-protected context attribute by the name exists
      • reduceOrderQualifyingTotal

        public void reduceOrderQualifyingTotal(java.math.BigDecimal amount,
                                               int types)
        Reduces the amount and type of order qualifying total
        Parameters:
        amount - the amount to be reduced
        types - the bit pattern of the monetary values to be reduced
      • setRewardOptions

        public void setRewardOptions(java.util.Map aMap)
        Sets the RewardOption map object.
        Parameters:
        aMap - The map object.
      • resetRewardOptions

        public void resetRewardOptions()
        Reset RewardOption map object to its original state.
      • getRewardOptions

        public java.util.Map getRewardOptions()
        Gets the RewardOption map object.
        Returns:
        The RewardOption map object.
      • getRewardOptionForPromotion

        public java.util.List getRewardOptionForPromotion(PromotionKey aPromotionKey)
        Gets list of RewardOption object for a specific promotion.
        Parameters:
        aPromotionKey - The promotion key.
        Returns:
        List of RewardOption object
      • addRewardOptionForPromotion

        public void addRewardOptionForPromotion(PromotionKey aPromotionKey,
                                                RewardOption aRewardOption)
        Adds a RewardOption for a specific promotion.
        Parameters:
        aPromotionKey - The promotion key.
        aRewardOption - The RewardOption object to add.
      • getAgenda

        public PromotionExecutionAgenda getAgenda()
        Gets the PromotionExecutionAgenda for the PromotionContext.
        Returns:
        The PromotionExecutionAgenda object.
      • setAgenda

        public void setAgenda(PromotionExecutionAgenda aAgenda)
        Sets the PromotionExecutionAgenda for the PromotionContext.
        Parameters:
        aAgenda - The PromotionExecutionAgenda to set.
      • getCurrentPromotionExecutionRecord

        public PromotionExecutionRecord getCurrentPromotionExecutionRecord()
        Gets the current PromotionExecutionRecord object.
        Returns:
        The PromotionExecutionRecord object.
      • setCurrentPromotionExecutionRecord

        public void setCurrentPromotionExecutionRecord(PromotionExecutionRecord aPromotionExecutionRecord)
        Sets the PromotionExecutionRecord object.
        Parameters:
        aPromotionExecutionRecord - The PromotionExecutionRecord object to set.
      • isUnderSimulatedPromotionEvaluationMode

        public boolean isUnderSimulatedPromotionEvaluationMode()
        Return true or false that indicates the promotion engine is evaluating under simulated mode.
        Returns:
        true or false.
      • getSimulatedPromotionEvaluationConfigurations

        public java.util.Map<java.lang.String,java.lang.String> getSimulatedPromotionEvaluationConfigurations()
        Gets the Map object that contains the optional evaluation configurations as name value pairs.
        Returns:
        The Map object.
      • setAllAttributeNames

        public void setAllAttributeNames(java.util.List<java.lang.String> allAttributeNames)
        sets all attribute names in cache for this context
        Parameters:
        allAttributeNames - a list of all attribute names to be stored
      • getAllAttributeNames

        public java.util.List getAllAttributeNames()
        gets all the attribute names stored in cache in the promotion context specified
        Returns:
        a list of attribute names for this context
      • clearAttributeNamesInCache

        public void clearAttributeNamesInCache()
        This method clears the transaction cache that stores all attribute names for all PromotionContext objects