Search in sources :

Example 6 with WorkflowException

use of org.broadleafcommerce.core.workflow.WorkflowException in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method removePaymentFromOrder.

@Override
@Transactional("blTransactionManager")
public void removePaymentFromOrder(Order order, OrderPayment payment) {
    OrderPayment paymentToRemove = null;
    for (OrderPayment info : order.getPayments()) {
        if (info.equals(payment)) {
            paymentToRemove = info;
        }
    }
    if (paymentToRemove != null) {
        try {
            securePaymentInfoService.findAndRemoveSecurePaymentInfo(paymentToRemove.getReferenceNumber(), payment.getType());
        } catch (WorkflowException e) {
            // do nothing--this is an acceptable condition
            LOG.debug("No secure payment is associated with the OrderPayment", e);
        }
        order.getPayments().remove(paymentToRemove);
        payment = paymentDao.readPaymentById(paymentToRemove.getId());
        paymentDao.delete(payment);
    }
}
Also used : WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with WorkflowException

use of org.broadleafcommerce.core.workflow.WorkflowException in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method updateItemQuantity.

@Override
@Transactional(value = "blTransactionManager", rollbackFor = { UpdateCartException.class, RemoveFromCartException.class })
public Order updateItemQuantity(Long orderId, OrderItemRequestDTO orderItemRequestDTO, boolean priceOrder) throws UpdateCartException, RemoveFromCartException {
    Order order = findOrderById(orderId);
    preValidateCartOperation(order);
    preValidateUpdateQuantityOperation(findOrderById(orderId), orderItemRequestDTO);
    if (orderItemRequestDTO.getQuantity() == 0) {
        return removeItem(orderId, orderItemRequestDTO.getOrderItemId(), priceOrder);
    }
    try {
        CartOperationRequest cartOpRequest = new CartOperationRequest(findOrderById(orderId), orderItemRequestDTO, priceOrder);
        Session session = em.unwrap(Session.class);
        FlushMode current = session.getFlushMode();
        if (!autoFlushUpdateCart) {
            // Performance measure. Hibernate will sometimes perform an autoflush when performing query operations and this can
            // be expensive. It is possible to avoid the autoflush if there's no concern about queries in the flow returning
            // incorrect results because something has not been flushed to the database yet.
            session.setFlushMode(FlushMode.MANUAL);
        }
        ProcessContext<CartOperationRequest> context;
        try {
            context = (ProcessContext<CartOperationRequest>) updateItemWorkflow.doActivities(cartOpRequest);
        } finally {
            if (!autoFlushUpdateCart) {
                session.setFlushMode(current);
            }
        }
        context.getSeedData().getOrder().getOrderMessages().addAll(((ActivityMessages) context).getActivityMessages());
        return context.getSeedData().getOrder();
    } catch (WorkflowException e) {
        throw new UpdateCartException("Could not update cart quantity", getCartOperationExceptionRootCause(e));
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) UpdateCartException(org.broadleafcommerce.core.order.service.exception.UpdateCartException) FlushMode(org.hibernate.FlushMode) Session(org.hibernate.Session) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with WorkflowException

use of org.broadleafcommerce.core.workflow.WorkflowException in project BroadleafCommerce by BroadleafCommerce.

the class OrderServiceImpl method removePaymentsFromOrder.

@Override
@Transactional("blTransactionManager")
public void removePaymentsFromOrder(Order order, PaymentType paymentInfoType) {
    List<OrderPayment> infos = new ArrayList<OrderPayment>();
    for (OrderPayment paymentInfo : order.getPayments()) {
        if (paymentInfoType == null || paymentInfoType.equals(paymentInfo.getType())) {
            infos.add(paymentInfo);
        }
    }
    order.getPayments().removeAll(infos);
    for (OrderPayment paymentInfo : infos) {
        try {
            securePaymentInfoService.findAndRemoveSecurePaymentInfo(paymentInfo.getReferenceNumber(), paymentInfo.getType());
        } catch (WorkflowException e) {
            // do nothing--this is an acceptable condition
            LOG.debug("No secure payment is associated with the OrderPayment", e);
        }
        order.getPayments().remove(paymentInfo);
        paymentInfo = paymentDao.readPaymentById(paymentInfo.getId());
        paymentDao.delete(paymentInfo);
    }
}
Also used : WorkflowException(org.broadleafcommerce.core.workflow.WorkflowException) ArrayList(java.util.ArrayList) OrderPayment(org.broadleafcommerce.core.payment.domain.OrderPayment) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

WorkflowException (org.broadleafcommerce.core.workflow.WorkflowException)8 Transactional (org.springframework.transaction.annotation.Transactional)6 ArrayList (java.util.ArrayList)3 Order (org.broadleafcommerce.core.order.domain.Order)3 UpdateCartException (org.broadleafcommerce.core.order.service.exception.UpdateCartException)3 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)3 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)2 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)2 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)2 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)2 RemoveFromCartException (org.broadleafcommerce.core.order.service.exception.RemoveFromCartException)2 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)2 PricingException (org.broadleafcommerce.core.pricing.service.exception.PricingException)2 ProcessContext (org.broadleafcommerce.core.workflow.ProcessContext)2 FlushMode (org.hibernate.FlushMode)2 Session (org.hibernate.Session)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)1 CheckoutSeed (org.broadleafcommerce.core.checkout.service.workflow.CheckoutSeed)1