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);
}
}
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));
}
}
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);
}
}
Aggregations