public class DiscountCalculatorService extends GenericService
adjust
method can be leveraged as a means of quickly applying a
discount.
Properties:
adjust
method should return negative amounts (if this property is false), or should throw
an exception instead (if true)
Qualifier
,
PricingModelProperties
Modifier and Type | Field and Description |
---|---|
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
|
SERVICE_INFO_KEY
DEFAULT_LOG_TRACE_STATUS
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS
Constructor and Description |
---|
DiscountCalculatorService()
Constructs a new DiscountCalculatorService
|
Modifier and Type | Method and Description |
---|---|
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 pGroupTotal,
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
|
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
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning
public static java.lang.String CLASS_VERSION
protected static final int ILLEGAL_TYPE
protected static final int AMOUNT_OFF_TYPE
protected static final int PERCENT_OFF_TYPE
protected static final int FIXED_PRICE_TYPE
protected static final int AMOUNT_INCREASE_TYPE
protected PromotionTools mPromotionTools
public DiscountCalculatorService()
public void setQualifierService(Qualifier pQualifierService)
pQualifierService
- new value to setpublic Qualifier getQualifierService()
public void setPromotionTools(PromotionTools pPromotionTools)
pPromotionTools
- new value to setpublic PromotionTools getPromotionTools()
public void setPricingModelProperties(PricingModelProperties pPricingModelProperties)
pPricingModelProperties
- new value to setpublic PricingModelProperties getPricingModelProperties()
public void setNegativeAmountException(boolean pNegativeAmountException)
public boolean isNegativeAmountException()
protected int getDiscountType(java.lang.String pDiscountType)
pDiscountType
- FIXED_PRICE_TYPE
,
AMOUNT_OFF_TYPE
,
PERCENT_OFF_TYPE
,
AMOUNT_INCREASE_TYPE
protected double adjust(double pAmount, double pAdjuster, java.lang.String pDiscountType, java.lang.String pId) throws PricingException
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.
pAmount
- The amount to adjustpAdjuster
- The adjustment parameter, used according to the pDiscountTypepDiscountType
- 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 loggedPricingException
- if there was a problem finding the adjusted price.protected double adjustAmount(double pAmount, double pAdjuster, java.lang.String pDiscountType) throws PricingException
PricingException
protected double adjustAmount(double pAmount, double pGroupTotal, double pAdjuster, java.lang.String pDiscountType, java.lang.String pId) throws PricingException
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.
pAmount
- The amount to adjustpGroupTotal
- The group total current pricepAdjuster
- The adjustment parameter, used according to the pDiscountTypepDiscountType
- 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 loggedPricingException
- if there was a problem finding the adjusted price.protected double getAdjuster(RepositoryItem pPricingModel, java.util.Map pExtraParameters) throws PricingException
pPricingModel
- RepositoryItem pricing modelpExtraParameters
- Map of optional extra parameters, may be nullPricingException
- if the method fails to get a valid double adjusterprotected java.lang.String getDiscountType(RepositoryItem pPricingModel, java.util.Map pExtraParameters) throws PricingException
pPricingModel
- RepositoryItem pricing modelpExtraParameters
- Map of optional extra parametersPricingException
- if the method fails to determine a valid discount type.protected Qualifier getQualifierService(RepositoryItem pPricingModel, java.util.Map pExtraParameters)
pPricingModel
- pExtraParameters
- PromotionTools.getQualifierService(RepositoryItem, Map, Qualifier)