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 Details

  • Constructor Details

    • DefaultRuleEngineCalculationService

      public DefaultRuleEngineCalculationService()
  • Method Details

    • addOrderLevelDiscount

      public DiscountRAO addOrderLevelDiscount(CartRAO cartRao, boolean absolute, BigDecimal amount)
      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:
      addOrderLevelDiscount in interface RuleEngineCalculationService
      Parameters:
      cartRao - the cartRAO
      absolute - whether the discount is absolute or a percentage discount
      amount - the amount
      Returns:
      the created and linked DiscountRAO
    • getCurrentPrice

      public BigDecimal getCurrentPrice(Set<OrderEntryRAO> orderEntryForDiscounts, Map<Integer,Integer> discountedOrderEntryMap)
      Description copied from interface: RuleEngineCalculationService
      Calculates current price of the set of Order Entries using only specified quantity of units for every Order Entry.
      Specified by:
      getCurrentPrice in interface RuleEngineCalculationService
      Parameters:
      orderEntryForDiscounts - set with Order Entries which price need to be calculated
      discountedOrderEntryMap - 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:
      addOrderEntryLevelDiscount in interface RuleEngineCalculationService
      Parameters:
      orderEntryRao - the orderEntryRao
      absolute - whether the discount is absolute or a percentage discount
      amount - 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: RuleEngineCalculationService
      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. If the absolute flag is set to true, the discount is absolute, otherwise it's a percentage based discount. If the perUnit flag is set to true, it means give discount on each product of order entry, If the perUnit flag is set to false, it means give discount to the whole order entry
      Specified by:
      addOrderEntryLevelDiscount in interface RuleEngineCalculationService
      Parameters:
      orderEntryRAO - the orderEntryRao to add the discount to
      absolute - whether the discount is absolute or percentage-based
      amount - the amount of the discount
      perUnit - 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

      public DiscountRAO addFixedPriceEntryDiscount(OrderEntryRAO orderEntryRao, BigDecimal fixedPrice)
      Description copied from interface: RuleEngineCalculationService
      Creates a new order entry level discount such that the order entry's price will be equal to the given fixedPrice multiplied by quantity.
      Specified by:
      addFixedPriceEntryDiscount in interface RuleEngineCalculationService
      Parameters:
      orderEntryRao - the orderEntryRao to add the discount to
      fixedPrice - the target unit price
      Returns:
      the created DiscountRAO
    • addFreeProductsToCart

      public FreeProductRAO addFreeProductsToCart(CartRAO cartRao, ProductModel product, int quantity)
      Description copied from interface: RuleEngineCalculationService
      Adds free product items to the cart.
      Specified by:
      addFreeProductsToCart in interface RuleEngineCalculationService
      Parameters:
      cartRao - cart where to add the product
      product - a product to add
      quantity - quantity of product items to add
      Returns:
      FreeProductRAO the free product to be given
    • ensureOrderEntryRAOEntryNumbers

      protected void ensureOrderEntryRAOEntryNumbers(AbstractOrderRAO abstractOrderRao)
      for the given AbstractOrderRAO this method ensures that each of the AbstractOrderRAO.getEntries() has a entry number set. Note: This method only sets OrderEntryRAO#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

      public ShipmentRAO changeDeliveryMode(CartRAO cartRao, DeliveryModeRAO mode)
      Description copied from interface: RuleEngineCalculationService
      Changes the current delivery mode to the given values, adds it to the cartRao and updates the carRao totals.
      Specified by:
      changeDeliveryMode in interface RuleEngineCalculationService
      Parameters:
      cartRao - the cartRao to change the delivery mode for
      mode - the new delivery mode
      Returns:
      the ShipmentRAO
    • calculateTotals

      public void calculateTotals(AbstractOrderRAO cartRao)
      Description copied from interface: RuleEngineCalculationService
      performs a (re)calculation on the given abstractOrderRao and updates these properties:
      Specified by:
      calculateTotals in interface RuleEngineCalculationService
      Parameters:
      cartRao - the abstractOrderRao to calculate
    • findOrderEntryRAO

      protected OrderEntryRAO findOrderEntryRAO(AbstractOrderRAO order, NumberedLineItem lineItem)
      returns the corresponding OrderEntryRAO for the given lineItem. The lookup is based on both having the same entryNumber.
      Parameters:
      order - the order to look up the order entry rao from
      lineItem - the line item
      Returns:
      the corresponding OrderEntryRAP or null if none is found
    • recalculateTotals

      protected void recalculateTotals(AbstractOrderRAO cartRao, Order cart)
      Uses the given cart to recalculate the totals of the given cartRao.
      Parameters:
      cartRao - the cartRao to update
      cart - the cart to use for calculation
    • createOrderDiscount

      protected OrderDiscount createOrderDiscount(Order cart, boolean absolute, BigDecimal amount)
      Creates an OrderDiscount based on the given values and adds it to the given cart.
      Parameters:
      cart - the cart to add the order discount to
      absolute - whether the discount is absolute or percentage based
      amount - the amount
      Returns:
      the created OrderDiscount
    • createDiscountRAO

      protected DiscountRAO createDiscountRAO(AbstractDiscount discount)
      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 given lineItem. Sets perUnit value for partial line discounts
      Parameters:
      lineItem - the line item to add the order discount to
      absolute - whether the discount is absolute or percentage based
      amount - the amount
      perUnit - 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 given lineItem.
      Parameters:
      lineItem - the line item to add the order discount to
      absolute - whether the discount is absolute or percentage based
      amount - the amount
      Returns:
      the created OrderDiscount
    • removeShippingCharges

      protected void removeShippingCharges(Order cart)
      Returns all Shipping charges from the Order.
      Parameters:
      cart - instance of Order
    • createShippingCharge

      protected OrderCharge createShippingCharge(Order cart, boolean absolute, BigDecimal value)
      creates an OrderCharge of AbstractCharge.ChargeType.SHIPPING for the given values and adds it to the given cart.
      Parameters:
      cart - the given cart to apply the shipping charge to
      absolute - whether the shipping charge is percentage-based or absolute.
      value - the value of the charge
      Returns:
      the newly created OrderCharge
    • createShipmentRAO

      protected ShipmentRAO createShipmentRAO(DeliveryModeRAO mode)
      Creates a new ShipmentRAO based on the given Delivery Mode.
    • getAbstractOrderRaoToOrderConverter

      protected Converter<AbstractOrderRAO,Order> 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: RuleEngineCalculationService
      Creates order entry level discounts for the cart cartRao, with the fixedPrice given as parameter and for the products from entries in selectedOrderEntryRaos and related quantities given in selectedOrderEntryMap.
      Specified by:
      addFixedPriceEntriesDiscount in interface RuleEngineCalculationService
      Parameters:
      cartRao - Cart RAO used for totals calculations
      selectedOrderEntryMap - Map having orderEntry.entryNumber as keys and unit quantity to be consumed as values
      selectedOrderEntryRaos - Order entries to be discounted
      fixedPrice - 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,Integer> getBiasDiscountInfoWithCurrency(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: RuleEngineCalculationService
      Creates order entry level discounts for the cart cartRao, adds it to the cartRao and updates the cartRao totals. Discounts are applied to entries contained within the selectedOrderEntryMap selectedOrderEntryRaos based on strategy.
      Specified by:
      addOrderEntryLevelDiscount in interface RuleEngineCalculationService
      Parameters:
      selectedOrderEntryMap - Map having orderEntry.entryNumber as keys and unit quantity to be consumed as values
      selectedOrderEntryRaos - Order entries to be discounted
      absolute - boolean value true is discount is absolute currency amount
      amount - 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

      protected MinimumAmountValidationStrategy getMinimumAmountValidationStrategy()
    • setMinimumAmountValidationStrategy

      public void setMinimumAmountValidationStrategy(MinimumAmountValidationStrategy minimumAmountValidationStrategy)
    • getOrderUtils

      protected OrderUtils getOrderUtils()
    • setOrderUtils

      public void setOrderUtils(OrderUtils orderUtils)
    • getCurrencyUtils

      protected CurrencyUtils getCurrencyUtils()
    • setCurrencyUtils

      public void setCurrencyUtils(CurrencyUtils currencyUtils)
    • getRaoUtils

      protected RaoUtils getRaoUtils()
    • setRaoUtils

      public void setRaoUtils(RaoUtils raoUtils)
    • getConsumptionSupport

      protected RAOConsumptionSupport getConsumptionSupport()
    • setConsumptionSupport

      public void setConsumptionSupport(RAOConsumptionSupport consumptionSupport)
    • getLineItemLookupStrategy

      protected NumberedLineItemLookupStrategy getLineItemLookupStrategy()
    • setLineItemLookupStrategy

      public void setLineItemLookupStrategy(NumberedLineItemLookupStrategy lineItemLookupStrategy)
    • getOrderEntryRaoProductPopulator

      protected Populator<ProductModel,OrderEntryRAO> getOrderEntryRaoProductPopulator()
    • setOrderEntryRaoProductPopulator

      public void setOrderEntryRaoProductPopulator(Populator<ProductModel,OrderEntryRAO> orderEntryRaoProductPopulator)