Interface AbstractOrderService<O extends AbstractOrderModel,E extends AbstractOrderEntryModel>

All Known Subinterfaces:
B2BCartService, B2BOrderService, CartService, OrderService
All Known Implementing Classes:
DefaultAbstractOrderService, DefaultAlipayOrderService, DefaultB2BCartService, DefaultB2BOrderService, DefaultCartService, DefaultCartServiceForAccelerator, DefaultChineseOrderService, DefaultOrderService, DefaultWeChatPayOrderService

public interface AbstractOrderService<O extends AbstractOrderModel,E extends AbstractOrderEntryModel>
Abstract interface for services dedicated for handling subtypes of AbstractOrderModel.
Extend this service with a typed interface (like OrderService, or CartService) to obtain a set of it's contract methods for your type (like OrderModel, or CartModel correspondingly).
Default implementation - DefaultAbstractOrderService - provides shared implementation on the AbstractOrderModel.
  • Method Details

    • addNewEntry

      E addNewEntry(O order, ProductModel product, long qty, UnitModel unit)
      Adds a new entry to the given order. The entry type is recognized basing on AbstractOrderEntryTypeService and the spring configuration behind it. When a product already exists, the corresponding entry quantity is increased. If a null Unit is specified, a unit according to given product will be chosen. The new entry is neither saved nor calculated.
      Parameters:
      order - - target order
      product - -product to add, must not be null
      qty - - quantity
      unit - - must not be null
      Returns:
      AbstractOrderEntryModel - newly created order entry
      Throws:
      IllegalArgumentException - if either order or product is null or quantity is negative
      See Also:
    • addNewEntry

      E addNewEntry(O order, ProductModel product, long qty, UnitModel unit, int number, boolean addToPresent)
      Adds a new entry to the given order on the required entry number. The entry type is recognized basing on AbstractOrderEntryTypeService and the spring configuration behind it. The new entry is neither saved nor calculated. If your new entry has caused entries shuffling you may need to call saveOrder(AbstractOrderModel) method in order to persist the changes.
      Parameters:
      order - - target order
      product - -product to add, must not be null
      qty - - quantity
      unit - - must not be null
      number - - entry number of the new entry in the order. Entries are indexed starting from 0. Set number to -1 if you want to append the entry as the last one. You can request any non-negative position.
      addToPresent - - if true an existing entry with matching product and unit will get its quantity increased; otherwise a new entry is created
      Returns:
      AbstractOrderEntryModel - newly created order entry
      Throws:
      IllegalArgumentException - if either order or product is null or quantity is negative.
      See Also:
    • addNewEntry

      AbstractOrderEntryModel addNewEntry(ComposedTypeModel entryType, O order, ProductModel product, long qty, UnitModel unit, int number, boolean addToPresent)
      Adds a new entry of the given ComposedTypeModel to the given order. The new entry is neither saved nor calculated. If your new entry has caused entries shuffling you may need to call saveOrder(AbstractOrderModel) method in order to persist the changes.
      Parameters:
      entryType - - the requested sub-type AbstractOrderEntry
      order - - target order
      product - -product to add, must not be null
      qty - - quantity
      unit - - must not be null
      number - - entry number of the new entry in the order. Entries are indexed starting from 0. Set number to -1 if you want to append the entry as the last one. You can request any non-negative position.
      addToPresent - - if true an existing entry with matching product and unit will get its quantity increased; otherwise a new entry is created
      Returns:
      AbstractOrderEntryModel - newly created order entry
      Throws:
      IllegalArgumentException - if either entryType or order or product is null or quantity is negative.
    • clone

      O clone(ComposedTypeModel orderType, ComposedTypeModel entryType, AbstractOrderModel original, String code)
      Creates new order from given original and change its type and type for entry. Delegates to the specific CloneAbstractOrderStrategy injected strategy. Resulting order remains not persisted.
      Parameters:
      orderType - type of result order (OrderModel will be chosen if null is passed)
      entryType - type of entry (if null will use service to get proper type)
      original - original order
      code - code for new order
      Returns:
      not persisted order model instance.
    • getEntryForNumber

      E getEntryForNumber(O order, int number)
      Returns an order entry with the given AbstractOrderEntryModel.ENTRYNUMBER. The method delegates to data access object and checks the actual persisted order in the data base, not the order state represented by the model.
      Parameters:
      order -
      number -
      Returns:
      AbstractOrderEntryModel
      Throws:
      UnknownIdentifierException - if no entry with the requested number exists
      IllegalArgumentException - if either order is null or number is negative
    • getEntriesForNumber

      List<E> getEntriesForNumber(O order, int start, int end)
      Returns order entries with the given AbstractOrderEntryModel.ENTRYNUMBER. The method delegates to data access object and checks the actual persisted order in the data base, not the order state represented by the model.
      Parameters:
      order -
      start - start of the range
      end - end of the range
      Returns:
      AbstractOrderEntryModel
      Throws:
      UnknownIdentifierException - if no entry from the requested range number exists
      IllegalArgumentException - if either order is null or start is negative or start is greater than end
    • getEntriesForProduct

      List<E> getEntriesForProduct(O order, ProductModel product)
      Returns order entries having the target product. In case is no entry contains the requested product, empty list is returned. The method delegates to data access object and checks the actual persisted order in the data base, not the order state represented by the model.
      Parameters:
      order - - target order
      product - - searched product
      Returns:
      matching order entries
      Throws:
      IllegalArgumentException - if either order or product is null
    • saveOrder

      O saveOrder(O order)

      Persist the model and all it's members and entries within one transaction using SaveAbstractOrderStrategy. After this method call the order and it's entries are refreshed.

      This method is useful if you have added an AbstractOrderEntryModel on the already occupied entryNumber position, which caused order entries shuffling. In other, trivial cases, the regular call to ModelService.save(Object) is sufficient. Please mind that the concrete typed service must allow entries shuffling (like CartService does). Tying to put OrderEntryModel on an occupied entryNumber using OrderService would throw an exception in the first place.

      The method call is delegated to the spring configurable SaveAbstractOrderStrategy.

      Parameters:
      order - - non persisted OrderModel that needs to be persisted.
      Returns:
      persisted OrderModel
      Throws:
      IllegalArgumentException - if order is null.
    • addTotalTaxValue

      void addTotalTaxValue(O order, TaxValue taxValue)
      Convenience method to add a TaxValue to the given order. please note that the order's tax values are overwritten each time CalculationService.calculate(AbstractOrderModel), CalculationService.calculate(AbstractOrderModel, java.util.Date), CalculationService.recalculate(AbstractOrderModel), CalculationService.recalculate(AbstractOrderModel, java.util.Date) is called. Those calls fetch the tax information from the price factory and overwrites the previous state. The content of the AbstractOrderModel.TOTALTAXVALUES represents all tax values introduced by the order entries. After this method call, the order model remains not persisted.
      Parameters:
      taxValue -
      order - target order
      Throws:
      IllegalArgumentException - if either order or taxValue is null.
    • addAllTotalTaxValues

      void addAllTotalTaxValues(O order, List<TaxValue> taxValues)
      Adds a collection of tax values into given order. please note that this field is overwritten each time CalculationService.calculate(AbstractOrderModel), CalculationService.calculate(AbstractOrderModel, java.util.Date), CalculationService.recalculate(AbstractOrderModel), CalculationService.recalculate(AbstractOrderModel, java.util.Date) is called. Those calls fetch the tax information from the price factory and overwrites the previous state. The content of the AbstractOrderModel.TOTALTAXVALUES represents all tax values introduced by the order entries. After this method call, the order model remains not persisted.
      Parameters:
      order - target order
      taxValues - tax values to add
      Throws:
      IllegalArgumentException - if either order or taxValues is null.
    • removeTotalTaxValue

      void removeTotalTaxValue(O order, TaxValue taxValue)
      Removes a tax value from the given order. please note that this field will be overwritten after one of the following method calls: CalculationService.calculate(AbstractOrderModel), CalculationService.calculate(AbstractOrderModel, java.util.Date), CalculationService.recalculate(AbstractOrderModel), CalculationService.recalculate(AbstractOrderModel, java.util.Date) is called. Those calls fetch the tax information from the price factory and overwrites the previous state. The content of the AbstractOrderModel.TOTALTAXVALUES represents all tax values introduced by the order entries. After this method call, the order model remains not persisted.
      Parameters:
      taxValue -
      order - target order
      Throws:
      IllegalArgumentException - if either order or taxValue is null.
    • addGlobalDiscountValue

      void addGlobalDiscountValue(O order, DiscountValue discountValue)
      Adds a global discount value to the given order. Such discount will be treated globally for the whole order rather than for any particular entry. After this method call order remains not persisted. User needs to manually persist and recalculate the order so that the global discount is reflected in the total price.
      Parameters:
      discountValue - discount to add
      order - target order
      Throws:
      IllegalArgumentException - if either order or discountValue is null.
    • addAllGlobalDiscountValues

      void addAllGlobalDiscountValues(O order, List<DiscountValue> discountValues)
      Adds a collection of global discount values to the given order. Such discounts will be treated globally for the whole order rather than for any particular entry. After this method call order remains not persisted. User needs to manually persist and recalculate the order so that the added global discounts are reflected in the total price.
      Parameters:
      discountValues - discount values to add
      order - target order
      Throws:
      IllegalArgumentException - if either order or discountValues is null.
    • removeGlobalDiscountValue

      void removeGlobalDiscountValue(O order, DiscountValue discountValue)
      Removes a global discount value from this order. After this method call order remains not persisted. User needs to manually persist and recalculate the order so that the added global discounts are reflected in the total price.
      Parameters:
      discountValue - discount to remove
      order - target order
      Throws:
      IllegalArgumentException - if either order or discountValue is null.
    • getGlobalDiscountValue

      DiscountValue getGlobalDiscountValue(O order, DiscountValue discountValue)
      Searches for complete discount value (with calculated applied value) object created using given discountValue. Returns null when discount value for given parameter can not be found.