@Test public void testGetAvailabilityModelNoInventory() throws Exception { final BigDecimal qty = BigDecimal.ZERO; setTestExpectationsNoInventory(); final ProductAvailabilityModel modelProduct = new ProductAvailabilityStrategyDefaultImpl(warehouseService, inventoryResolver).getAvailabilityModel(shopId, product, supplier); assertNotNull(modelProduct); assertNull(modelProduct.getDefaultSkuCode()); assertEquals(SkuWarehouse.AVAILABILITY_NA, modelProduct.getAvailability()); assertFalse(modelProduct.isAvailable()); assertFalse(modelProduct.isInStock()); assertFalse(modelProduct.isPerpetual()); assertNull(modelProduct.getReleaseDate()); assertTrue(modelProduct.getAvailableToSellQuantity(skuCode).compareTo(qty) == 0); final ProductAvailabilityModel modelSku = new ProductAvailabilityStrategyDefaultImpl(warehouseService, inventoryResolver).getAvailabilityModel(shopId, sku, supplier); assertNotNull(modelSku); assertEquals(skuCode, modelSku.getDefaultSkuCode()); assertEquals(SkuWarehouse.AVAILABILITY_NA, modelSku.getAvailability()); assertFalse(modelSku.isAvailable()); assertFalse(modelSku.isInStock()); assertFalse(modelSku.isPerpetual()); assertNull(modelSku.getReleaseDate()); assertTrue(modelSku.getAvailableToSellQuantity(skuCode).compareTo(qty) == 0); context.assertIsSatisfied(); }
@Override public ProductAvailabilityModel getAvailabilityModel(final long shopId, final Product product, final String supplier) { final Map<String, BigDecimal> qty = new HashMap<>(); final Map<String, Warehouse> warehouses = warehouseService.getByShopIdMapped(shopId, false); if (!warehouses.isEmpty()) { final Warehouse warehouse = StringUtils.isBlank(supplier) ? warehouses.values().iterator().next() : warehouses.get(supplier); final SortedMap<Integer, SkuWarehouse> rankedInventory = new TreeMap<>(); if (warehouse != null) { for (final ProductSku sku : product.getSku()) { final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, sku.getCode()); if (inventory != null) { rankedInventory.put(sku.getRank(), inventory); qty.put(inventory.getSkuCode(), inventory.getAvailableToSell()); } } } if (!rankedInventory.isEmpty()) { for (final SkuWarehouse first : rankedInventory.values()) { final boolean availableNow = isAvailableNow( first.getAvailability(), !first.isDisabled(), first.getAvailablefrom(), first.getAvailableto(), first.getReleaseDate(), qty ); return new ProductAvailabilityModelImpl( warehouse.getCode(), first.getSkuCode(), first.getAvailability(), availableNow, first.getReleaseDate(), qty, first.getRestockDate(), first.getRestockNote() ); } } } return new ProductAvailabilityModelImpl( supplier, null, SkuWarehouse.AVAILABILITY_NA, false, null, qty, null, null ); }
ProductAvailabilityStrategyDefaultImpl implements ProductAvailabilityStrategy, Configuration { @Override public ProductAvailabilityModel getAvailabilityModel(final long shopId, final Product product, final String supplier) { final Map<String, BigDecimal> qty = new HashMap<>(); final Map<String, Warehouse> warehouses = warehouseService.getByShopIdMapped(shopId, false); if (!warehouses.isEmpty()) { final Warehouse warehouse = StringUtils.isBlank(supplier) ? warehouses.values().iterator().next() : warehouses.get(supplier); final SortedMap<Integer, SkuWarehouse> rankedInventory = new TreeMap<>(); if (warehouse != null) { for (final ProductSku sku : product.getSku()) { final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, sku.getCode()); if (inventory != null) { rankedInventory.put(sku.getRank(), inventory); qty.put(inventory.getSkuCode(), inventory.getAvailableToSell()); } } } if (!rankedInventory.isEmpty()) { for (final SkuWarehouse first : rankedInventory.values()) { final boolean availableNow = isAvailableNow( first.getAvailability(), !first.isDisabled(), first.getAvailablefrom(), first.getAvailableto(), first.getReleaseDate(), qty ); return new ProductAvailabilityModelImpl( warehouse.getCode(), first.getSkuCode(), first.getAvailability(), availableNow, first.getReleaseDate(), qty, first.getRestockDate(), first.getRestockNote() ); } } } return new ProductAvailabilityModelImpl( supplier, null, SkuWarehouse.AVAILABILITY_NA, false, null, qty, null, null ); } }
ProductAvailabilityStrategyDefaultImpl implements ProductAvailabilityStrategy, Configuration { @Override public ProductAvailabilityModel getAvailabilityModel(final long shopId, final Product product, final String supplier) { final Map<String, BigDecimal> qty = new HashMap<>(); final Map<String, Warehouse> warehouses = warehouseService.getByShopIdMapped(shopId, false); if (!warehouses.isEmpty()) { final Warehouse warehouse = StringUtils.isBlank(supplier) ? warehouses.values().iterator().next() : warehouses.get(supplier); final SortedMap<Integer, SkuWarehouse> rankedInventory = new TreeMap<>(); if (warehouse != null) { for (final ProductSku sku : product.getSku()) { final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, sku.getCode()); if (inventory != null) { rankedInventory.put(sku.getRank(), inventory); qty.put(inventory.getSkuCode(), inventory.getAvailableToSell()); } } } if (!rankedInventory.isEmpty()) { for (final SkuWarehouse first : rankedInventory.values()) { final boolean availableNow = isAvailableNow( first.getAvailability(), !first.isDisabled(), first.getAvailablefrom(), first.getAvailableto(), first.getReleaseDate(), qty ); return new ProductAvailabilityModelImpl( warehouse.getCode(), first.getSkuCode(), first.getAvailability(), availableNow, first.getReleaseDate(), qty, first.getRestockDate(), first.getRestockNote() ); } } } return new ProductAvailabilityModelImpl( supplier, null, SkuWarehouse.AVAILABILITY_NA, false, null, qty, null, null ); } ProductAvailabilityStrategyDefaultImpl(final WarehouseService warehouseService,
                                                  final InventoryResolver inventoryResolver); }
ProductAvailabilityStrategyDefaultImpl implements ProductAvailabilityStrategy, Configuration { @Override public ProductAvailabilityModel getAvailabilityModel(final long shopId, final Product product, final String supplier) { final Map<String, BigDecimal> qty = new HashMap<>(); final Map<String, Warehouse> warehouses = warehouseService.getByShopIdMapped(shopId, false); if (!warehouses.isEmpty()) { final Warehouse warehouse = StringUtils.isBlank(supplier) ? warehouses.values().iterator().next() : warehouses.get(supplier); final SortedMap<Integer, SkuWarehouse> rankedInventory = new TreeMap<>(); if (warehouse != null) { for (final ProductSku sku : product.getSku()) { final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, sku.getCode()); if (inventory != null) { rankedInventory.put(sku.getRank(), inventory); qty.put(inventory.getSkuCode(), inventory.getAvailableToSell()); } } } if (!rankedInventory.isEmpty()) { for (final SkuWarehouse first : rankedInventory.values()) { final boolean availableNow = isAvailableNow( first.getAvailability(), !first.isDisabled(), first.getAvailablefrom(), first.getAvailableto(), first.getReleaseDate(), qty ); return new ProductAvailabilityModelImpl( warehouse.getCode(), first.getSkuCode(), first.getAvailability(), availableNow, first.getReleaseDate(), qty, first.getRestockDate(), first.getRestockNote() ); } } } return new ProductAvailabilityModelImpl( supplier, null, SkuWarehouse.AVAILABILITY_NA, false, null, qty, null, null ); } ProductAvailabilityStrategyDefaultImpl(final WarehouseService warehouseService,
                                                  final InventoryResolver inventoryResolver); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final Product product,
                                                         final String supplier); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSearchResultDTO product); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSku sku,
                                                         final String supplier); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSkuSearchResultDTO sku); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final String skuCode,
                                                         final String supplier); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext); }
ProductAvailabilityStrategyDefaultImpl implements ProductAvailabilityStrategy, Configuration { @Override public ProductAvailabilityModel getAvailabilityModel(final long shopId, final Product product, final String supplier) { final Map<String, BigDecimal> qty = new HashMap<>(); final Map<String, Warehouse> warehouses = warehouseService.getByShopIdMapped(shopId, false); if (!warehouses.isEmpty()) { final Warehouse warehouse = StringUtils.isBlank(supplier) ? warehouses.values().iterator().next() : warehouses.get(supplier); final SortedMap<Integer, SkuWarehouse> rankedInventory = new TreeMap<>(); if (warehouse != null) { for (final ProductSku sku : product.getSku()) { final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, sku.getCode()); if (inventory != null) { rankedInventory.put(sku.getRank(), inventory); qty.put(inventory.getSkuCode(), inventory.getAvailableToSell()); } } } if (!rankedInventory.isEmpty()) { for (final SkuWarehouse first : rankedInventory.values()) { final boolean availableNow = isAvailableNow( first.getAvailability(), !first.isDisabled(), first.getAvailablefrom(), first.getAvailableto(), first.getReleaseDate(), qty ); return new ProductAvailabilityModelImpl( warehouse.getCode(), first.getSkuCode(), first.getAvailability(), availableNow, first.getReleaseDate(), qty, first.getRestockDate(), first.getRestockNote() ); } } } return new ProductAvailabilityModelImpl( supplier, null, SkuWarehouse.AVAILABILITY_NA, false, null, qty, null, null ); } ProductAvailabilityStrategyDefaultImpl(final WarehouseService warehouseService,
                                                  final InventoryResolver inventoryResolver); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final Product product,
                                                         final String supplier); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSearchResultDTO product); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSku sku,
                                                         final String supplier); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final ProductSkuSearchResultDTO sku); @Override ProductAvailabilityModel getAvailabilityModel(final long shopId,
                                                         final String skuCode,
                                                         final String supplier); @Override ConfigurationContext getCfgContext(); void setCfgContext(final ConfigurationContext cfgContext);  }