atg.commerce.pricing
Class DiscountCalculatorService

java.lang.Object
  extended by atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
      extended by atg.nucleus.GenericService
          extended by atg.commerce.pricing.DiscountCalculatorService
All Implemented Interfaces:
atg.naming.AbsoluteNameable, NameContextBindingListener, NameContextElement, atg.naming.NameContextParentable, NameResolver, AdminableService, atg.nucleus.Configured, ApplicationLogging, atg.nucleus.logging.ApplicationLoggingSender, atg.nucleus.logging.TraceApplicationLogging, VariableArgumentApplicationLogging, ComponentNameResolver, Service, ServiceListener, java.util.EventListener
Direct Known Subclasses:
ItemDiscountCalculator, OrderDiscountCalculator, ShippingDiscountCalculator, TaxDiscountCalculator

public class DiscountCalculatorService
extends GenericService

A GenericService version of a discount calculator. Discount calculators can extend this class so as to eliminate redundant configuration code. Additionally, the adjust method can be leveraged as a means of quickly applying a discount.

Properties:

See Also:
Qualifier, PricingModelProperties

Field Summary
protected static int AMOUNT_INCREASE_TYPE
          Integer representation of an Amount Increase adjustment
protected static int AMOUNT_OFF_TYPE
          Integer representation of an Amount Off discount
static java.lang.String CLASS_VERSION
          Class version string
protected static int FIXED_PRICE_TYPE
          Integer representation of a Fixed Price discount
protected static int ILLEGAL_TYPE
          Integer representation of an illegal discount type.
protected  PromotionTools mPromotionTools
          Utility service to help with processing promotion items
protected static int PERCENT_OFF_TYPE
          Integer representation of a Percent Off discount
 
Fields inherited from class atg.nucleus.GenericService
SERVICE_INFO_KEY
 
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
DiscountCalculatorService()
          Constructs a new DiscountCalculatorService
 
Method Summary
protected  double adjust(double pAmount, double pAdjuster, java.lang.String pDiscountType, java.lang.String pId)
          Returns the input pAmount adjusted by the input pAdjuster in the manner specified by pDiscountType.
protected  double adjustAmount(double pAmount, double pAdjuster, java.lang.String pDiscountType)
           
protected  double getAdjuster(RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          Determines the amount of adjustment to apply.
protected  java.lang.String getDiscountType(RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          Determines the discount type to apply.
protected  int getDiscountType(java.lang.String pDiscountType)
          Returns the int discount type for the string discount type provided.
 PricingModelProperties getPricingModelProperties()
          Get property PricingModelProperties
 PromotionTools getPromotionTools()
          Get property PromotionTools
 Qualifier getQualifierService()
          Get property QualifierService
protected  Qualifier getQualifierService(RepositoryItem pPricingModel, java.util.Map pExtraParameters)
          Gets the Qualifier service this calculator should use to process promotions.
 boolean isNegativeAmountException()
          Get property negativeAmountException.
 void setNegativeAmountException(boolean pNegativeAmountException)
           
 void setPricingModelProperties(PricingModelProperties pPricingModelProperties)
          Set property PricingModelProperties
 void setPromotionTools(PromotionTools pPromotionTools)
          Set property PromotionTools
 void setQualifierService(Qualifier pQualifierService)
          Set property QualifierService
 
Methods inherited from class atg.nucleus.GenericService
addLogListener, createAdminServlet, doStartService, doStopService, getAbsoluteName, getAdminServlet, getAdminServletOutputStreamEncoding, getLoggingForVlogging, getLogListenerCount, getLogListeners, getName, getNameContext, getNucleus, getRoot, getServiceConfiguration, getServiceInfo, isAdminServletUseServletOutputStream, isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingTrace, isLoggingWarning, isRunning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logTrace, logTrace, logTrace, logWarning, logWarning, logWarning, nameContextElementBound, nameContextElementUnbound, removeLogListener, reResolveThis, resolveName, resolveName, resolveName, resolveName, sendLogEvent, setAdminServletOutputStreamEncoding, setAdminServletUseServletOutputStream, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingTrace, setLoggingWarning, setNucleus, setServiceInfo, startService, stopService
 
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, 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 java.lang.String CLASS_VERSION
Class version string


ILLEGAL_TYPE

protected static final int ILLEGAL_TYPE
Integer representation of an illegal discount type. An illegal type is defined as being not one of the valid types below

See Also:
Constant Field Values

AMOUNT_OFF_TYPE

protected static final int AMOUNT_OFF_TYPE
Integer representation of an Amount Off discount

See Also:
Constant Field Values

PERCENT_OFF_TYPE

protected static final int PERCENT_OFF_TYPE
Integer representation of a Percent Off discount

See Also:
Constant Field Values

FIXED_PRICE_TYPE

protected static final int FIXED_PRICE_TYPE
Integer representation of a Fixed Price discount

See Also:
Constant Field Values

AMOUNT_INCREASE_TYPE

protected static final int AMOUNT_INCREASE_TYPE
Integer representation of an Amount Increase adjustment

See Also:
Constant Field Values

mPromotionTools

protected PromotionTools mPromotionTools
Utility service to help with processing promotion items

Constructor Detail

DiscountCalculatorService

public DiscountCalculatorService()
Constructs a new DiscountCalculatorService

Method Detail

setQualifierService

public void setQualifierService(Qualifier pQualifierService)
Set property QualifierService

Parameters:
pQualifierService - new value to set

getQualifierService

public Qualifier getQualifierService()
Get property QualifierService

Returns:
property QualifierService

setPromotionTools

public void setPromotionTools(PromotionTools pPromotionTools)
Set property PromotionTools

Parameters:
pPromotionTools - new value to set

getPromotionTools

public PromotionTools getPromotionTools()
Get property PromotionTools

Returns:
property PromotionTools

setPricingModelProperties

public void setPricingModelProperties(PricingModelProperties pPricingModelProperties)
Set property PricingModelProperties

Parameters:
pPricingModelProperties - new value to set

getPricingModelProperties

public PricingModelProperties getPricingModelProperties()
Get property PricingModelProperties

Returns:
PricingModelProperties

setNegativeAmountException

public void setNegativeAmountException(boolean pNegativeAmountException)

isNegativeAmountException

public boolean isNegativeAmountException()
Get property negativeAmountException. If negativeAmountException is true and a discount causes the amount to be negative throw an exception, otherwise log a warning message and set the amount to 0.0. The default is false

Returns:
property NegativeAmountException

getDiscountType

protected int getDiscountType(java.lang.String pDiscountType)
Returns the int discount type for the string discount type provided.

Parameters:
pDiscountType -
Returns:
int discount type
See Also:
FIXED_PRICE_TYPE, AMOUNT_OFF_TYPE, PERCENT_OFF_TYPE, AMOUNT_INCREASE_TYPE

adjust

protected double adjust(double pAmount,
                        double pAdjuster,
                        java.lang.String pDiscountType,
                        java.lang.String pId)
                 throws PricingException
Returns the input pAmount adjusted by the input pAdjuster in the manner specified by pDiscountType. For example:

If pAmount is 30, pAdjuster is 10, and pDiscountType is "amountOff", then the amount 30 will have the fixed amount 10 subtracted from it to produce a result of 20.

Parameters:
pAmount - The amount to adjust
pAdjuster - The adjustment parameter, used according to the pDiscountType
pDiscountType - The manner in which pAmount should be adjusted by pAdjuster.
pId - An identifier to associate with this operation if an expception is thrown or a warning logged
Returns:
The adjusted amount
Throws:
PricingException - if there was a problem finding the adjusted price.

adjustAmount

protected double adjustAmount(double pAmount,
                              double pAdjuster,
                              java.lang.String pDiscountType)
                       throws PricingException
Throws:
PricingException

getAdjuster

protected double getAdjuster(RepositoryItem pPricingModel,
                             java.util.Map pExtraParameters)
                      throws PricingException
Determines the amount of adjustment to apply. First checks for a discount structure in the extra parameters map. If found then uses it's adjuster otherwise tries to get the adjuster from the pricing model.

Parameters:
pPricingModel - RepositoryItem pricing model
pExtraParameters - Map of optional extra parameters, may be null
Returns:
double adjuster to use
Throws:
PricingException - if the method fails to get a valid double adjuster

getDiscountType

protected java.lang.String getDiscountType(RepositoryItem pPricingModel,
                                           java.util.Map pExtraParameters)
                                    throws PricingException
Determines the discount type to apply. First checks for a discount structure in the extra parameters map. If found then uses it's discount type otherwise tries to get the discount type from the pricing model.

Parameters:
pPricingModel - RepositoryItem pricing model
pExtraParameters - Map of optional extra parameters
Returns:
String discount type to use
Throws:
PricingException - if the method fails to determine a valid discount type.

getQualifierService

protected Qualifier getQualifierService(RepositoryItem pPricingModel,
                                        java.util.Map pExtraParameters)
Gets the Qualifier service this calculator should use to process promotions.

Parameters:
pPricingModel -
pExtraParameters -
Returns:
See Also:
PromotionTools.getQualifierService(RepositoryItem, Map, Qualifier)