atg.commerce.pricing
Class BandedDiscountCalculatorHelper

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.logging.ApplicationLoggingImpl
          extended by atg.commerce.pricing.BandedDiscountCalculatorHelper
All Implemented Interfaces:
ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging

public class BandedDiscountCalculatorHelper
extends ApplicationLoggingImpl

A helper class with methods common to all banded calculators for use.


Nested Class Summary
 class BandedDiscountCalculatorHelper.Band
          Internal class to represent a band in the banded promotion
 
Field Summary
static java.lang.String ADJUSTER_ATTRIBUTE
          PMDL 'adjuster' attribute
static java.lang.String BAND_ATTRIBUTE
          PMDL 'band' attribute
static java.lang.String BANDING_PROPERTY_ATTRIBUTE
          PMDL 'bandingProperty' attribute
static java.lang.String BANDING_PROPERTY_SCOPE_ATTRIBUTE
          PMDL 'bandingPropertyScope' attribute
static java.lang.String BANDING_PROPERTY_SCOPE_DIPI
          PMDL banding property scope - "DetailedItemPriceInfo"
static java.lang.String BANDING_PROPERTY_SCOPE_QUALIFIED_ITEM
          PMDL banding property scope - "QualifiedItem"
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging
DEFAULT_LOG_TRACE_STATUS
 
Fields inherited from interface atg.nucleus.logging.ApplicationLogging
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
 
Constructor Summary
BandedDiscountCalculatorHelper()
          Constructor.
 
Method Summary
protected  double calculateBandingValue(java.lang.String pBandingPropertyScope, java.util.Map<java.lang.String,java.lang.Object> pObjectBindings, java.util.Collection pQualifiedItems)
          Determines the banding value to use.
protected  java.util.Map<java.lang.String,java.lang.Object> createBindings(java.lang.String pBandingProperty, java.util.Map pExtraParameters)
          Method to create an object bindings map with the objects that are required to determine the banding property value.
protected  BandedDiscountCalculatorHelper.Band determineBand(double pBandingValue, java.util.List<BandedDiscountCalculatorHelper.Band> pBands)
          Determines which band to use based on the banding value.
protected  java.util.List<BandedDiscountCalculatorHelper.Band> determineBands(java.util.List<DiscountDetail> pDetails)
          Determines the bands from the discount details and sorts them.
 double getAdjuster(RepositoryItem pPricingModel, java.util.Collection pQualifiedItems, java.util.Map pExtraParameters, java.lang.String pDefaultBandingProperty, java.lang.String pDefaultBandingPropertyScope)
          Determines the amount of adjustment to apply.
protected  double getBandingPropertyValue(java.util.Map<java.lang.String,java.lang.Object> pObjectBindings)
          This method resolves the banding property value.
 CalculatorInfo getCalculatorInfo(java.lang.String pCalculatorType)
          Provide a CalculatorInfo for the calculator
 
Methods inherited from class atg.nucleus.logging.ApplicationLoggingImpl
addGlobalLogListeners, addLogListener, getLoggingForVlogging, getLoggingIdentifer, getLoggingIdentifier, getLogListenerCount, getLogListeners, initializeFromServiceEvent, isAutoInitListeners, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, removeLogListener, sendLogEvent, setAutoInitListeners, setLoggingDebug, setLoggingError, setLoggingIdentifier, setLoggingInfo, setLoggingTrace, setLoggingWarning
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static final java.lang.String CLASS_VERSION
Class version string

See Also:
Constant Field Values

BANDING_PROPERTY_ATTRIBUTE

public static final java.lang.String BANDING_PROPERTY_ATTRIBUTE
PMDL 'bandingProperty' attribute

See Also:
Constant Field Values

BANDING_PROPERTY_SCOPE_ATTRIBUTE

public static final java.lang.String BANDING_PROPERTY_SCOPE_ATTRIBUTE
PMDL 'bandingPropertyScope' attribute

See Also:
Constant Field Values

BAND_ATTRIBUTE

public static final java.lang.String BAND_ATTRIBUTE
PMDL 'band' attribute

See Also:
Constant Field Values

ADJUSTER_ATTRIBUTE

public static final java.lang.String ADJUSTER_ATTRIBUTE
PMDL 'adjuster' attribute

See Also:
Constant Field Values

BANDING_PROPERTY_SCOPE_DIPI

public static final java.lang.String BANDING_PROPERTY_SCOPE_DIPI
PMDL banding property scope - "DetailedItemPriceInfo"

See Also:
Constant Field Values

BANDING_PROPERTY_SCOPE_QUALIFIED_ITEM

public static final java.lang.String BANDING_PROPERTY_SCOPE_QUALIFIED_ITEM
PMDL banding property scope - "QualifiedItem"

See Also:
Constant Field Values
Constructor Detail

BandedDiscountCalculatorHelper

public BandedDiscountCalculatorHelper()
Constructor. Sets logging name.

Method Detail

getAdjuster

public double getAdjuster(RepositoryItem pPricingModel,
                          java.util.Collection pQualifiedItems,
                          java.util.Map pExtraParameters,
                          java.lang.String pDefaultBandingProperty,
                          java.lang.String pDefaultBandingPropertyScope)
                   throws PricingException
Determines the amount of adjustment to apply. First checks for a discount structure in the extra parameters map. If not found then the method will determine which band of the discount structure to use and obtain the adjuster accordingly. If no band is found then it return NaN as the adjuster.

Parameters:
pPricingModel - RepositoryItem pricing model
pQualifiedItems - Collection of QualifiedItem objects
pExtraParameters - Map of optional extra parameters, may be null
pDefaultBandingProperty - String default banding property to use
pDefaultBandingPropertyScope - String default banding property scope to use
Returns:
double adjuster to use or NaN if no valid band found.
Throws:
PricingException - if the method fails to get a valid double adjuster

createBindings

protected java.util.Map<java.lang.String,java.lang.Object> createBindings(java.lang.String pBandingProperty,
                                                                          java.util.Map pExtraParameters)
                                                                   throws PricingException
Method to create an object bindings map with the objects that are required to determine the banding property value. This method will first parse out the passed in pBandingProperty string by looking for the first dot '.' character. This will parse out the bean name and property name to use. The property name is stored in the returned map with the key Constants.BINDING_KEY_BANDING_BEAN_PROPERTY_NAME. If the bean name starts with a '/' then it is assumed to be a nucleus component and is resolved. Otherwise if the bean name corresponds to the extra parameters map or the pricing context then the bean is set accordingly. If the bean is determined then it is stored in the returned map with the key Constants.BINDING_KEY_BANDING_BEAN. Otherwise the bean name is stored with the key Constants.BINDING_KEY_BANDING_BEAN_NAME.

Parameters:
pBandingProperty - String banding property name
pExtraParameters - Map of extra parameters
Returns:
Map of bound objects
Throws:
PricingException

calculateBandingValue

protected double calculateBandingValue(java.lang.String pBandingPropertyScope,
                                       java.util.Map<java.lang.String,java.lang.Object> pObjectBindings,
                                       java.util.Collection pQualifiedItems)
                                throws PricingException
Determines the banding value to use. If the banding property scope is QualifiedItem then this method will get the total matching quantity for each QualifiedItem and get the banding property value for each QualfiedItem and sum (quantity * banding property value). If the banding property scope is DetailedItemPriceInfo then this method will get the matching quantity for each DetailedItemPriceInfo and get the banding property value for each DetailedItemPriceInfo and sum (quantity * banding property value). If the banding property scope is null then this method will just return the banding property value. If the banding property scope is not null then pQualifiedItems must not be null. The banding property value is obtained by calling the getBandingPropertyValue method. Note: The pObjectBindings map must already be setup before calling into this method. This is normally done through the createBindings method.

Parameters:
pBandingPropertyScope - String bandingPropertyScope "QualifiedItem", "DetailedItemPriceInfo" or null.
pObjectBindings - Map of banded property objects to use.
pQualifiedItems - Collection of QualifiedItem objects, can only be null if scope is null.
Returns:
double banding value to use
Throws:
PricingException - for any problems determining the banding value to use.

getBandingPropertyValue

protected double getBandingPropertyValue(java.util.Map<java.lang.String,java.lang.Object> pObjectBindings)
                                  throws PricingException
This method resolves the banding property value. It requires that pObjectBindings is already correctly setup (usually through the createBindings method). pObjectBindings should contain the property name to use and either the bean object or the bean name to use. If the bean is not provided then the bean name is used to lookup the bean in pObjectBindings. The method will use dynamic beans to resolve the property value using the bean and the property name. If the bandingProperty is null then the bean and property name will be null so this method will return 1.0d, i.e. just the quantity of the item will be used in the calculation.

Parameters:
pObjectBindings - Map of banding property objects to use
Returns:
double property value to use.
Throws:
PricingException - if it fails to resolve the property value.

determineBands

protected java.util.List<BandedDiscountCalculatorHelper.Band> determineBands(java.util.List<DiscountDetail> pDetails)
                                                                      throws PricingException
Determines the bands from the discount details and sorts them.

Parameters:
pDetails - List of DiscountDetail from the discount structure
Returns:
List of Band objects in sorted order
Throws:
PricingException - for problems creating the bands, must be at least one band.

determineBand

protected BandedDiscountCalculatorHelper.Band determineBand(double pBandingValue,
                                                            java.util.List<BandedDiscountCalculatorHelper.Band> pBands)
Determines which band to use based on the banding value.

Parameters:
pBandingValue - double banding value to match with
pBands - List of Band objects to search
Returns:
Band to use or null if no valid band

getCalculatorInfo

public CalculatorInfo getCalculatorInfo(java.lang.String pCalculatorType)
Provide a CalculatorInfo for the calculator

Parameters:
pCalculatorType - String calculator type to set
Returns:
CalculatorInfo