@Test public void testHandleMixedSingleInventorySurplus() throws Exception { String label = assertPgFeatures("testPaymentGateway", false, true, true, true); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "0.00"); CustomerOrder customerOrder = createTestOrder(TestOrderType.MIXED, label, true); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "3.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "4.00"); assertTrue(customerOrder.getDelivery().size() == 1); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_DATE_WAIT); assertSinglePaymentEntry(customerOrder.getOrdernum(), "1000.71", PaymentGateway.AUTH, Payment.PAYMENT_STATUS_OK, false); assertEquals("1000.71", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_IN_PROGRESS, customerOrder.getOrderStatus()); changeAvailabilityDatesAndAssert(WAREHOUSE_ID, "CC_TEST6", DateUtils.ldtFrom(0L), true); CustomerOrderDelivery delivery = null; for (final CustomerOrderDelivery orderDelivery : customerOrder.getDelivery()) { if (CustomerOrderDelivery.DELIVERY_STATUS_DATE_WAIT.equals(orderDelivery.getDeliveryStatus())) { assertNull(delivery); delivery = orderDelivery; } } assertTrue(handler.handle( new OrderEventImpl("", customerOrder, delivery, Collections.EMPTY_MAP))); assertInventory(WAREHOUSE_ID, "CC_TEST1", "9.00", "2.00"); assertInventory(WAREHOUSE_ID, "CC_TEST2", "1.00", "1.00"); assertInventory(WAREHOUSE_ID, "CC_TEST6", "500.00", "3.00"); assertInventory(WAREHOUSE_ID, "CC_TEST5-NOINV", "0.00", "4.00"); assertDeliveryStates(customerOrder.getDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); assertSinglePaymentEntry(customerOrder.getOrdernum(), "1000.71", PaymentGateway.AUTH, Payment.PAYMENT_STATUS_OK, false); assertEquals("1000.71", customerOrder.getOrderTotal().toPlainString()); assertEquals("0.00", paymentService.getOrderAmount(customerOrder.getOrdernum()).toPlainString()); assertEquals(CustomerOrder.ORDER_STATUS_IN_PROGRESS, customerOrder.getOrderStatus()); }
@Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final LocalDateTime now = now(); final Collection<CustomerOrderDeliveryDet> deliveryDetails = orderEvent.getCustomerOrderDelivery().getDetail(); final Map<String, Warehouse> warehouseByCode = warehouseService.getByShopIdMapped( orderEvent.getCustomerOrder().getShop().getShopId(), false); for (CustomerOrderDeliveryDet det : deliveryDetails) { final Warehouse warehouse = warehouseByCode.get(det.getSupplierCode()); if (warehouse == null) { return false; } final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, det.getProductSkuCode()); if (inventory == null || !inventory.isAvailable(now) || !inventory.isReleased(now)) { return false; } } transition(orderEvent, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); getOrderStateManager().fireTransition(new OrderEventImpl(orderEvent, OrderStateManager.EVT_DELIVERY_ALLOWED_QUANTITY, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery())); return true; } }
DeliveryAllowedByTimeoutOrderEventHandlerImpl extends AbstractEventHandlerImpl implements OrderEventHandler, ApplicationContextAware { @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final LocalDateTime now = now(); final Collection<CustomerOrderDeliveryDet> deliveryDetails = orderEvent.getCustomerOrderDelivery().getDetail(); final Map<String, Warehouse> warehouseByCode = warehouseService.getByShopIdMapped( orderEvent.getCustomerOrder().getShop().getShopId(), false); for (CustomerOrderDeliveryDet det : deliveryDetails) { final Warehouse warehouse = warehouseByCode.get(det.getSupplierCode()); if (warehouse == null) { return false; } final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, det.getProductSkuCode()); if (inventory == null || !inventory.isAvailable(now) || !inventory.isReleased(now)) { return false; } } transition(orderEvent, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); getOrderStateManager().fireTransition(new OrderEventImpl(orderEvent, OrderStateManager.EVT_DELIVERY_ALLOWED_QUANTITY, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery())); return true; } } }
DeliveryAllowedByTimeoutOrderEventHandlerImpl extends AbstractEventHandlerImpl implements OrderEventHandler, ApplicationContextAware { @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final LocalDateTime now = now(); final Collection<CustomerOrderDeliveryDet> deliveryDetails = orderEvent.getCustomerOrderDelivery().getDetail(); final Map<String, Warehouse> warehouseByCode = warehouseService.getByShopIdMapped( orderEvent.getCustomerOrder().getShop().getShopId(), false); for (CustomerOrderDeliveryDet det : deliveryDetails) { final Warehouse warehouse = warehouseByCode.get(det.getSupplierCode()); if (warehouse == null) { return false; } final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, det.getProductSkuCode()); if (inventory == null || !inventory.isAvailable(now) || !inventory.isReleased(now)) { return false; } } transition(orderEvent, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); getOrderStateManager().fireTransition(new OrderEventImpl(orderEvent, OrderStateManager.EVT_DELIVERY_ALLOWED_QUANTITY, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery())); return true; } } DeliveryAllowedByTimeoutOrderEventHandlerImpl(final WarehouseService warehouseService,
                                                         final InventoryResolver inventoryResolver,
                                                         final ProductService productService); }
DeliveryAllowedByTimeoutOrderEventHandlerImpl extends AbstractEventHandlerImpl implements OrderEventHandler, ApplicationContextAware { @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final LocalDateTime now = now(); final Collection<CustomerOrderDeliveryDet> deliveryDetails = orderEvent.getCustomerOrderDelivery().getDetail(); final Map<String, Warehouse> warehouseByCode = warehouseService.getByShopIdMapped( orderEvent.getCustomerOrder().getShop().getShopId(), false); for (CustomerOrderDeliveryDet det : deliveryDetails) { final Warehouse warehouse = warehouseByCode.get(det.getSupplierCode()); if (warehouse == null) { return false; } final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, det.getProductSkuCode()); if (inventory == null || !inventory.isAvailable(now) || !inventory.isReleased(now)) { return false; } } transition(orderEvent, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); getOrderStateManager().fireTransition(new OrderEventImpl(orderEvent, OrderStateManager.EVT_DELIVERY_ALLOWED_QUANTITY, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery())); return true; } } DeliveryAllowedByTimeoutOrderEventHandlerImpl(final WarehouseService warehouseService,
                                                         final InventoryResolver inventoryResolver,
                                                         final ProductService productService); @Override boolean handle(final OrderEvent orderEvent); @Override void setApplicationContext(final ApplicationContext applicationContext); }
DeliveryAllowedByTimeoutOrderEventHandlerImpl extends AbstractEventHandlerImpl implements OrderEventHandler, ApplicationContextAware { @Override public boolean handle(final OrderEvent orderEvent) throws OrderException { synchronized (OrderEventHandler.syncMonitor) { final LocalDateTime now = now(); final Collection<CustomerOrderDeliveryDet> deliveryDetails = orderEvent.getCustomerOrderDelivery().getDetail(); final Map<String, Warehouse> warehouseByCode = warehouseService.getByShopIdMapped( orderEvent.getCustomerOrder().getShop().getShopId(), false); for (CustomerOrderDeliveryDet det : deliveryDetails) { final Warehouse warehouse = warehouseByCode.get(det.getSupplierCode()); if (warehouse == null) { return false; } final SkuWarehouse inventory = inventoryResolver.findByWarehouseSku(warehouse, det.getProductSkuCode()); if (inventory == null || !inventory.isAvailable(now) || !inventory.isReleased(now)) { return false; } } transition(orderEvent, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery(), CustomerOrderDelivery.DELIVERY_STATUS_INVENTORY_WAIT); getOrderStateManager().fireTransition(new OrderEventImpl(orderEvent, OrderStateManager.EVT_DELIVERY_ALLOWED_QUANTITY, orderEvent.getCustomerOrder(), orderEvent.getCustomerOrderDelivery())); return true; } } DeliveryAllowedByTimeoutOrderEventHandlerImpl(final WarehouseService warehouseService,
                                                         final InventoryResolver inventoryResolver,
                                                         final ProductService productService); @Override boolean handle(final OrderEvent orderEvent); @Override void setApplicationContext(final ApplicationContext applicationContext);  }