com.ibm.commerce.order.calculation
Class CalculationRuleCalculateCmdImpl

java.lang.Object
  CacheableCommandImpl
      com.ibm.commerce.command.AbstractECTargetableCommand
          com.ibm.commerce.command.TaskCommandImpl
              com.ibm.commerce.command.BusinessPolicyCommandImpl
                  com.ibm.commerce.order.calculation.CalculationCmdImpl
                      com.ibm.commerce.order.calculation.CalculationRuleCalculateCmdImpl
All Implemented Interfaces:
BusinessPolicyCommand, CalculationCmd, CalculationRuleCalculateCmd, ECCommand, ECTargetableCommand, TaskCommand

public class CalculationRuleCalculateCmdImpl
extends CalculationCmdImpl
implements CalculationRuleCalculateCmd

The default implementation of CalculationRuleCalculateCmd.

Its behaviour is as follows:

  1. identifies the calculation scales associated with the calculation rule (see CRULESCALE).
  2. groups the calculation scales by currency (see CALSCALE.SETCCURR).
  3. if there are ones in the currency specified, discards the others.
  4. for each calculation scale, calculates its values:
    1. invokes the calculation method of type "CalculationScaleLookup" referenced by the calculation scale (see CALSCALE.CALMETHOD_ID, CalculationScaleLookupCmd) to determine the following:
      • a lookup number.
      • a base monetary value.
      • a result multiplier.
      • a mathematical weight for each item.
    2. identifies the calculation ranges of the calcuation scale where (range start <= lookup number).
    3. for each calculation range, in descending order of range start:
      1. determines the applicable lookup number, which is (max(lookup number, range end) - range start) if the calculation range is cumulative (see CALRANGE.CUMULATIVE), or max(lookup number, range end) if not.
      2. invokes the calculation method of type "CalculationRange" referenced by the calculation range (see CALRANGE.CALMETHOD_ID, CalculationRangeCmd) to calculate the resulting value.
      3. multiplies this value by the result multiplier.
      4. adds this value to a total value.
      5. breaks if the calculation range is not cumulative.
    4. distributes the total value among the items based on their mathematical weights.
    5. applies the direct attachments associated with the calculation rule.
  5. for each group of calculation scales, merges the lists of resulting values.
  6. select the merged list that has the lowest total value.

Commands used:

Access beans used:
See Also:
Serialized Form

Field Summary
static java.lang.String COPYRIGHT
The IBM copyright notice field.
Fields inherited from class com.ibm.commerce.command.BusinessPolicyCommandImpl
policyId, requestProperties
Fields inherited from class com.ibm.commerce.command.AbstractECTargetableCommand
commandContext
Fields inherited from interface com.ibm.commerce.order.calculation.CalculationRuleCalculateCmd
defaultCommandClassName, NAME
Fields inherited from interface com.ibm.commerce.command.ECCommand
defaultCommandClassName
Constructor Summary
CalculationRuleCalculateCmdImpl()
Constructor for CalculationRuleCalculateCmdImpl.
Method Summary
protected void applyOrderItemLevelParameters(java.math.BigDecimal[] adValues, DirectAttachmentHelper aDirectAttachmentHelper)
Applies the parametrized orderitem level direct attachments (see ORDICALCD) associated with the calculation rule to a list of values.
protected void applyOrderLevelParameters(java.math.BigDecimal[] adValues, java.math.BigDecimal[] adWeights, DirectAttachmentHelper aDirectAttachmentHelper, java.lang.Long anOrderId)
Applies the parametrized order level direct attachments (see ORDCALCD) associated with the calculation rule to a list of values.
protected void applyParameters(java.math.BigDecimal[] adValues, java.math.BigDecimal[] adWeights)
Applies the parametrized direct attachments associated with the calculation rule to a list of values.
protected java.math.BigDecimal callRange(CalculationRangeAccessBean aabRange, CalculationRangeLookupResultAccessBean aabLookupResult, java.math.BigDecimal adApplicableLookupNumber, java.math.BigDecimal adApplicableBaseMonetaryValue)
Invokes the calculation method of type "CalculationRange" referenced by the calculation range (see CALRANGE.CALMETHOD_ID, CalculationRangeCmd) to calculate the resulting value.
protected CalculationScaleLookupCmd callScaleLookup(CalculationScaleAccessBean aabScale)
Invokes the calculation method of type "CalculationScaleLookup" referenced by the calculation scale (see CALSCALE.CALMETHOD_ID, CalculationScaleLookupCmd) to determine a lookup number, a base monetary value, a result multiplier and a list of mathematical weights.
protected void compareValues()
Merges the resulting lists of values of the calculation scales by currency and selects the merged list with the lowest total value.
protected Item[] getItems()
Returns the items.
protected CalculationRuleAccessBean getRule()
Returns the calculation rule.
protected java.util.Set getScaleCurrencies(CalculationScaleAccessBean[] aabScales)
Retrieves the set of currencies referenced by a list of calculation scales.
java.math.BigDecimal[] getValues()
Returns the values corresponding to the items.
protected java.math.BigDecimal[] getValues(java.lang.String astrCurrency)
Returns the merged list of values of a currency.
void performExecute()
The business logic for this command.
void reset()
Resets the command properties.
protected java.math.BigDecimal[] scaleCalculate(CalculationScaleAccessBean aabScale)
Calculates the resulting list of values of a calculation scale.
void setItems(Item[] aItems)
Sets the items.
void setRule(CalculationRuleAccessBean aabRule)
Sets the calculation rule.
protected void setValues(java.math.BigDecimal[] adValues)
Sets the values.
protected void setValues(java.lang.String astrCurrency, java.math.BigDecimal[] adValues)
Sets the merged list of values of a currency.
Methods inherited from class com.ibm.commerce.order.calculation.CalculationCmdImpl
createCommand, getCurrency, getCustomProperties, getCustomProperty, getTimestamp, getUsageId, recycleCommand, setCurrency, setCustomProperties, setCustomProperty, setTimestamp, setUsageId
Methods inherited from class com.ibm.commerce.command.BusinessPolicyCommandImpl
getPolicyId, getRequestProperties, setPolicyId, setRequestProperties
Methods inherited from class com.ibm.commerce.command.AbstractECTargetableCommand
accessControlCheck, checkIsAllowed, checkParameters, checkResourcePermission, createCommandExecutionEvent, execute, finalize, getAccCheck, getCommandContext, getCommandIfName, getCommandName, getCommandStoreId, getDefaultProperties, getResources, getStoreId, getUser, getUserId, isReadyToCallExecute, setAccCheck, setCommandContext, setCommandIfName, setCommandStoreId, setDefaultProperties, validateParameters
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.ibm.commerce.order.calculation.CalculationCmd
getCurrency, getCustomProperties, getCustomProperty, getTimestamp, getUsageId, setCurrency, setCustomProperties, setCustomProperty, setTimestamp, setUsageId
Methods inherited from interface com.ibm.commerce.command.BusinessPolicyCommand
getPolicyId, getRequestProperties, setPolicyId, setRequestProperties
Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
The IBM copyright notice field.
See Also:
Constant Field Values
Constructor Detail

CalculationRuleCalculateCmdImpl

public CalculationRuleCalculateCmdImpl()
Constructor for CalculationRuleCalculateCmdImpl.
Method Detail

reset

public void reset()
Resets the command properties. Prepares the command for re-execution.
Overrides:
reset in class CalculationCmdImpl
See Also:
com.ibm.websphere.command.Command#reset()

applyOrderItemLevelParameters

protected void applyOrderItemLevelParameters(java.math.BigDecimal[] adValues,
                                             DirectAttachmentHelper aDirectAttachmentHelper)
                                      throws ECException
Applies the parametrized orderitem level direct attachments (see ORDICALCD) associated with the calculation rule to a list of values. This method is called by applyParameters(BigDecimal[], BigDecimal[]).
Parameters:
adValues - the values to apply to.
aDirectAttachmentHelper - a DirectAttachmentHelper instance.
Throws:
ECException

applyOrderLevelParameters

protected void applyOrderLevelParameters(java.math.BigDecimal[] adValues,
                                         java.math.BigDecimal[] adWeights,
                                         DirectAttachmentHelper aDirectAttachmentHelper,
                                         java.lang.Long anOrderId)
                                  throws ECException
Applies the parametrized order level direct attachments (see ORDCALCD) associated with the calculation rule to a list of values. This method is called by applyParameters(BigDecimal[], BigDecimal[]).
Parameters:
adValues - the values to apply to.
adWeights - the mathematical weights to use when distributing values.
aDirectAttachmentHelper - a DirectAttachmentHelper instance.
anOrderId - the order ID.
Throws:
ECException

applyParameters

protected void applyParameters(java.math.BigDecimal[] adValues,
                               java.math.BigDecimal[] adWeights)
                        throws ECException
Applies the parametrized direct attachments associated with the calculation rule to a list of values. This method is called by scaleCalculate(CalculationScaleAccessBean).
Parameters:
adValues - the values to apply to.
adWeights - the mathematical weights to use when distributing values.
Throws:
ECException

callRange

protected java.math.BigDecimal callRange(CalculationRangeAccessBean aabRange,
                                         CalculationRangeLookupResultAccessBean aabLookupResult,
                                         java.math.BigDecimal adApplicableLookupNumber,
                                         java.math.BigDecimal adApplicableBaseMonetaryValue)
                                  throws ECException
Invokes the calculation method of type "CalculationRange" referenced by the calculation range (see CALRANGE.CALMETHOD_ID, CalculationRangeCmd) to calculate the resulting value. This method is called by scaleCalculate(CalculationScaleAccessBean).
Parameters:
aabRange - the calculation range.
aabLookupResult - the calculation range lookup result.
adApplicableLookupNumber - the applicable lookup number.
adApplicableBaseMonetaryValue - the applicable base monetary value.
Returns:
the resulting value.
Throws:
ECException

callScaleLookup

protected CalculationScaleLookupCmd callScaleLookup(CalculationScaleAccessBean aabScale)
                                             throws ECException
Invokes the calculation method of type "CalculationScaleLookup" referenced by the calculation scale (see CALSCALE.CALMETHOD_ID, CalculationScaleLookupCmd) to determine a lookup number, a base monetary value, a result multiplier and a list of mathematical weights. This method is called by scaleCalculate(CalculationScaleAccessBean).
Parameters:
aabScale - the calculation scale.
Returns:
the command.
Throws:
ECException

compareValues

protected void compareValues()
                      throws ECException
Merges the resulting lists of values of the calculation scales by currency and selects the merged list with the lowest total value. This method is called by performExecute().
Throws:
ECException

getItems

protected Item[] getItems()
Returns the items.
Returns:
the items.

getRule

protected CalculationRuleAccessBean getRule()
Returns the calculation rule.
Returns:
the calculation rule.

getScaleCurrencies

protected java.util.Set getScaleCurrencies(CalculationScaleAccessBean[] aabScales)
                                    throws ECException
Retrieves the set of currencies referenced by a list of calculation scales. This method is called by performExecute().
Parameters:
aabScales - the calculation scales.
Returns:
the set of currencies (class: String).
Throws:
ECException

getValues

public java.math.BigDecimal[] getValues()
Returns the values corresponding to the items.
Specified by:
getValues in interface CalculationRuleCalculateCmd
Returns:
the values.

getValues

protected java.math.BigDecimal[] getValues(java.lang.String astrCurrency)
Returns the merged list of values of a currency.
Parameters:
astrCurrency - the currency.
Returns:
the merged list of values of the currency.

performExecute

public void performExecute()
                    throws ECException
Description copied from class: AbstractECTargetableCommand
The business logic for this command. This method should be overwritten by all command writers. Command writers should call super.performExecute() as the first line in their method.
Specified by:
performExecute in interface ECCommand
Overrides:
performExecute in class AbstractECTargetableCommand
Throws:
ECException
See Also:
ECCommand.performExecute()

scaleCalculate

protected java.math.BigDecimal[] scaleCalculate(CalculationScaleAccessBean aabScale)
                                         throws ECException
Calculates the resulting list of values of a calculation scale. This method is called by performExecute().
Parameters:
aabScale - the calculation scale.
Returns:
the resulting list of values.
Throws:
ECException

setItems

public void setItems(Item[] aItems)
Sets the items.
Specified by:
setItems in interface CalculationRuleCalculateCmd
Parameters:
aItems - the items.

setRule

public void setRule(CalculationRuleAccessBean aabRule)
Sets the calculation rule.
Specified by:
setRule in interface CalculationRuleCalculateCmd
Parameters:
aabRule - the calculation rule.

setValues

protected void setValues(java.math.BigDecimal[] adValues)
Sets the values.
Parameters:
adValues - the values.

setValues

protected void setValues(java.lang.String astrCurrency,
                         java.math.BigDecimal[] adValues)
Sets the merged list of values of a currency.
Parameters:
astrCurrency - the currency.
adValues - the merged list of values.

Feedback