Class DefaultStockService

java.lang.Object
de.hybris.platform.stock.impl.DefaultStockService
All Implemented Interfaces:
StockService

public class DefaultStockService extends Object implements StockService
Default implementation of StockService.
  • Constructor Details

    • DefaultStockService

      public DefaultStockService()
  • Method Details

    • getProductStatus

      public StockLevelStatus getProductStatus(ProductModel product, WarehouseModel warehouse)
      Description copied from interface: StockService
      Checks the stock level status of the product in the specified warehouse.
      Specified by:
      getProductStatus in interface StockService
      Parameters:
      product - the product
      warehouse - warehouse of the product
      Returns:
      stock level status
    • getProductStatus

      public StockLevelStatus getProductStatus(ProductModel product, Collection<WarehouseModel> warehouses)
      Description copied from interface: StockService
      Checks the stock level status of the product in all specified warehouses.
      Specified by:
      getProductStatus in interface StockService
      Parameters:
      product - the product
      warehouses - warehouses of the product
      Returns:
      stock level status
    • createStockLevel

      protected StockLevelModel createStockLevel(ProductModel product, WarehouseModel warehouse, int available)
      Creates a new stock level. The created StockLevelModel is saved.
      Parameters:
      product - the product
      warehouse - warehouse of the product
      available - amount of available products
      Returns:
      the created StockLevelModel
    • createStockLevel

      protected StockLevelModel createStockLevel(ProductModel product, WarehouseModel warehouse, int available, int overSelling, int reserved, InStockStatus status, int maxStockLevelHistoryCount, boolean treatNegativeAsZero)
      Creates a new stock level. The created StockLevelModel is saved.
      Parameters:
      product - the product
      warehouse - warehouse of the product
      available - amount of available products
      overSelling - amount of over-selling products
      reserved - amount of reserved products
      status - tag of in stock, out of stock, or not specified
      maxStockLevelHistoryCount - max count of StockLevelHistoryEntryModel, negative value for unlimited
      treatNegativeAsZero - true if negative stock level is treated as zero
      Returns:
      the created StockLevelModel
    • createStockLevelHistoryEntry

      protected StockLevelHistoryEntryModel createStockLevelHistoryEntry(StockLevelModel stockLevel, int actual, int reserved, StockLevelUpdateType updateType, String comment)
      Creates a new stock level history entry. The created StockLevelHistoryEntryModel is saved.
      Parameters:
      stockLevel - the stock level whose history entry should be created
      actual - the actual amount
      reserved - the reserved amount
      updateType - the update type
      comment - the comment
      Returns:
      the created StockLevelHistoryEntryModel
    • getStockLevelAmount

      public int getStockLevelAmount(ProductModel product, WarehouseModel warehouse)
      Description copied from interface: StockService
      Finds the stock level of the specified product in the specified warehouse, and calculates the actual available amount.
      Specified by:
      getStockLevelAmount in interface StockService
      Parameters:
      product - the product
      warehouse - warehouse of the product
      Returns:
      actual available amount for the specific product
    • getTotalStockLevelAmount

      public int getTotalStockLevelAmount(ProductModel product)
      Description copied from interface: StockService
      Finds the stock levels of the specified product from all warehouses, and calculates the total actual amount.
      Specified by:
      getTotalStockLevelAmount in interface StockService
      Parameters:
      product - the product
      Returns:
      calculated actual amount of the specified product
    • getTotalStockLevelAmount

      public int getTotalStockLevelAmount(ProductModel product, Collection<WarehouseModel> warehouses)
      Description copied from interface: StockService
      Finds all stock levels of the specified product in the specified warehouses, and calculates the total actual amount.
      Specified by:
      getTotalStockLevelAmount in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      Returns:
      calculated actual amount of the specified product in the warehouses
    • setInStockStatus

      public void setInStockStatus(ProductModel product, Collection<WarehouseModel> warehouses, InStockStatus status)
      Description copied from interface: StockService
      Sets the in stock status of all stock levels of the product in the specified warehouses.
      Specified by:
      setInStockStatus in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      status - the in stock status
    • getInStockStatus

      public InStockStatus getInStockStatus(ProductModel product, WarehouseModel warehouse)
      Description copied from interface: StockService
      Checks the stock level status of the product in the specified warehouses.
      Specified by:
      getInStockStatus in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse
      Returns:
      the in stock status
    • reserve

      public void reserve(ProductModel product, WarehouseModel warehouse, int amount, String comment) throws InsufficientStockLevelException
      Description copied from interface: StockService
      Reserves the product in the specified warehouse.
      Specified by:
      reserve in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse where product is 'stored'
      amount - the amount of the reservation
      comment - the comment for the reservation
      Throws:
      InsufficientStockLevelException - if not enough products are available in the stock
    • release

      public void release(ProductModel product, WarehouseModel warehouse, int amount, String comment)
      Description copied from interface: StockService
      Release the product in the specified warehouse.
      Specified by:
      release in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse where product is 'stored'
      amount - the amount of the release
      comment - the comment for the release
    • updateActualStockLevel

      public void updateActualStockLevel(ProductModel product, WarehouseModel warehouse, int actualAmount, String comment)
      Description copied from interface: StockService
      Updates the actual stock level of the specified product in the specified warehouse.
      Specified by:
      updateActualStockLevel in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse where product is 'stored'
      actualAmount - the actual amount of the product
      comment - the comment for the update operation
    • getAvailability

      public Map<WarehouseModel,Integer> getAvailability(List<WarehouseModel> warehouses, ProductModel product, Date date)
      Gets the product quantity for the specified product, warehouses and date.
      Specified by:
      getAvailability in interface StockService
      Parameters:
      warehouses - the warehouses
      product - the product
      date - the date the specified quantity has to be available at least.
      Returns:
      Returns the mapped quantity
    • getAvailability

      public Map<WarehouseModel,Date> getAvailability(List<WarehouseModel> warehouses, ProductModel product, int quantity)
      Returns product availability, passing product, and quantity as parameters
      Specified by:
      getAvailability in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      quantity - the asked quantity
      Returns:
      Returns the mapped availability date
    • getAvailability

      public String getAvailability(ProductModel product, WarehouseModel warehouse, Date date, LanguageModel language)
      Description copied from interface: StockService
      Gets the available quantity of the product for the specified warehouse.
      Specified by:
      getAvailability in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse
      date - the date the specified quantity has to be available at least (could be null).
      language - language for which the text should be localized
      Returns:
      the configured availability text message
    • getAvailability

      public String getAvailability(ProductModel product, List<WarehouseModel> warehouses, Date date, LanguageModel language)
      Gets the available quantity of the product for the specified warehouses by invoking injected strategy. Configuration:
        
                      
        
       
      Specified by:
      getAvailability in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      date - the date the specified quantity has to be available at least (could be null).
      language - language for which the text should be localized
      Returns:
      Returns a configured availability text message
    • getAvailability

      public String getAvailability(ProductModel product, WarehouseModel warehouse, int quantity, LanguageModel language)
      Description copied from interface: StockService
      Gets availability date by invoking strategy for calculating product availability, passing product, quantity and warehouse as parameters.
      Specified by:
      getAvailability in interface StockService
      Parameters:
      product - the product
      warehouse - the warehouse
      quantity - the asked quantity
      language - language for which the text should be localized
      Returns:
      String the configured availability text message
    • getAvailability

      public String getAvailability(ProductModel product, List<WarehouseModel> warehouses, int quantity, LanguageModel language)
      Gets availability date by invoking strategy for calculating product availability, passing product, quantity and warehouses as parameters by invoking injected strategy. Configuration:
        
                      
        
       
      Specified by:
      getAvailability in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      quantity - the asked quantity
      language - language for which the text should be localized
      Returns:
      Returns a configured availability text message
    • getBestMatchOfQuantity

      public WarehouseModel getBestMatchOfQuantity(Map<WarehouseModel,Integer> map)
      Returns the warehouse which offers the "best" product "quantity" by invoking injected strategy.
      Configuration:
       
              
       
      
       
              
       
      
       
       
       
      Specified by:
      getBestMatchOfQuantity in interface StockService
      Parameters:
      map - the mapped quantities of a certain product
      Returns:
      WarehouseModel best match
    • getBestMatchOfAvailability

      public WarehouseModel getBestMatchOfAvailability(Map<WarehouseModel,Date> map)
      Returns the warehouse which offers the "best" product "availability" by invoking injected strategy.
      Configuration:
       
              
       
      
       
              
       
      
       
       
       
      Specified by:
      getBestMatchOfAvailability in interface StockService
      Parameters:
      map - the mapped available dates of a certain product
      Returns:
      WarehouseModel best match
    • getStockLevel

      public StockLevelModel getStockLevel(ProductModel product, WarehouseModel warehouse)
      Description copied from interface: StockService
      Finds the stock level of the specified product at the specified warehouse.
      Specified by:
      getStockLevel in interface StockService
      Parameters:
      product - the product
      warehouse - warehouse of the product
      Returns:
      found stock level, and null if no such stock level can be found.
    • getAllStockLevels

      public Collection<StockLevelModel> getAllStockLevels(ProductModel product)
      Description copied from interface: StockService
      Finds the stock levels of the specified product from all warehouses.
      Specified by:
      getAllStockLevels in interface StockService
      Parameters:
      product - the product
      Returns:
      all found stock levels of product
    • getStockLevels

      public Collection<StockLevelModel> getStockLevels(ProductModel product, Collection<WarehouseModel> warehouses)
      Description copied from interface: StockService
      Finds all stock levels of the specified product in the specified warehouses.
      Specified by:
      getStockLevels in interface StockService
      Parameters:
      product - the product
      warehouses - the warehouses
      Returns:
      found stock levels of the product
    • getModelService

      protected ModelService getModelService()
    • setModelService

      public void setModelService(ModelService modelService)
    • getStockLevelDao

      protected StockLevelDao getStockLevelDao()
    • setStockLevelDao

      public void setStockLevelDao(StockLevelDao stockLevelDao)
    • getStockLevelStatusStrategy

      protected StockLevelStatusStrategy getStockLevelStatusStrategy()
    • setStockLevelStatusStrategy

      public void setStockLevelStatusStrategy(StockLevelStatusStrategy stockLevelStatusStrategy)
    • getProductAvailabilityStrategy

      protected ProductAvailabilityStrategy getProductAvailabilityStrategy()
    • setProductAvailabilityStrategy

      public void setProductAvailabilityStrategy(ProductAvailabilityStrategy productAvailabilityStrategy)
      The injected strategy will be used for calculating the availability of the specified product.
      Parameters:
      productAvailabilityStrategy - the productAvailabilityStrategy to set
    • getStockLevelProductStrategy

      protected StockLevelProductStrategy getStockLevelProductStrategy()
    • setStockLevelProductStrategy

      public void setStockLevelProductStrategy(StockLevelProductStrategy stockLevelProductStrategy)