// req: 11.7 public Order createFromShoppingCart(ShoppingCart shoppingCart, Consumer consumer) { Assert.notNull(shoppingCart); Assert.isTrue(shoppingCart.getId() != 0); Assert.notNull(consumer); Assert.isTrue(consumer.getId() != 0); Order result; Collection<OrderItem> orderItems; double amount; result = this.create(); // Adding OrderItems orderItems = orderItemService.createByShoppingCart(shoppingCart, result); result.setOrderItems(orderItems); // Calculate amount amount = this.amountCalculate(orderItems); result.setAmount(amount); // Adding Order to Consumer result.setConsumer(consumer); return result; }
/** Guarda la Order desde ShoppingCart. NO USAR. Usar desde ShoppingCartService.saveCheckOut. */ public void saveFromShoppingCart(ShoppingCart shoppingCart, Order order) { Assert.notNull(shoppingCart); Assert.notNull(order); Collection<OrderItem> orderItems; double amount; // Check CreditCard Assert.isTrue( this.checkCreditcard(order.getCreditCard()), "order.commit.error.creditcard.date"); // Adding OrderItems orderItems = orderItemService.createByShoppingCart(shoppingCart, order); order.setOrderItems(orderItems); // Calculate amount amount = this.amountCalculate(orderItems); Assert.isTrue(amount == order.getAmount(), "order.commit.AmountChanged"); order = this.save(order); // Saving OrderItems orderItems = orderItemService.createByShoppingCart(shoppingCart, order); orderItemService.save(orderItems); }
/** * Pone el deliveryMoment a la Order * * @param order */ public void completedOrder(Order order) { Assert.notNull(order); Assert.isTrue( order.getClerk().equals(clerkService.findByprincipal()), "Only the owner clerk can complete the order"); order.setDeliveryMoment(new Date()); this.save(order); }
// ref: 18.3 public void assignToClerkManual(Clerk clerk, Order order) { Assert.notNull(clerk); Assert.isTrue(clerk.getId() != 0); Assert.notNull(order); Assert.isTrue(order.getId() != 0); Assert.isNull(order.getClerk()); order.setClerk(clerk); this.save(order); }
// req: 11.7 private Order create() { Order result; String ticker; result = new Order(); ticker = this.tickerGenerate(); result.setPlacementMoment(new Date()); result.setTicker(ticker); return result; }
// req: 16.1 public void cancelOrder(Order order) { Assert.notNull(order); Assert.isTrue(order.getId() != 0); Assert.isTrue( order.getConsumer().equals(consumerService.findByPrincipal()), "Only the owner can cancel the order"); Assert.isTrue(order.getCancelMoment() == null, "order.cancel.error.isCancelled"); Clerk clerk; clerk = clerkService.findByOrder(order); Assert.isNull(clerk, "Can't remove a order when a clerk has assigned"); order.setCancelMoment(new Date()); this.save(order); }
// Frederik public boolean insertOrders(ArrayList<Order> ol, Connection conn) throws SQLException { int rowsInserted = 0; String SQLString = "insert into orders values (?,?,?,?)"; PreparedStatement statement = null; statement = conn.prepareStatement(SQLString); for (int i = 0; i < ol.size(); i++) { Order o = ol.get(i); statement.setInt(1, o.getOID()); statement.setInt(2, o.getCID()); statement.setDate(3, o.getFromDate()); statement.setDate(4, o.getToDate()); rowsInserted += statement.executeUpdate(); } System.out.println("insertOrders: " + (rowsInserted == ol.size())); return (rowsInserted == ol.size()); }
// Frederik public Order getOrder(Connection conn, int oID) { Order o = null; String SQLString = "select * " + "from orders " + "where oid = ?"; PreparedStatement statement = null; try { statement = conn.prepareStatement(SQLString); statement.setInt(1, oID); ResultSet rs = statement.executeQuery(); if (rs.next()) { o = new Order(rs.getInt(1), rs.getInt(2), rs.getDate(3), rs.getDate(4)); SQLString = "select * " + "from orderdetails " + "where oid = ?"; statement = conn.prepareStatement(SQLString); statement.setInt(1, oID); rs = statement.executeQuery(); while (rs.next()) { o.addDetail(new OrderDetail(rs.getInt(1), rs.getInt(2), rs.getInt(3))); } } } catch (SQLException ex) { System.out.println("Fail in OrderMapper - getOrder"); System.out.println(ex.getMessage()); } return o; }
// Kirstine, Charlotte og Frederik public ArrayList<Order> getOrders(Connection conn, String datoFra, String datoTil) { Order currentO = null; ArrayList<Order> ol = new ArrayList(); String SQLString = "select * " + "from orders " + "where datofra between to_date(?,'dd-mon-yyyy') " + "and to_date(?,'dd-mon-yyyy')"; PreparedStatement statement = null; try { statement = conn.prepareStatement(SQLString); statement.setString(1, datoFra); statement.setString(2, datoTil); ResultSet rs = statement.executeQuery(); SQLString = "select * " + "from orderdetails " + "where oID = ?"; statement = conn.prepareStatement(SQLString); ResultSet rs2; String SQLString2 = "select * " + "from installers " + "where oID = ?"; PreparedStatement statement2 = conn.prepareStatement(SQLString2); ResultSet rs3; while (rs.next()) { currentO = new Order(rs.getInt(1), rs.getInt(2), rs.getDate(3), rs.getDate(4)); statement.setInt(1, currentO.getOID()); rs2 = statement.executeQuery(); while (rs2.next()) { currentO.addDetail(new OrderDetail(rs2.getInt(1), rs2.getInt(2), rs2.getInt(3))); } statement2.setInt(1, currentO.getOID()); rs3 = statement2.executeQuery(); Calendar c = new GregorianCalendar(); while (rs3.next()) { c.setTimeInMillis(rs3.getDate(3).getTime()); String from = c.get(c.DAY_OF_MONTH) + "-" + c.get(c.MONTH) + "-" + c.get(c.YEAR) + " " + c.get(c.HOUR_OF_DAY) + ":" + c.get(c.MINUTE); c.setTimeInMillis(rs3.getDate(4).getTime()); String to = c.get(c.DAY_OF_MONTH) + "-" + c.get(c.MONTH) + "-" + c.get(c.YEAR) + " " + c.get(c.HOUR_OF_DAY) + ":" + c.get(c.MINUTE); currentO.addInstaller(new Installer(rs3.getInt(1), rs3.getInt(2), from, to)); } ol.add(currentO); } } catch (SQLException ex) { System.out.println("Fail in OrderMapper - getOrders"); System.out.println(ex.getMessage()); } return ol; }
@Override public void entryOperationFinished( Notification source, Operation op, List<? extends Serializable> entries) { for (Serializable entry : entries) { if (op.equals(Operation.DELETE)) { // waiter deletes Order order = (Order) entry; if (gui != null) { if (order instanceof GroupOrder) { order.setStatus(Order.Status.delivered); } else { order.setStatus(Order.Status.delivering); } gui.addOrUpdateOrder(order); } if (group != null) { if (order instanceof GroupOrder) { if (group.getGroupData().equals(((GroupOrder) order).getGroupData())) { group.notifyPaying(); } } } if (groupView != null) { CustomerData g = order.getCustomerData(); if (order instanceof GroupOrder) { g.setStatus(CustomerData.Status.eating); } groupView.updateCustomerData(g); } } else if (op.equals(Operation.TAKE)) { // load balancer takes Order order = (Order) entry; if (gui != null) { order.setStatus(Order.Status.outsourced); gui.addOrUpdateOrder(order); } if (groupView != null) { CustomerData customerData = order.getCustomerData(); String newBranch; if (customerData.getBranch().startsWith("1")) { newBranch = "2"; } else { newBranch = "1"; } customerData.setBranch(newBranch + " (moved)"); groupView.updateCustomerData(customerData); } } else if (op.equals(Operation.WRITE)) { Entry ent = (Entry) entry; Order g = (Order) ent.getValue(); if (gui != null) { gui.addOrUpdateOrder(g); } if (loadBalancer != null) { loadBalancer.balance(source.getObservedContainer()); } } } }