com.ibm.commerce.order.calculation
Class CalculationHelper

java.lang.Object
  |
  +--com.ibm.commerce.order.calculation.CalculationHelper

public class CalculationHelper
extends java.lang.Object

This class defines the helper methods used by the Calculation Framework.


Field Summary
static java.lang.String COPYRIGHT
           
 
Constructor Summary
protected CalculationHelper()
           
 
Method Summary
 void applyCalculationUsages(OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to apply all calculation usages enabled in the store.
 void applyCalculationUsages(OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, java.util.Set aEnabledUsageIds, java.util.Set aDisabledUsageIds, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to apply all calculation usages enabled in the store.
 int compare(java.lang.Comparable[] c1, java.lang.Comparable[] c2)
           
 int compare(java.lang.Comparable c1, java.lang.Comparable c2)
           
 boolean containsAny(java.lang.Object[] a1, java.lang.Object[] a2)
           
 java.math.BigDecimal convertMonetaryValue(java.math.BigDecimal adValue1, java.lang.String astrCurrency1, java.lang.String astrCurrency2, CommandContext commandContext)
          This method converts the monetary value from one currency to another using the forward conversion rate.
 java.math.BigDecimal convertMonetaryValueR(java.math.BigDecimal adValue1, java.lang.String astrCurrency1, java.lang.String astrCurrency2, CommandContext commandContext)
          This method converts the monetary value from one currency to another using the backward conversion rate.
 java.math.BigDecimal convertQuantityValue(java.math.BigDecimal adValue1, java.lang.String astrUnit1, java.lang.String astrUnit2)
          This method converts the quantity value from one unit to another.
 void correctZeroBoundaryCrossings(Item[] aItems, java.math.BigDecimal[] adAdjustments, java.lang.String astrCurrency, CommandContext commandContext)
          This method is called by DiscountCalculationCodeApply to correct discounts that cross the zero boundary.
protected  boolean correctZeroBoundaryCrossingsIteration(Item[] aItems, java.math.BigDecimal[] adAdjustments)
           
 java.math.BigDecimal[] destructiveAdd(java.math.BigDecimal[] adValues1, java.math.BigDecimal[] adValues2)
           
 java.math.BigDecimal divide(java.math.BigDecimal ad1, java.math.BigDecimal ad2)
          Returns ad1.divide(ad2, 20, BigDecimal.ROUND_HALF_UP).
 void finalizeCalculationUsages(OrderAccessBean aabOrder, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, CommandContext commandContext)
          This method is called by OrderProcess/ProcessOrder to apply all calculation usages enabled in the store.
 void finalizeCalculationUsages(OrderAccessBean aabOrder, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, java.util.Set aEnabledUsageIds, java.util.Set aDisabledUsageIds, CommandContext commandContext)
          This method is called by OrderProcess/ProcessOrder to apply all calculation usages enabled by the store.
 int findMax(java.math.BigDecimal[] e)
           
 int findMin(java.math.BigDecimal[] e)
           
 java.lang.Integer getCodeId(java.lang.Integer anRuleId)
           
static CalculationHelper getInstance()
          Returns an instance of this class.
 java.lang.Long[] getProductAndItemIds(java.lang.Long anCatalogEntryId)
          Returns the parent product of an item and the item itself.
 java.lang.Long[] getProductOrItemIds(java.lang.Long anCatalogEntryId)
          Returns the parent product of an item.
 java.math.BigDecimal getQuantity(java.lang.Long anCatalogEntryId, java.math.BigDecimal adNormalizedQuantity, java.lang.String astrUnit)
          Returns the quantity represented by the normalized quantity.
 java.math.BigDecimal getRoundingMultiple(java.lang.String astrCurrency, CommandContext commandContext)
           
 java.lang.Integer getStoreGroupId(java.lang.Integer anStoreId)
           
 java.math.BigDecimal getTaxableAdjustmentTotal(java.lang.Long anOrderItemId, java.lang.Integer anTaxCategoryId)
           
 java.lang.Integer[] getTaxCategoryIds(StoreAccessBean aabStore, java.lang.Integer anUsageId)
          Returns the tax categories of a particular calculation usage: Calculation Usage Tax Categories sales tax all sales tax categories shipping tax all shipping tax categories other null
 java.math.BigDecimal getWeight(java.lang.Long anCatalogEntryId, java.math.BigDecimal adNormalizedQuantity, java.lang.String astrUnit)
          Returns the weight represented by the normalized quantity.
 void initializeCalculationUsages(OrderAccessBean aabOrder, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to initialize all calculation usages enabled by the store.
 void initializeCalculationUsages(OrderAccessBean aabOrder, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, java.util.Set aEnabledUsageIds, java.util.Set aDisabledUsageIds, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to initialize all calculation usages enabled by the store.
 boolean isCurrentUserInMemberGroup(java.lang.Long anMemberGroupId, CommandContext commandContext)
           
 boolean isEffective(CalculationCodeAccessBean aabCode, java.sql.Timestamp aTimestamp)
           
 boolean isEffective(CalculationRuleAccessBean aabRule, java.sql.Timestamp aTimestamp)
           
 boolean isPublished(CalculationCodeAccessBean aabCode)
           
 CalculationCodeAccessBean[] merge(CalculationCodeAccessBean[] aabCodes1, CalculationCodeAccessBean[] aabCodes2)
           
 java.math.BigDecimal[] remapValues(Item[] aItems1, java.math.BigDecimal[] adValues1, Item[] aItems2)
           
 void round(java.math.BigDecimal[] a, java.lang.String astrCurrency, CommandContext commandContext)
           
 java.math.BigDecimal round(java.math.BigDecimal adValue, java.lang.String astrCurrency, CommandContext commandContext)
           
 java.math.BigDecimal[] spread(java.math.BigDecimal adValue, java.math.BigDecimal[] adWeights)
           
 java.math.BigDecimal sum(java.math.BigDecimal[] adValues)
           
 void summarizeCalculationUsages(OrderAccessBean aabOrder, SubOrderAccessBean[] aabSubOrders, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to summarize all calculation usages enabled by the store.
 void summarizeCalculationUsages(OrderAccessBean aabOrder, SubOrderAccessBean[] aabSubOrders, OrderItemAccessBean[] aabOrderItems, java.lang.String astrCurrency, java.util.HashMap ahshCustomProperties, java.util.Set aEnabledUsageIds, java.util.Set aDisabledUsageIds, CommandContext commandContext)
          This method is called by OrderPrepare/PrepareOrder to summarize all calculation usages enabled by the store.
 java.lang.String toString(java.lang.Object[] a)
           
 SubOrderAccessBean[] updateSubOrders(java.lang.Long anOrderId, OrderItemAccessBean[] aabOrderItems)
          This method is called by OrderPrepare/PrepareOrder to update the suborder totals of an order.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Constructor Detail

CalculationHelper

protected CalculationHelper()
Method Detail

applyCalculationUsages

public void applyCalculationUsages(OrderItemAccessBean[] aabOrderItems,
                                   java.lang.String astrCurrency,
                                   java.util.HashMap ahshCustomProperties,
                                   CommandContext commandContext)
                            throws ECException
This method is called by OrderPrepare/PrepareOrder to apply all calculation usages enabled in the store.

applyCalculationUsages

public void applyCalculationUsages(OrderItemAccessBean[] aabOrderItems,
                                   java.lang.String astrCurrency,
                                   java.util.HashMap ahshCustomProperties,
                                   java.util.Set aEnabledUsageIds,
                                   java.util.Set aDisabledUsageIds,
                                   CommandContext commandContext)
                            throws ECException
This method is called by OrderPrepare/PrepareOrder to apply all calculation usages enabled in the store.
Parameters:
aEnabledUsageIds - if not null, calculation usages not in this set will be disabled
aDisabledUsageIds - if not null, calculation usages in this set will be disabled

compare

public int compare(java.lang.Comparable[] c1,
                   java.lang.Comparable[] c2)

compare

public int compare(java.lang.Comparable c1,
                   java.lang.Comparable c2)

containsAny

public boolean containsAny(java.lang.Object[] a1,
                           java.lang.Object[] a2)

convertMonetaryValue

public java.math.BigDecimal convertMonetaryValue(java.math.BigDecimal adValue1,
                                                 java.lang.String astrCurrency1,
                                                 java.lang.String astrCurrency2,
                                                 CommandContext commandContext)
                                          throws ECException
This method converts the monetary value from one currency to another using the forward conversion rate.

convertMonetaryValueR

public java.math.BigDecimal convertMonetaryValueR(java.math.BigDecimal adValue1,
                                                  java.lang.String astrCurrency1,
                                                  java.lang.String astrCurrency2,
                                                  CommandContext commandContext)
                                           throws ECException
This method converts the monetary value from one currency to another using the backward conversion rate.

convertQuantityValue

public java.math.BigDecimal convertQuantityValue(java.math.BigDecimal adValue1,
                                                 java.lang.String astrUnit1,
                                                 java.lang.String astrUnit2)
                                          throws ECException
This method converts the quantity value from one unit to another.

correctZeroBoundaryCrossings

public void correctZeroBoundaryCrossings(Item[] aItems,
                                         java.math.BigDecimal[] adAdjustments,
                                         java.lang.String astrCurrency,
                                         CommandContext commandContext)
                                  throws ECException
This method is called by DiscountCalculationCodeApply to correct discounts that cross the zero boundary.

correctZeroBoundaryCrossingsIteration

protected boolean correctZeroBoundaryCrossingsIteration(Item[] aItems,
                                                        java.math.BigDecimal[] adAdjustments)
                                                 throws ECException

destructiveAdd

public java.math.BigDecimal[] destructiveAdd(java.math.BigDecimal[] adValues1,
                                             java.math.BigDecimal[] adValues2)

divide

public java.math.BigDecimal divide(java.math.BigDecimal ad1,
                                   java.math.BigDecimal ad2)
Returns ad1.divide(ad2, 20, BigDecimal.ROUND_HALF_UP).

finalizeCalculationUsages

public void finalizeCalculationUsages(OrderAccessBean aabOrder,
                                      OrderItemAccessBean[] aabOrderItems,
                                      java.lang.String astrCurrency,
                                      java.util.HashMap ahshCustomProperties,
                                      CommandContext commandContext)
                               throws ECException
This method is called by OrderProcess/ProcessOrder to apply all calculation usages enabled in the store.

finalizeCalculationUsages

public void finalizeCalculationUsages(OrderAccessBean aabOrder,
                                      OrderItemAccessBean[] aabOrderItems,
                                      java.lang.String astrCurrency,
                                      java.util.HashMap ahshCustomProperties,
                                      java.util.Set aEnabledUsageIds,
                                      java.util.Set aDisabledUsageIds,
                                      CommandContext commandContext)
                               throws ECException
This method is called by OrderProcess/ProcessOrder to apply all calculation usages enabled by the store.
Parameters:
aEnabledUsageIds - if not null, calculation usages not in this set will be disabled
aDisabledUsageIds - if not null, calculation usages in this set will be disabled

findMax

public int findMax(java.math.BigDecimal[] e)

findMin

public int findMin(java.math.BigDecimal[] e)

getCodeId

public java.lang.Integer getCodeId(java.lang.Integer anRuleId)
                            throws ECException

getInstance

public static CalculationHelper getInstance()
Returns an instance of this class.

getProductAndItemIds

public java.lang.Long[] getProductAndItemIds(java.lang.Long anCatalogEntryId)
                                      throws ECException
Returns the parent product of an item and the item itself.

getProductOrItemIds

public java.lang.Long[] getProductOrItemIds(java.lang.Long anCatalogEntryId)
                                     throws ECException
Returns the parent product of an item. If it does not have one, returns the item itself.

getQuantity

public java.math.BigDecimal getQuantity(java.lang.Long anCatalogEntryId,
                                        java.math.BigDecimal adNormalizedQuantity,
                                        java.lang.String astrUnit)
                                 throws ECException
Returns the quantity represented by the normalized quantity.

getRoundingMultiple

public java.math.BigDecimal getRoundingMultiple(java.lang.String astrCurrency,
                                                CommandContext commandContext)
                                         throws ECException

getStoreGroupId

public java.lang.Integer getStoreGroupId(java.lang.Integer anStoreId)
                                  throws ECException

getTaxableAdjustmentTotal

public java.math.BigDecimal getTaxableAdjustmentTotal(java.lang.Long anOrderItemId,
                                                      java.lang.Integer anTaxCategoryId)
                                               throws ECException

getTaxCategoryIds

public java.lang.Integer[] getTaxCategoryIds(StoreAccessBean aabStore,
                                             java.lang.Integer anUsageId)
                                      throws ECException
Returns the tax categories of a particular calculation usage:
Calculation Usage Tax Categories
sales tax all sales tax categories
shipping tax all shipping tax categories
other null

getWeight

public java.math.BigDecimal getWeight(java.lang.Long anCatalogEntryId,
                                      java.math.BigDecimal adNormalizedQuantity,
                                      java.lang.String astrUnit)
                               throws ECException
Returns the weight represented by the normalized quantity.

initializeCalculationUsages

public void initializeCalculationUsages(OrderAccessBean aabOrder,
                                        OrderItemAccessBean[] aabOrderItems,
                                        java.lang.String astrCurrency,
                                        java.util.HashMap ahshCustomProperties,
                                        CommandContext commandContext)
                                 throws ECException
This method is called by OrderPrepare/PrepareOrder to initialize all calculation usages enabled by the store.

initializeCalculationUsages

public void initializeCalculationUsages(OrderAccessBean aabOrder,
                                        OrderItemAccessBean[] aabOrderItems,
                                        java.lang.String astrCurrency,
                                        java.util.HashMap ahshCustomProperties,
                                        java.util.Set aEnabledUsageIds,
                                        java.util.Set aDisabledUsageIds,
                                        CommandContext commandContext)
                                 throws ECException
This method is called by OrderPrepare/PrepareOrder to initialize all calculation usages enabled by the store.
Parameters:
aEnabledUsageIds - if not null, calculation usages not in this set will be disabled
aDisabledUsageIds - if not null, calculation usages in this set will be disabled

isCurrentUserInMemberGroup

public boolean isCurrentUserInMemberGroup(java.lang.Long anMemberGroupId,
                                          CommandContext commandContext)
                                   throws ECException

isEffective

public boolean isEffective(CalculationCodeAccessBean aabCode,
                           java.sql.Timestamp aTimestamp)
                    throws ECException

isEffective

public boolean isEffective(CalculationRuleAccessBean aabRule,
                           java.sql.Timestamp aTimestamp)
                    throws ECException

isPublished

public boolean isPublished(CalculationCodeAccessBean aabCode)
                    throws ECException

merge

public CalculationCodeAccessBean[] merge(CalculationCodeAccessBean[] aabCodes1,
                                         CalculationCodeAccessBean[] aabCodes2)
                                  throws ECException

remapValues

public java.math.BigDecimal[] remapValues(Item[] aItems1,
                                          java.math.BigDecimal[] adValues1,
                                          Item[] aItems2)

round

public void round(java.math.BigDecimal[] a,
                  java.lang.String astrCurrency,
                  CommandContext commandContext)
           throws ECException

round

public java.math.BigDecimal round(java.math.BigDecimal adValue,
                                  java.lang.String astrCurrency,
                                  CommandContext commandContext)
                           throws ECException

spread

public java.math.BigDecimal[] spread(java.math.BigDecimal adValue,
                                     java.math.BigDecimal[] adWeights)
                              throws ECException

sum

public java.math.BigDecimal sum(java.math.BigDecimal[] adValues)

summarizeCalculationUsages

public void summarizeCalculationUsages(OrderAccessBean aabOrder,
                                       SubOrderAccessBean[] aabSubOrders,
                                       OrderItemAccessBean[] aabOrderItems,
                                       java.lang.String astrCurrency,
                                       java.util.HashMap ahshCustomProperties,
                                       CommandContext commandContext)
                                throws ECException
This method is called by OrderPrepare/PrepareOrder to summarize all calculation usages enabled by the store.

summarizeCalculationUsages

public void summarizeCalculationUsages(OrderAccessBean aabOrder,
                                       SubOrderAccessBean[] aabSubOrders,
                                       OrderItemAccessBean[] aabOrderItems,
                                       java.lang.String astrCurrency,
                                       java.util.HashMap ahshCustomProperties,
                                       java.util.Set aEnabledUsageIds,
                                       java.util.Set aDisabledUsageIds,
                                       CommandContext commandContext)
                                throws ECException
This method is called by OrderPrepare/PrepareOrder to summarize all calculation usages enabled by the store.
Parameters:
aEnabledUsageIds - if not null, calculation usages not in this set will be disabled
aDisabledUsageIds - if not null, calculation usages in this set will be disabled

toString

public java.lang.String toString(java.lang.Object[] a)

updateSubOrders

public SubOrderAccessBean[] updateSubOrders(java.lang.Long anOrderId,
                                            OrderItemAccessBean[] aabOrderItems)
                                     throws ECException
This method is called by OrderPrepare/PrepareOrder to update the suborder totals of an order.