Interface AbstractOrderService<O extends AbstractOrderModel,​E extends AbstractOrderEntryModel>

    • Method Detail

      • 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:
        java.lang.IllegalArgumentException - if either order or product is null or quantity is negative
        See Also:
        AbstractOrderEntryTypeService.getAbstractOrderEntryType(AbstractOrderModel)
      • 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:
        java.lang.IllegalArgumentException - if either order or product is null or quantity is negative.
        See Also:
        AbstractOrderEntryTypeService.getAbstractOrderEntryType(AbstractOrderModel)
      • 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:
        java.lang.IllegalArgumentException - if either entryType or order or product is null or quantity is negative.
      • clone

        O clone​(ComposedTypeModel orderType,
                ComposedTypeModel entryType,
                AbstractOrderModel original,
                java.lang.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
        java.lang.IllegalArgumentException - if either order is null or number is negative
      • getEntriesForNumber

        java.util.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
        java.lang.IllegalArgumentException - if either order is null or start is negative or start is greater than end
      • getEntriesForProduct

        java.util.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:
        java.lang.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:
        java.lang.IllegalArgumentException - if order 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:
        java.lang.IllegalArgumentException - if either order or discountValue is null.
      • addAllGlobalDiscountValues

        void addAllGlobalDiscountValues​(O order,
                                        java.util.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:
        java.lang.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:
        java.lang.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.