@Test public void testPersistReassembledOrder1() throws Exception { Customer customer = createCustomer(); assertFalse(customer.getAddress().isEmpty()); ShoppingCart shoppingCart = getShoppingCart(true); CustomerOrder order = customerOrderService.createFromCart(shoppingCart); assertEquals(4, order.getDelivery().size()); }
@Override public CustomerOrder createFromCart(final ShoppingCart shoppingCart) throws OrderAssemblyException { final boolean checkoutBlocked = Boolean.valueOf(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); if (checkoutBlocked) { throw new PlaceOrderDisabledException(shoppingCart.getCustomerEmail()); } if (validateCart(shoppingCart).isCheckoutBlocked()) { throw new OrderAssemblyException("Cart validation failed"); } final Map<String, Boolean> onePhysicalDelivery = new HashMap<>(); for (final Map.Entry<String, Boolean> isAllowed : shoppingCart.getOrderInfo().getMultipleDeliveryAvailable().entrySet()) { onePhysicalDelivery.put(isAllowed.getKey(), !shoppingCart.getOrderInfo().isMultipleDelivery() || !isAllowed.getValue()); } final CustomerOrder customerOrderToDelete = findByGuid(shoppingCart.getGuid()); if (customerOrderToDelete != null) { final boolean orderIsProcessedByPg = !CustomerOrder.ORDER_STATUS_NONE.equals(customerOrderToDelete.getOrderStatus()); final boolean orderHasPgSet = StringUtils.isNotBlank(customerOrderToDelete.getPgLabel()); if (orderIsProcessedByPg || orderHasPgSet) { if (orderIsProcessedByPg) { LOG.warn("Order {} with {} cart guid has {} order status instead of 1 - ORDER_STATUS_NONE, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus() ); } else { LOG.warn("Order {} with {} cart guid has {} order status and PG {}, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus(), customerOrderToDelete.getPgLabel() ); } customerOrderToDelete.setGuid(UUID.randomUUID().toString()); customerOrderToDelete.setCartGuid(customerOrderToDelete.getOrdernum()); getGenericDao().saveOrUpdate(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } else { getGenericDao().delete(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } } final String orderNumber = orderNumberGenerator.getNextOrderNumber(); final CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, orderNumber); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, onePhysicalDelivery); return create(customerOrder); }
CustomerOrderServiceImpl extends BaseGenericServiceImpl<CustomerOrder> implements CustomerOrderService { @Override public CustomerOrder createFromCart(final ShoppingCart shoppingCart) throws OrderAssemblyException { final boolean checkoutBlocked = Boolean.valueOf(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); if (checkoutBlocked) { throw new PlaceOrderDisabledException(shoppingCart.getCustomerEmail()); } if (validateCart(shoppingCart).isCheckoutBlocked()) { throw new OrderAssemblyException("Cart validation failed"); } final Map<String, Boolean> onePhysicalDelivery = new HashMap<>(); for (final Map.Entry<String, Boolean> isAllowed : shoppingCart.getOrderInfo().getMultipleDeliveryAvailable().entrySet()) { onePhysicalDelivery.put(isAllowed.getKey(), !shoppingCart.getOrderInfo().isMultipleDelivery() || !isAllowed.getValue()); } final CustomerOrder customerOrderToDelete = findByGuid(shoppingCart.getGuid()); if (customerOrderToDelete != null) { final boolean orderIsProcessedByPg = !CustomerOrder.ORDER_STATUS_NONE.equals(customerOrderToDelete.getOrderStatus()); final boolean orderHasPgSet = StringUtils.isNotBlank(customerOrderToDelete.getPgLabel()); if (orderIsProcessedByPg || orderHasPgSet) { if (orderIsProcessedByPg) { LOG.warn("Order {} with {} cart guid has {} order status instead of 1 - ORDER_STATUS_NONE, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus() ); } else { LOG.warn("Order {} with {} cart guid has {} order status and PG {}, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus(), customerOrderToDelete.getPgLabel() ); } customerOrderToDelete.setGuid(UUID.randomUUID().toString()); customerOrderToDelete.setCartGuid(customerOrderToDelete.getOrdernum()); getGenericDao().saveOrUpdate(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } else { getGenericDao().delete(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } } final String orderNumber = orderNumberGenerator.getNextOrderNumber(); final CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, orderNumber); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, onePhysicalDelivery); return create(customerOrder); } }
CustomerOrderServiceImpl extends BaseGenericServiceImpl<CustomerOrder> implements CustomerOrderService { @Override public CustomerOrder createFromCart(final ShoppingCart shoppingCart) throws OrderAssemblyException { final boolean checkoutBlocked = Boolean.valueOf(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); if (checkoutBlocked) { throw new PlaceOrderDisabledException(shoppingCart.getCustomerEmail()); } if (validateCart(shoppingCart).isCheckoutBlocked()) { throw new OrderAssemblyException("Cart validation failed"); } final Map<String, Boolean> onePhysicalDelivery = new HashMap<>(); for (final Map.Entry<String, Boolean> isAllowed : shoppingCart.getOrderInfo().getMultipleDeliveryAvailable().entrySet()) { onePhysicalDelivery.put(isAllowed.getKey(), !shoppingCart.getOrderInfo().isMultipleDelivery() || !isAllowed.getValue()); } final CustomerOrder customerOrderToDelete = findByGuid(shoppingCart.getGuid()); if (customerOrderToDelete != null) { final boolean orderIsProcessedByPg = !CustomerOrder.ORDER_STATUS_NONE.equals(customerOrderToDelete.getOrderStatus()); final boolean orderHasPgSet = StringUtils.isNotBlank(customerOrderToDelete.getPgLabel()); if (orderIsProcessedByPg || orderHasPgSet) { if (orderIsProcessedByPg) { LOG.warn("Order {} with {} cart guid has {} order status instead of 1 - ORDER_STATUS_NONE, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus() ); } else { LOG.warn("Order {} with {} cart guid has {} order status and PG {}, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus(), customerOrderToDelete.getPgLabel() ); } customerOrderToDelete.setGuid(UUID.randomUUID().toString()); customerOrderToDelete.setCartGuid(customerOrderToDelete.getOrdernum()); getGenericDao().saveOrUpdate(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } else { getGenericDao().delete(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } } final String orderNumber = orderNumberGenerator.getNextOrderNumber(); final CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, orderNumber); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, onePhysicalDelivery); return create(customerOrder); } CustomerOrderServiceImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao,
                                    final GenericDAO<Customer, Long> customerDao,
                                    final GenericDAO<Object, Long> genericDao,
                                    final GenericDAO<CustomerOrderDelivery, Long> customerOrderDeliveryDao,
                                    final OrderNumberGenerator orderNumberGenerator,
                                    final OrderAssembler orderAssembler,
                                    final DeliveryAssembler deliveryAssembler,
                                    final OrderSplittingStrategy orderSplittingStrategy,
                                    final CartContentsValidator cartContentsValidator); }
CustomerOrderServiceImpl extends BaseGenericServiceImpl<CustomerOrder> implements CustomerOrderService { @Override public CustomerOrder createFromCart(final ShoppingCart shoppingCart) throws OrderAssemblyException { final boolean checkoutBlocked = Boolean.valueOf(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); if (checkoutBlocked) { throw new PlaceOrderDisabledException(shoppingCart.getCustomerEmail()); } if (validateCart(shoppingCart).isCheckoutBlocked()) { throw new OrderAssemblyException("Cart validation failed"); } final Map<String, Boolean> onePhysicalDelivery = new HashMap<>(); for (final Map.Entry<String, Boolean> isAllowed : shoppingCart.getOrderInfo().getMultipleDeliveryAvailable().entrySet()) { onePhysicalDelivery.put(isAllowed.getKey(), !shoppingCart.getOrderInfo().isMultipleDelivery() || !isAllowed.getValue()); } final CustomerOrder customerOrderToDelete = findByGuid(shoppingCart.getGuid()); if (customerOrderToDelete != null) { final boolean orderIsProcessedByPg = !CustomerOrder.ORDER_STATUS_NONE.equals(customerOrderToDelete.getOrderStatus()); final boolean orderHasPgSet = StringUtils.isNotBlank(customerOrderToDelete.getPgLabel()); if (orderIsProcessedByPg || orderHasPgSet) { if (orderIsProcessedByPg) { LOG.warn("Order {} with {} cart guid has {} order status instead of 1 - ORDER_STATUS_NONE, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus() ); } else { LOG.warn("Order {} with {} cart guid has {} order status and PG {}, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus(), customerOrderToDelete.getPgLabel() ); } customerOrderToDelete.setGuid(UUID.randomUUID().toString()); customerOrderToDelete.setCartGuid(customerOrderToDelete.getOrdernum()); getGenericDao().saveOrUpdate(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } else { getGenericDao().delete(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } } final String orderNumber = orderNumberGenerator.getNextOrderNumber(); final CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, orderNumber); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, onePhysicalDelivery); return create(customerOrder); } CustomerOrderServiceImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao,
                                    final GenericDAO<Customer, Long> customerDao,
                                    final GenericDAO<Object, Long> genericDao,
                                    final GenericDAO<CustomerOrderDelivery, Long> customerOrderDeliveryDao,
                                    final OrderNumberGenerator orderNumberGenerator,
                                    final OrderAssembler orderAssembler,
                                    final DeliveryAssembler deliveryAssembler,
                                    final OrderSplittingStrategy orderSplittingStrategy,
                                    final CartContentsValidator cartContentsValidator); @Override CustomerOrderDelivery findDelivery(final long deliveryId); @Override CustomerOrderDelivery findDeliveryByNumber(final String deliveryNum); @Override List<Long> findEligibleForExportOrderIds(); @Override int findAwaitingDeliveriesCount(final Set<Long> shops, final String deliveryStatus, final List<String> orderStatus); @Override List<Long> findAwaitingDeliveriesIds(final List<String> skuCodes, final String deliveryStatus, final List<String> orderStatus); @Override ResultsIterator<CustomerOrderDelivery> findAwaitingDeliveries(final List<String> skuCodes, final String deliveryStatus, final List<String> orderStatus); @Override List<CustomerOrder> findOrders(final int start,
                                          final int offset,
                                          final String sort,
                                          final boolean sortDescending,
                                          final Map<String, List> filter); @Override int findOrderCount(final Map<String, List> filter); @Override List<Long> findCustomerOrderIdsByDeliveryIds(final Collection<Long> deliveryIds); @Override List<CustomerOrder> findCustomerOrders(final long customerId, final LocalDateTime since); @Override List<CustomerOrder> findCustomerOrders(final Customer customer, final LocalDateTime since); @Override Map<String, Boolean> isOrderMultipleDeliveriesAllowed(final ShoppingCart shoppingCart); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByDeliveryReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override CustomerOrder findByOrderNumber(final String orderNumber); @Override void delete(final CustomerOrder instance); }
CustomerOrderServiceImpl extends BaseGenericServiceImpl<CustomerOrder> implements CustomerOrderService { @Override public CustomerOrder createFromCart(final ShoppingCart shoppingCart) throws OrderAssemblyException { final boolean checkoutBlocked = Boolean.valueOf(shoppingCart.getOrderInfo().getDetailByKey(AttributeNamesKeys.Cart.ORDER_INFO_BLOCK_CHECKOUT)); if (checkoutBlocked) { throw new PlaceOrderDisabledException(shoppingCart.getCustomerEmail()); } if (validateCart(shoppingCart).isCheckoutBlocked()) { throw new OrderAssemblyException("Cart validation failed"); } final Map<String, Boolean> onePhysicalDelivery = new HashMap<>(); for (final Map.Entry<String, Boolean> isAllowed : shoppingCart.getOrderInfo().getMultipleDeliveryAvailable().entrySet()) { onePhysicalDelivery.put(isAllowed.getKey(), !shoppingCart.getOrderInfo().isMultipleDelivery() || !isAllowed.getValue()); } final CustomerOrder customerOrderToDelete = findByGuid(shoppingCart.getGuid()); if (customerOrderToDelete != null) { final boolean orderIsProcessedByPg = !CustomerOrder.ORDER_STATUS_NONE.equals(customerOrderToDelete.getOrderStatus()); final boolean orderHasPgSet = StringUtils.isNotBlank(customerOrderToDelete.getPgLabel()); if (orderIsProcessedByPg || orderHasPgSet) { if (orderIsProcessedByPg) { LOG.warn("Order {} with {} cart guid has {} order status instead of 1 - ORDER_STATUS_NONE, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus() ); } else { LOG.warn("Order {} with {} cart guid has {} order status and PG {}, keeping the order", customerOrderToDelete.getCustomerorderId(), shoppingCart.getGuid(), customerOrderToDelete.getOrderStatus(), customerOrderToDelete.getPgLabel() ); } customerOrderToDelete.setGuid(UUID.randomUUID().toString()); customerOrderToDelete.setCartGuid(customerOrderToDelete.getOrdernum()); getGenericDao().saveOrUpdate(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } else { getGenericDao().delete(customerOrderToDelete); getGenericDao().flushClear(); getGenericDao().evict(customerOrderToDelete); } } final String orderNumber = orderNumberGenerator.getNextOrderNumber(); final CustomerOrder customerOrder = orderAssembler.assembleCustomerOrder(shoppingCart, orderNumber); deliveryAssembler.assembleCustomerOrder(customerOrder, shoppingCart, onePhysicalDelivery); return create(customerOrder); } CustomerOrderServiceImpl(final GenericDAO<CustomerOrder, Long> customerOrderDao,
                                    final GenericDAO<Customer, Long> customerDao,
                                    final GenericDAO<Object, Long> genericDao,
                                    final GenericDAO<CustomerOrderDelivery, Long> customerOrderDeliveryDao,
                                    final OrderNumberGenerator orderNumberGenerator,
                                    final OrderAssembler orderAssembler,
                                    final DeliveryAssembler deliveryAssembler,
                                    final OrderSplittingStrategy orderSplittingStrategy,
                                    final CartContentsValidator cartContentsValidator); @Override CustomerOrderDelivery findDelivery(final long deliveryId); @Override CustomerOrderDelivery findDeliveryByNumber(final String deliveryNum); @Override List<Long> findEligibleForExportOrderIds(); @Override int findAwaitingDeliveriesCount(final Set<Long> shops, final String deliveryStatus, final List<String> orderStatus); @Override List<Long> findAwaitingDeliveriesIds(final List<String> skuCodes, final String deliveryStatus, final List<String> orderStatus); @Override ResultsIterator<CustomerOrderDelivery> findAwaitingDeliveries(final List<String> skuCodes, final String deliveryStatus, final List<String> orderStatus); @Override List<CustomerOrder> findOrders(final int start,
                                          final int offset,
                                          final String sort,
                                          final boolean sortDescending,
                                          final Map<String, List> filter); @Override int findOrderCount(final Map<String, List> filter); @Override List<Long> findCustomerOrderIdsByDeliveryIds(final Collection<Long> deliveryIds); @Override List<CustomerOrder> findCustomerOrders(final long customerId, final LocalDateTime since); @Override List<CustomerOrder> findCustomerOrders(final Customer customer, final LocalDateTime since); @Override Map<String, Boolean> isOrderMultipleDeliveriesAllowed(final ShoppingCart shoppingCart); @Override CartValidityModel validateCart(final ShoppingCart shoppingCart); @Override CustomerOrder createFromCart(final ShoppingCart shoppingCart); @Override CustomerOrder findByReference(final String reference); @Override CustomerOrder findByDeliveryReference(final String reference); @Override CustomerOrder findByGuid(final String shoppingCartGuid); @Override CustomerOrder findByOrderNumber(final String orderNumber); @Override void delete(final CustomerOrder instance);  }