Class DefaultRuleEngineCalculationService
java.lang.Object
de.hybris.platform.ruleengineservices.calculation.impl.DefaultRuleEngineCalculationService
- All Implemented Interfaces:
RuleEngineCalculationService
public class DefaultRuleEngineCalculationService
extends Object
implements RuleEngineCalculationService
The DefaultRuleEngineCalculationService uses the order calculation facilities to calculate the order and cart.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFixedPriceEntriesDiscount(CartRAO cartRao, Map<Integer, Integer> selectedOrderEntryMap, Set<OrderEntryRAO> selectedOrderEntryRaos, BigDecimal fixedPrice) Creates order entry level discounts for the cartcartRao, with thefixedPricegiven as parameter and for the products from entries inselectedOrderEntryRaosand related quantities given inselectedOrderEntryMap.addFixedPriceEntryDiscount(OrderEntryRAO orderEntryRao, BigDecimal fixedPrice) Creates a new order entry level discount such that the order entry's price will be equal to the givenfixedPricemultiplied by quantity.addFreeProductsToCart(CartRAO cartRao, ProductModel product, int quantity) Adds free product items to the cart.addOrderEntryLevelDiscount(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount) creates a DiscountRAO for the given OrderEntryRAO based on the input.addOrderEntryLevelDiscount(OrderEntryRAO orderEntryRAO, boolean absolute, BigDecimal amount, boolean perUnit) Create a set of order entry level discounts based on the given value, absolute flag and perUnit flag, adds it to the corresponding orderRao and updates the orderRao totals.protected DiscountRAOaddOrderEntryLevelDiscount(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount, int consumedQty) addOrderEntryLevelDiscount(Map<Integer, Integer> selectedOrderEntryMap, Set<OrderEntryRAO> selectedOrderEntryRaos, boolean absolute, BigDecimal amount) Creates order entry level discounts for the cartcartRao, adds it to the cartRao and updates the cartRao totals.protected Set<DiscountRAO>addOrderEntryLevelDiscountWithPerUnitFlag(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount, int consumedQty, boolean perUnit) addOrderLevelDiscount(CartRAO cartRao, boolean absolute, BigDecimal amount) creates a DiscountRAO for the given CartRAO based on the input.voidcalculateTotals(AbstractOrderRAO cartRao) performs a (re)calculation on the given abstractOrderRao and updates these properties:AbstractOrderRAO.getTotal()AbstractOrderRAO.getSubTotal()AbstractOrderRAO.getDeliveryCost()AbstractOrderRAO.getPaymentCost()changeDeliveryMode(CartRAO cartRao, DeliveryModeRAO mode) Changes the current delivery mode to the given values, adds it to the cartRao and updates the carRao totals.protected BigDecimalconvertPercentageDiscountToAbsoluteDiscount(BigDecimal percentageAmount, int quantityToConsume, NumberedLineItem orderLineItem) protected BigDecimalconvertPercentageDiscountToAbsoluteDiscount(BigDecimal percentageAmount, Order cart) protected Set<DiscountRAO>createAbsoluteDiscountRAO(LineItem lineItem, BigDecimal amount, int applicableUnits) protected DiscountRAOcreateAbsoluteDiscountRAO(LineItem lineItem, BigDecimal amount, int applicableUnits, boolean perUnit) protected DiscountRAOcreateDiscountRAO(AbstractDiscount discount) Creates a new DiscountRAO based on the given AbstractDiscount.protected LineItemDiscountcreateLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount) Creates an LineItemDiscount based on the given values and adds it to the givenlineItem.protected LineItemDiscountcreateLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount, boolean perUnit) Creates an LineItemDiscount based on the given values and adds it to the givenlineItem.protected LineItemDiscountcreateLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount, boolean perUnit, int applicableUnits) protected OrderDiscountcreateOrderDiscount(Order cart, boolean absolute, BigDecimal amount) Creates an OrderDiscount based on the given values and adds it to the givencart.protected ShipmentRAOCreates a new ShipmentRAO based on the given Delivery Mode.protected OrderChargecreateShippingCharge(Order cart, boolean absolute, BigDecimal value) creates anOrderChargeofAbstractCharge.ChargeType.SHIPPINGfor the given values and adds it to the given cart.protected voidensureOrderEntryRAOEntryNumbers(AbstractOrderRAO abstractOrderRao) for the givenAbstractOrderRAOthis method ensures that each of theAbstractOrderRAO.getEntries()has a entry number set.protected OrderEntryRAOfindOrderEntryRAO(AbstractOrderRAO order, NumberedLineItem lineItem) returns the corresponding OrderEntryRAO for the givenlineItem.protected Converter<AbstractOrderRAO,Order> protected org.apache.commons.lang3.tuple.ImmutableTriple<BigDecimal,BigDecimal, Integer> getBiasDiscountInfoWithCurrency(Currency currency, BigDecimal amount, int appliedToQuantity) protected RAOConsumptionSupportprotected CurrencyUtilsgetCurrentPrice(Set<OrderEntryRAO> orderEntryForDiscounts, Map<Integer, Integer> discountedOrderEntryMap) Calculates current price of the set of Order Entries using only specified quantity of units for every Order Entry.protected NumberedLineItemLookupStrategyprotected MinimumAmountValidationStrategyprotected Populator<ProductModel,OrderEntryRAO> protected OrderUtilsprotected RaoUtilsprotected voidrecalculateTotals(AbstractOrderRAO cartRao, Order cart) Uses the givencartto recalculate the totals of the givencartRao.protected voidremoveShippingCharges(Order cart) Returns all Shipping charges from the Order.voidsetAbstractOrderRaoToOrderConverter(Converter<AbstractOrderRAO, Order> abstractOrderRaoToOrderConverter) voidsetConsumptionSupport(RAOConsumptionSupport consumptionSupport) voidsetCurrencyUtils(CurrencyUtils currencyUtils) voidsetLineItemLookupStrategy(NumberedLineItemLookupStrategy lineItemLookupStrategy) voidsetMinimumAmountValidationStrategy(MinimumAmountValidationStrategy minimumAmountValidationStrategy) voidsetOrderEntryRaoProductPopulator(Populator<ProductModel, OrderEntryRAO> orderEntryRaoProductPopulator) voidsetOrderUtils(OrderUtils orderUtils) voidsetRaoUtils(RaoUtils raoUtils) protected LineItemDiscountvalidateLineItemDiscount(LineItem lineItem, boolean absolute, Currency currency, LineItemDiscount discount)
-
Field Details
-
CART_NULL_DESC
- See Also:
-
AMOUNT_NULL_DESC
- See Also:
-
-
Constructor Details
-
DefaultRuleEngineCalculationService
public DefaultRuleEngineCalculationService()
-
-
Method Details
-
addOrderLevelDiscount
creates a DiscountRAO for the given CartRAO based on the input. Adds the discount to the cart RAO and recalculates the totals of the given CartRAO. The absolute parameter determines if the discount is an absolute one or a percentage based one. If absolute is set to false, the amount is read as an percent value, e.g. 10 for 10% (and not 0.1 for 10%)- Specified by:
addOrderLevelDiscountin interfaceRuleEngineCalculationService- Parameters:
cartRao- the cartRAOabsolute- whether the discount is absolute or a percentage discountamount- the amount- Returns:
- the created and linked DiscountRAO
-
getCurrentPrice
public BigDecimal getCurrentPrice(Set<OrderEntryRAO> orderEntryForDiscounts, Map<Integer, Integer> discountedOrderEntryMap) Description copied from interface:RuleEngineCalculationServiceCalculates current price of the set of Order Entries using only specified quantity of units for every Order Entry.- Specified by:
getCurrentPricein interfaceRuleEngineCalculationService- Parameters:
orderEntryForDiscounts- set with Order Entries which price need to be calculateddiscountedOrderEntryMap- Map having orderEntry.entryNumber as keys and Unit Quantity To Be Consumed as values- Returns:
- BigDecimal current price
-
addOrderEntryLevelDiscount
public DiscountRAO addOrderEntryLevelDiscount(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount) creates a DiscountRAO for the given OrderEntryRAO based on the input. Adds the discount to the order entry RAO and recalculates the totals of the corresponding CartRAO. The absolute parameter determines if the discount is an absolute one or a percentage based one. If absolute is set to false, the amount is read as an percent value, e.g. 10 for 10% (and not 0.1 for 10%)- Specified by:
addOrderEntryLevelDiscountin interfaceRuleEngineCalculationService- Parameters:
orderEntryRao- the orderEntryRaoabsolute- whether the discount is absolute or a percentage discountamount- the amount- Returns:
- the created and linked DiscountRAO
-
addOrderEntryLevelDiscount
protected DiscountRAO addOrderEntryLevelDiscount(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount, int consumedQty) -
addOrderEntryLevelDiscount
public Set<DiscountRAO> addOrderEntryLevelDiscount(OrderEntryRAO orderEntryRAO, boolean absolute, BigDecimal amount, boolean perUnit) Description copied from interface:RuleEngineCalculationServiceCreate a set of order entry level discounts based on the given value, absolute flag and perUnit flag, adds it to the corresponding orderRao and updates the orderRao totals. If theabsoluteflag is set to true, the discount is absolute, otherwise it's a percentage based discount. If theperUnitflag is set to true, it means give discount on each product of order entry, If theperUnitflag is set to false, it means give discount to the whole order entry- Specified by:
addOrderEntryLevelDiscountin interfaceRuleEngineCalculationService- Parameters:
orderEntryRAO- the orderEntryRao to add the discount toabsolute- whether the discount is absolute or percentage-basedamount- the amount of the discountperUnit- whether the discount is given to each product of order entry or the whole order entry- Returns:
- the created DiscountRAO set
-
addOrderEntryLevelDiscountWithPerUnitFlag
protected Set<DiscountRAO> addOrderEntryLevelDiscountWithPerUnitFlag(OrderEntryRAO orderEntryRao, boolean absolute, BigDecimal amount, int consumedQty, boolean perUnit) -
addFixedPriceEntryDiscount
Description copied from interface:RuleEngineCalculationServiceCreates a new order entry level discount such that the order entry's price will be equal to the givenfixedPricemultiplied by quantity.- Specified by:
addFixedPriceEntryDiscountin interfaceRuleEngineCalculationService- Parameters:
orderEntryRao- the orderEntryRao to add the discount tofixedPrice- the target unit price- Returns:
- the created DiscountRAO
-
addFreeProductsToCart
Description copied from interface:RuleEngineCalculationServiceAdds free product items to the cart.- Specified by:
addFreeProductsToCartin interfaceRuleEngineCalculationService- Parameters:
cartRao- cart where to add the productproduct- a product to addquantity- quantity of product items to add- Returns:
- FreeProductRAO the free product to be given
-
ensureOrderEntryRAOEntryNumbers
for the givenAbstractOrderRAOthis method ensures that each of theAbstractOrderRAO.getEntries()has a entry number set. Note: This method only setsOrderEntryRAO#setEntryNumber(Integer)if it is not yet set, it does not check for duplicates or any other inconsistencies.- Parameters:
abstractOrderRao- the AbstractOrderRAO to check
-
changeDeliveryMode
Description copied from interface:RuleEngineCalculationServiceChanges the current delivery mode to the given values, adds it to the cartRao and updates the carRao totals.- Specified by:
changeDeliveryModein interfaceRuleEngineCalculationService- Parameters:
cartRao- the cartRao to change the delivery mode formode- the new delivery mode- Returns:
- the ShipmentRAO
-
calculateTotals
Description copied from interface:RuleEngineCalculationServiceperforms a (re)calculation on the given abstractOrderRao and updates these properties:- Specified by:
calculateTotalsin interfaceRuleEngineCalculationService- Parameters:
cartRao- the abstractOrderRao to calculate
-
findOrderEntryRAO
returns the corresponding OrderEntryRAO for the givenlineItem. The lookup is based on both having the sameentryNumber.- Parameters:
order- the order to look up the order entry rao fromlineItem- the line item- Returns:
- the corresponding OrderEntryRAP or null if none is found
-
recalculateTotals
Uses the givencartto recalculate the totals of the givencartRao.- Parameters:
cartRao- the cartRao to updatecart- the cart to use for calculation
-
createOrderDiscount
Creates an OrderDiscount based on the given values and adds it to the givencart.- Parameters:
cart- the cart to add the order discount toabsolute- whether the discount is absolute or percentage basedamount- the amount- Returns:
- the created OrderDiscount
-
createDiscountRAO
Creates a new DiscountRAO based on the given AbstractDiscount.- Parameters:
discount- the discount- Returns:
- a new DiscountRAO
-
createLineItemDiscount
protected LineItemDiscount createLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount, boolean perUnit) Creates an LineItemDiscount based on the given values and adds it to the givenlineItem. Sets perUnit value for partial line discounts- Parameters:
lineItem- the line item to add the order discount toabsolute- whether the discount is absolute or percentage basedamount- the amountperUnit- true if the discount does not necessarily apply to whole line item- Returns:
- the created OrderDiscount
-
createLineItemDiscount
protected LineItemDiscount createLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount, boolean perUnit, int applicableUnits) -
validateLineItemDiscount
protected LineItemDiscount validateLineItemDiscount(LineItem lineItem, boolean absolute, Currency currency, LineItemDiscount discount) -
createLineItemDiscount
protected LineItemDiscount createLineItemDiscount(LineItem lineItem, boolean absolute, BigDecimal amount) Creates an LineItemDiscount based on the given values and adds it to the givenlineItem.- Parameters:
lineItem- the line item to add the order discount toabsolute- whether the discount is absolute or percentage basedamount- the amount- Returns:
- the created OrderDiscount
-
removeShippingCharges
Returns all Shipping charges from the Order.- Parameters:
cart- instance ofOrder
-
createShippingCharge
creates anOrderChargeofAbstractCharge.ChargeType.SHIPPINGfor the given values and adds it to the given cart.- Parameters:
cart- the given cart to apply the shipping charge toabsolute- whether the shipping charge is percentage-based or absolute.value- the value of the charge- Returns:
- the newly created OrderCharge
-
createShipmentRAO
Creates a new ShipmentRAO based on the given Delivery Mode. -
getAbstractOrderRaoToOrderConverter
-
setAbstractOrderRaoToOrderConverter
public void setAbstractOrderRaoToOrderConverter(Converter<AbstractOrderRAO, Order> abstractOrderRaoToOrderConverter) -
addFixedPriceEntriesDiscount
public List<DiscountRAO> addFixedPriceEntriesDiscount(CartRAO cartRao, Map<Integer, Integer> selectedOrderEntryMap, Set<OrderEntryRAO> selectedOrderEntryRaos, BigDecimal fixedPrice) Description copied from interface:RuleEngineCalculationServiceCreates order entry level discounts for the cartcartRao, with thefixedPricegiven as parameter and for the products from entries inselectedOrderEntryRaosand related quantities given inselectedOrderEntryMap.- Specified by:
addFixedPriceEntriesDiscountin interfaceRuleEngineCalculationService- Parameters:
cartRao- Cart RAO used for totals calculationsselectedOrderEntryMap- Map having orderEntry.entryNumber as keys and unit quantity to be consumed as valuesselectedOrderEntryRaos- Order entries to be discountedfixedPrice- Target price for discounted product- Returns:
- List of discounts that are generated
-
createAbsoluteDiscountRAO
protected DiscountRAO createAbsoluteDiscountRAO(LineItem lineItem, BigDecimal amount, int applicableUnits, boolean perUnit) -
createAbsoluteDiscountRAO
protected Set<DiscountRAO> createAbsoluteDiscountRAO(LineItem lineItem, BigDecimal amount, int applicableUnits) -
getBiasDiscountInfoWithCurrency
protected org.apache.commons.lang3.tuple.ImmutableTriple<BigDecimal,BigDecimal, getBiasDiscountInfoWithCurrencyInteger> (Currency currency, BigDecimal amount, int appliedToQuantity) -
addOrderEntryLevelDiscount
public List<DiscountRAO> addOrderEntryLevelDiscount(Map<Integer, Integer> selectedOrderEntryMap, Set<OrderEntryRAO> selectedOrderEntryRaos, boolean absolute, BigDecimal amount) Description copied from interface:RuleEngineCalculationServiceCreates order entry level discounts for the cartcartRao, adds it to the cartRao and updates the cartRao totals. Discounts are applied to entries contained within the selectedOrderEntryMapselectedOrderEntryRaosbased on strategy.- Specified by:
addOrderEntryLevelDiscountin interfaceRuleEngineCalculationService- Parameters:
selectedOrderEntryMap- Map having orderEntry.entryNumber as keys and unit quantity to be consumed as valuesselectedOrderEntryRaos- Order entries to be discountedabsolute- boolean value true is discount is absolute currency amountamount- value of discount- Returns:
- List of discounts created as a result of this action
-
convertPercentageDiscountToAbsoluteDiscount
protected BigDecimal convertPercentageDiscountToAbsoluteDiscount(BigDecimal percentageAmount, int quantityToConsume, NumberedLineItem orderLineItem) -
convertPercentageDiscountToAbsoluteDiscount
protected BigDecimal convertPercentageDiscountToAbsoluteDiscount(BigDecimal percentageAmount, Order cart) -
getMinimumAmountValidationStrategy
-
setMinimumAmountValidationStrategy
public void setMinimumAmountValidationStrategy(MinimumAmountValidationStrategy minimumAmountValidationStrategy) -
getOrderUtils
-
setOrderUtils
-
getCurrencyUtils
-
setCurrencyUtils
-
getRaoUtils
-
setRaoUtils
-
getConsumptionSupport
-
setConsumptionSupport
-
getLineItemLookupStrategy
-
setLineItemLookupStrategy
-
getOrderEntryRaoProductPopulator
-
setOrderEntryRaoProductPopulator
public void setOrderEntryRaoProductPopulator(Populator<ProductModel, OrderEntryRAO> orderEntryRaoProductPopulator)
-