// removes the new books order item request placed by the customer on delivering it public List<OrderItem> removeNewBookOrderItem(Book book, List<OrderItem> list) { try { Book book1 = new Book(); for (int i = list.size() - 1; i >= 0; i--) { OrderItem oi = list.get(i); if (oi.getBook().getProductName().trim().equals(book.getProductName()) && oi.getBook().getAuthor().trim().equals(book.getAuthor()) && oi.getBook().getEdition().trim().equals(book.getEdition()) && oi.getBook().getActive() == book.getActive()) { list.remove(i); book1 = oi.getBook(); if (book1.getActive() == 0) { Session session1 = HibernateUtil.getSessionFactory().openSession(); Transaction tx1 = session1.beginTransaction(); Book book2 = (Book) session1.get(Book.class, book1.getProductId()); if (book.getOrderitemList() != null) { session1.delete(book2.getInventoryItem()); } session1.delete(book2); tx1.commit(); close(); } break; } } } catch (Exception e) { System.out.print("Can not delete"); } return list; }
// updates the details of an order item public void updateItem(String status, Float cost, int oid) { try { Session session1 = HibernateUtil.getSessionFactory().openSession(); Transaction tx1 = session1.beginTransaction(); OrderItem oi1 = (OrderItem) session1.get(OrderItem.class, oid); oi1.setItemStatus(status); Book book = oi1.getBook(); int bookId = book.getProductId(); Book book1 = (Book) session1.get(Book.class, bookId); session1.update(oi1); session1.update(book1); tx1.commit(); close(); } catch (Exception e) { e.printStackTrace(); } }
// updates the order item cost for the books to be sold by the customer public Boolean updateOrderitemCost(int orderitemId, Float cost) { Boolean flag = false; try { Session session1 = HibernateUtil.getSessionFactory().openSession(); Transaction tx1 = session1.beginTransaction(); OrderItem orderitem = (OrderItem) session1.get(OrderItem.class, orderitemId); Book book = orderitem.getBook(); book.setProductCost(cost); orderitem.setBook(book); DifferentOrder order = orderitem.getOrderNo(); order.setOrderAmount(orderitem.getQuantity() * orderitem.getBook().getProductCost()); orderitem.setOrderNo(order); session1.update(order); session1.update(orderitem); flag = true; tx1.commit(); session1.close(); } catch (Exception e) { e.printStackTrace(); } return flag; }