Ejemplo n.º 1
0
 /**
  * Test method for {@link controller.OrderInterface#addItemToOrder(model.Order, model.MenuItem)}.
  * Test with null order. Expect error
  */
 @Test(expected = model.PizzaException.class)
 public void testAddItemToOrderNullOrder() throws PizzaException {
   MenuItem mi = new MenuItem(5, "wings", "wings");
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().addItemToOrder(null, mi);
   assertFalse(temp.getItems().contains(mi));
 }
Ejemplo n.º 2
0
  /** Constructor that takes an order. */
  public NewOrderController(Order order) {

    _currentOrder = order;
    _modifying = true;

    // Recover the quantity map.Recover the side quantity map: start with a sorted side
    // food item list.
    ArrayList<FoodItem> itemList = SideFoodItem.getDb().list();
    Collections.sort(itemList);

    // Create the map and initialize all of the values to zero.
    _quantityMap = new HashMap<SideFoodItem, Integer>();
    for (FoodItem sfi : SideFoodItem.getDb().list()) {
      _quantityMap.put((SideFoodItem) sfi, 0);
    }

    // Go through the SFIs in the given list and increment the corresponding
    // element of the map.
    ArrayList<PizzaFoodItem> pizzaFoodItems = new ArrayList<PizzaFoodItem>();
    for (FoodItem item : _currentOrder.getFoodItems()) {
      if (item instanceof SideFoodItem) {
        int value = _quantityMap.get((SideFoodItem) item);
        _quantityMap.put((SideFoodItem) item, value + 1);
      } else {
        pizzaFoodItems.add((PizzaFoodItem) item);
      }
    }

    // Now clear the order's list and add in back in all of the pizzas.
    _currentOrder.getFoodItems().clear();
    for (PizzaFoodItem item : pizzaFoodItems) {
      _currentOrder.addFoodItem(item);
    }
  }
Ejemplo n.º 3
0
 /**
  * Test method for {@link controller.OrderInterface#cancelCurrentOrder(model.Order)}. Test with a
  * non-system order. Expect error
  */
 @Test(expected = model.PizzaException.class)
 public void testCancelCurrentOrderBadOrder() throws PizzaException {
   Order temp = new Order();
   test.getOrderInterface().cancelCurrentOrder(temp);
   assertFalse(temp.getOrderStatus() == model.OrderStatus.canceled);
   assertFalse(test.getPizzaStore().getOrderQueue().getCanceledOrders().contains(temp));
 }
Ejemplo n.º 4
0
 /**
  * Test method for {@link controller.OrderInterface#addItemToOrder(model.Order, model.MenuItem)}.
  * Test with non-system order. Expect error
  */
 @Test(expected = model.PizzaException.class)
 public void testAddItemToOrderNonSystem() throws PizzaException {
   MenuItem mi = new MenuItem(5, "wings", "wings");
   Order temp = new Order();
   test.getOrderInterface().addItemToOrder(temp, mi);
   assertFalse(temp.getItems().contains(mi));
 }
Ejemplo n.º 5
0
  /** Updates the food item list stored in the order based on the quantity map. */
  private void updateOrderFoodItemList() {

    // Filter out the list of pizzas in the order.
    ArrayList<PizzaFoodItem> pizzaList = new ArrayList<PizzaFoodItem>();
    for (FoodItem item : _currentOrder.getFoodItems()) {
      if (item instanceof PizzaFoodItem) {
        pizzaList.add((PizzaFoodItem) item);
      }
    }

    // Remove everything from the list.
    _currentOrder.getFoodItems().clear();

    // Add the pizzas.
    _currentOrder.getFoodItems().addAll(pizzaList);

    // Add the sides to the order according to the
    // quantity map.
    for (SideFoodItem side : _quantityMap.keySet()) {

      // Duplicate this side the appropriate number of times.
      for (int i = 0; i < _quantityMap.get(side); i++) {

        SideFoodItem duplicateItem =
            new SideFoodItem(
                side.getName(),
                side.getPrice(),
                side.getPrepTime(),
                side.getCookTime(),
                side.getOvenSpaceUnits());
        _currentOrder.addFoodItem(duplicateItem);
      }
    }
  }
Ejemplo n.º 6
0
 /**
  * Test method for {@link controller.OrderInterface#prepOrder(model.Order)}. Test with an order
  * that's ready to be prepped, but is empty. Expect error.
  */
 @Test(expected = model.PizzaException.class)
 public void testPrepOrderGoodButEmpty() throws PizzaException {
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().prepOrder(temp);
   assertFalse(test.getPizzaStore().getOrderQueue().getOrdersBeingMade().contains(temp));
   assertFalse(temp.getOrderStatus() == model.OrderStatus.beingMade);
 }
Ejemplo n.º 7
0
  /**
   * searches all registry lists for a specific keyword and returns all matches in a a list
   *
   * <p>function is obsolete since 1.19
   *
   * @param req the "search keyword"
   * @return list of matching objects
   */
  public ArrayList<Object> search(String req) {
    ArrayList<Object> returnValues = new ArrayList<Object>();

    for (Customer c : getCustomers().values()) {
      if (c.getName().contains(req)
          || c.getAddress().contains(req)
          || c.getCivic().contains(req)
          || c.getPhone().contains(req)) {
        returnValues.add(c);
      }
    }

    for (Item i : getItems().values()) {
      if (i.getName().contains(req) || i.getPrice().contains(req) || i.getDetails().contains(req)) {
        returnValues.add(i);
      }
    }

    for (Order i : getOrders().values()) {
      if (i.getOrderNo().contains(req) || i.getCustomer().getName().contains(req)) {
        returnValues.add(i);
      }
    }
    return returnValues;
  }
Ejemplo n.º 8
0
  /**
   * Handles input in the WaitingForPhoneNumber state.
   *
   * @param message The string message.
   * @param channel The channel from which the input was received.
   */
  private void handleWaitingForCustInfo(String message, NewOrderInChan channel) {

    // Only one channel to get input.
    switch ((NewOrderInChan) channel) {
      case ICMenuOption:
        // Do nothing
        break;

      case ICCustomerPhone:

        // Check if the string is a valid phone number.  If so, set
        // it as the new phone number.
        if (Customer.isValidPhoneNumber(message)) {

          _currentOrder.getCustomer().setPhoneNumber(message);
        }
        break;

      case ICCustomerName:

        // Set the new string as the name.
        _currentOrder.getCustomer().setName(message);
        break;

      case ICCustomerAddress:

        // Check that the address is valid.
        Address addr = Address.getAddressForAlias(message);
        if (null == addr) {

          // Do nothing.

        } else {

          _currentOrder.getCustomer().setStreetAddress(addr);

          // If we got a valid address, the customer should
          // be done being detailed.  Add this new customer
          // to the database and proceed to the order construction
          // state.
          Customer.getDb().add(_currentOrder.getCustomer());
          gotoDisplayingOrder();
        }
        break;

      case ICBack:

        // Check for a back button.
        if (message.equalsIgnoreCase(NewOrderView.BACK_KEY)) {

          // Go back to the customer phone number prompt.
          gotoWaitingForPhoneNumber();
        }
        break;

      default:
        handleInputError("The input was invalid. Please try again.");
        break;
    }
  }
Ejemplo n.º 9
0
 /**
  * Test method for {@link controller.OrderInterface#cancelCurrentOrder(model.Order)}. Test with an
  * order that is ready to be canceled.
  */
 @Test
 public void testCancelCurrentOrderGood() throws PizzaException {
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().cancelCurrentOrder(temp);
   assertTrue(temp.getOrderStatus() == model.OrderStatus.canceled);
   assertTrue(test.getPizzaStore().getOrderQueue().getCanceledOrders().contains(temp));
 }
Ejemplo n.º 10
0
 /**
  * Test method for {@link controller.OrderInterface#addItemToOrder(model.Order, model.MenuItem)}.
  * Test with good inputs.
  */
 @Test
 public void testAddItemToOrderGood() throws PizzaException {
   MenuItem mi = test.getManagerInterface().addItemToMenu(10, "wings", "wings");
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().addItemToOrder(temp, mi);
   assertTrue(temp.getItems().contains(mi));
 }
Ejemplo n.º 11
0
 /**
  * Test method for {@link controller.OrderInterface#completeOrder(model.Order)}. Test complete
  * order with already canceled order
  */
 @Test(expected = model.PizzaException.class)
 public void testCompleteOrderCanceledOrder() throws PizzaException {
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().cancelCurrentOrder(temp);
   test.getOrderInterface().completeOrder(temp);
   assertTrue(temp.getOrderStatus() == model.OrderStatus.canceled);
   assertFalse(test.getPizzaStore().getOrderQueue().getPastOrders().contains(temp));
 }
Ejemplo n.º 12
0
 /**
  * Test method for {@link controller.OrderInterface#addPizzaToOrder(model.Order, model.Pizza)}.
  * Test with good inputs.
  */
 @Test
 public void testAddPizzaToOrderGood() throws PizzaException {
   PizzaSize ps = test.getManagerInterface().addPizzaSizeToMenu(6, "bloop");
   Pizza pizza = new Pizza(toppings, ps);
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().addPizzaToOrder(temp, pizza);
   assertTrue(temp.getPizzas().contains(pizza));
 }
Ejemplo n.º 13
0
 /**
  * Test method for {@link controller.OrderInterface#prepOrder(model.Order)}. Test with an order
  * that's ready to be prepped.
  */
 @Test
 public void testPrepOrderGood() throws PizzaException {
   pizzaList.add(new Pizza(toppings, new PizzaSize(10, "Large")));
   itemList.add(new MenuItem(5, "wings", "wings"));
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().prepOrder(temp);
   assertTrue(test.getPizzaStore().getOrderQueue().getOrdersBeingMade().contains(temp));
   assertTrue(temp.getOrderStatus() == model.OrderStatus.beingMade);
 }
Ejemplo n.º 14
0
 /**
  * Test method for {@link controller.OrderInterface#addPizzaToOrder(model.Order, model.Pizza)}.
  * Test with a non-system pizzasize. Expect error.
  */
 @Test(expected = model.PizzaException.class)
 public void testAddPizzaToOrderNonSystemPizzaSize() throws PizzaException {
   PizzaSize ps = new PizzaSize(10, "ARRRRRRRGGGGHH");
   Pizza pizza = new Pizza(toppings, ps);
   Order temp = new Order();
   test.getOrderInterface().addPizzaToOrder(temp, pizza);
   assertFalse(temp.getPizzas().contains(pizza));
   assertFalse(test.getPizzaStore().getOrderQueue().getCurrentOrders().contains(temp));
 }
Ejemplo n.º 15
0
  /** Moves the controller into the WaitingForPhoneNumber state. */
  private void gotoDisplayingOrderConfirmation() {

    this.currentState = NewOrderContState.CSDisplayingOrderConfirmation;

    // Disallow modifying and deleting of the list.
    view.setChannelEnabled(NewOrderInChan.ICCustomerName, false);
    view.setChannelEnabled(NewOrderInChan.ICCustomerAddress, false);

    view.setChannelEnabled(NewOrderInChan.ICListDelete, false);
    view.setChannelEnabled(NewOrderInChan.ICListModify, false);
    view.setChannelEnabled(NewOrderInChan.ICMenuOption, false);
    view.setChannelEnabled(NewOrderInChan.ICBack, false);

    // Show a "continue" option.
    view.setChannelEnabled(NewOrderInChan.ICConfirm, true);

    // Display the customer and the list.
    view.displayObject(_currentOrder.getCustomer(), NewOrderOutChan.OCCustomerDisplay);
    view.displayList(_currentOrder.getFoodItems(), NewOrderOutChan.OCFoodItemList);

    view.displayString(
        "$" + Order.formatPrice(_currentOrder.calculateSubtotal()),
        NewOrderOutChan.OCSubTotalDisplay);
    view.displayString(
        "$" + Order.formatPrice(_currentOrder.getTax()), NewOrderOutChan.OCTaxDisplay);
    view.displayString(
        "$" + Order.formatPrice(_currentOrder.calculateTotal()), NewOrderOutChan.OCTotalDisplay);

    view.displayString(
        "" + Time.formatTime(_currentOrder.calculateEstimatedDeliveryTime()),
        NewOrderOutChan.OCDeliveryTimeDisplay);
  }
Ejemplo n.º 16
0
 /**
  * Test method for {@link controller.OrderInterface#applySpecialsToOrder(model.Order)}. Test with
  * good inputs. Should allow
  */
 @Test
 public void testApplySpecialsToOrderGood() throws PizzaException {
   PizzaSize large = test.getManagerInterface().addPizzaSizeToMenu(10, "Large");
   pizzaList.add(new Pizza(toppings, large));
   model.MenuItem mi = test.getManagerInterface().addItemToMenu(5, "name", "name");
   itemList.add(mi);
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   temp.tallyTotalPrice();
   assertTrue(temp.getPrice() == 15);
   test.getManagerInterface().createSpecialWithItem("Cheap Wings", mi, 1);
   test.getOrderInterface().applySpecialsToOrder(temp);
   assertTrue(temp.getPrice() == 11);
 }
Ejemplo n.º 17
0
 /**
  * Test method for {@link controller.OrderInterface#prepOrder(model.Order)}. Test with an order
  * that's already been canceled. Expect error.
  */
 @Test(expected = model.PizzaException.class)
 public void testPrepOrderCanceled() throws PizzaException {
   pizzaList.add(new Pizza(toppings, new PizzaSize(10, "Large")));
   itemList.add(new MenuItem(5, "wings", "wings"));
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().prepOrder(temp);
   assertTrue(test.getPizzaStore().getOrderQueue().getOrdersBeingMade().contains(temp));
   assertTrue(temp.getOrderStatus() == model.OrderStatus.beingMade);
   test.getOrderInterface().cancelCurrentOrder(temp);
   test.getOrderInterface().prepOrder(temp);
   assertTrue(test.getPizzaStore().getOrderQueue().getCanceledOrders().contains(temp));
   assertTrue(temp.getOrderStatus() == model.OrderStatus.canceled);
   assertFalse(test.getPizzaStore().getOrderQueue().getOrdersBeingMade().contains(temp));
 }
Ejemplo n.º 18
0
  /** Moves the controller into the WaitingForPhoneNumber state. */
  private void gotoDisplayingOrder() {

    this.currentState = NewOrderContState.CSDisplayingOrder;

    // Disable the back button if we're modifying.
    if (_modifying) {
      view.setChannelEnabled(NewOrderInChan.ICBack, false);
    }

    // Disable the customer info channels.
    view.setChannelEnabled(NewOrderInChan.ICCustomerName, false);
    view.setChannelEnabled(NewOrderInChan.ICCustomerAddress, false);

    // Enable the other channels.
    view.setChannelEnabled(NewOrderInChan.ICListDelete, true);
    view.setChannelEnabled(NewOrderInChan.ICListModify, true);
    view.setChannelEnabled(NewOrderInChan.ICMenuOption, true);

    // Update the fooditem list in the order.
    updateOrderFoodItemList();

    // Display the customer and the list.
    view.displayObject(_currentOrder.getCustomer(), NewOrderOutChan.OCCustomerDisplay);
    view.displayList(_currentOrder.getFoodItems(), NewOrderOutChan.OCFoodItemList);

    view.displayString(
        "$" + Order.formatPrice(_currentOrder.calculateSubtotal()),
        NewOrderOutChan.OCSubTotalDisplay);
    view.displayString(
        "$" + Order.formatPrice(_currentOrder.getTax()), NewOrderOutChan.OCTaxDisplay);
    view.displayString(
        "$" + Order.formatPrice(_currentOrder.calculateTotal()), NewOrderOutChan.OCTotalDisplay);
  }
Ejemplo n.º 19
0
  @Override
  public String execute() throws Exception {
    HttpServletRequest request = ServletActionContext.getRequest();
    setIid(Long.parseLong(request.getParameter("iid")));
    userSession.put("iid", iid);
    //   	String auth = (String) userSession.get("auth");
    rid = (Long) userSession.get("rid");
    Order order = waresService.getOrderByIid(iid);
    if (order != null) {
      userSession.put("ordered", (String) "y");
      List dishes = (List) (waresService.getOrderDish(order.getOrderId()));
      userSession.put("orderdishes", dishes);
    } else {
      List menudishes = waresService.getMenuDish(rid);
      userSession.put("menudishes", menudishes);
    }
    //        auth = (String) userSession.get("auth");
    //        if (auth == null) {
    //       	return INPUT;
    //       }

    return SUCCESS;
  }
  private void display() {

    // create labels and textfields
    Label lbl_klantNaam = new Label("Klant naam:");
    lbl_klantNaam.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_klantID = new Label("Klant email:");
    lbl_klantID.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_klantAdres = new Label("Klant adres:");
    lbl_klantAdres.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_factuurNummer = new Label("Factuur nummer:");
    lbl_factuurNummer.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_factuurDatum = new Label("Factuur datum:");
    lbl_factuurDatum.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_debiteurenNummer = new Label("Debiteuren nummer:");
    lbl_debiteurenNummer.setTextFill((Color.valueOf("#FFFC00")));

    String klantHeleNaam = klantVoornaam + " " + klantAchternaam;
    Label lbl_DklantNaam = new Label(klantHeleNaam);
    lbl_DklantNaam.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_DklantID = new Label(order.getKlantEmail());
    lbl_DklantID.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_DklantAdres = new Label(order.getFactuurAdres());
    lbl_DklantAdres.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_DfactuurNummer = new Label(Integer.toString(order.getOrderID()));
    lbl_DfactuurNummer.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_DfactuurDatum = new Label(order.getOrderDatum().toString());
    lbl_DfactuurDatum.setTextFill((Color.valueOf("#FFFC00")));
    Label lbl_DdebiteurenNummer = new Label(Integer.toString(debiteurenNummer));
    lbl_DdebiteurenNummer.setTextFill((Color.valueOf("#FFFC00")));

    TextField tf_wijnnaam = new TextField();
    TextField tf_prijs = new TextField();

    table.setEditable(true);

    TableColumn<OrderRegel, Integer> codeCol = new TableColumn<>("Nr");
    codeCol.setCellValueFactory(new PropertyValueFactory<>("orderRegelID"));

    TableColumn<OrderRegel, Integer> aantalCol = new TableColumn("Aantal");
    aantalCol.setCellValueFactory(new PropertyValueFactory<>("aantal"));

    TableColumn<OrderRegel, Integer> wijnCol = new TableColumn("Wijn serie nr");
    wijnCol.setCellValueFactory(new PropertyValueFactory<>("wijnID"));

    TableColumn<OrderRegel, String> naamCol = new TableColumn("Naam");
    naamCol.setCellValueFactory(new PropertyValueFactory<>("wijnNaam"));

    TableColumn<OrderRegel, Integer> jaartalCol = new TableColumn("Jaartal");
    jaartalCol.setCellValueFactory(new PropertyValueFactory<>("wijnJaartal"));

    TableColumn<OrderRegel, Integer> perflesCol = new TableColumn("Per fles");
    perflesCol.setCellValueFactory(new PropertyValueFactory<>("wijnPrijs"));

    TableColumn<OrderRegel, Double> bedragCol = new TableColumn("Bedrag");
    bedragCol.setCellValueFactory(new PropertyValueFactory<>("totaalPrijs"));

    table = new TableView<>();
    ObservableList<OrderRegel> orders =
        FXCollections.observableArrayList(orderController.getAlleOrderRegels(order.getOrderID()));
    table.setItems(orders);
    table.getColumns().addAll(wijnCol, naamCol, jaartalCol, aantalCol, perflesCol, bedragCol);

    // topbox items
    title = new Label("Lions-club Oegstgeest/Warmond");
    title.setId("title");
    title.setTextFill(Color.web("#FFCF03"));
    title.autosize();

    icon = new ImageView(new Image("/images/icon.png"));
    icon.setPreserveRatio(true);
    icon.autosize();

    // buttons
    cancel = new Button("Terug");
    cancel.setOnAction(
        e -> new BestellingOverzichtView(new OrderController(), new KlantController()));

    Button exporteer = new Button("Exporteer naar PDF");
    exporteer.setOnAction(
        e -> {
          factuurGenerator =
              new FactuurGenerator(klantController.getKlantByOrder(order), order, orders);
          factuurGenerator.factuur();

          Alert alert = new Alert(AlertType.INFORMATION);
          alert.setHeaderText(null);
          alert.setTitle("Exporteer naar PDF");
          alert.setContentText("De factuur is succesvol ge�xporteerd. ");

          alert.showAndWait();
        });

    // add elements to panes
    topBox.getChildren().addAll(icon, title);
    topBox.setAlignment(Pos.CENTER);

    centerBox.getChildren().add(form);
    centerBox.getChildren().add(table);

    form.addColumn(
        0,
        lbl_klantNaam,
        lbl_klantID,
        lbl_klantAdres,
        lbl_factuurNummer,
        lbl_factuurDatum,
        lbl_debiteurenNummer);
    form.addColumn(
        1,
        lbl_DklantNaam,
        lbl_DklantID,
        lbl_DklantAdres,
        lbl_DfactuurNummer,
        lbl_DfactuurDatum,
        lbl_DdebiteurenNummer);
    form.addColumn(2, exporteer);

    bottomBox.getChildren().add(cancel);
    bottomBox.getChildren().add(exporteer);

    mainPane.setTop(topBox);
    mainPane.setCenter(centerBox);
    mainPane.setBottom(bottomBox);
    stage.setScene(scene);
  }
Ejemplo n.º 21
0
  /**
   * Handles input in the WaitingForPhoneNumber state.
   *
   * @param message The string message.
   * @param channel The channel from which the input was received.
   */
  private void handleDisplayingOrder(String message, NewOrderInChan channel) {

    // Only one channel to get input.
    switch ((NewOrderInChan) channel) {
      case ICMenuOption:

        // Check which button was pressed.
        if (message.equalsIgnoreCase(NewOrderView.ADD_PIZZA_KEY)) {

          // Get a new pizza from the AddPizzaController, then
          // add it to the order.

          AddPizzaController apCont = new AddPizzaController(_currentOrder.getFoodItems());
          AddPizzaView apView =
              PizzaDeliverySystem.RUN_WITH_GUI ? new AddPizzaViewGUI() : new AddPizzaViewCL();

          apCont.setView(apView);
          apView.setController(apCont);
          _currentOrder.getFoodItems().addAll(apCont.getPizzas());

          // Return to this state (so we update all the information).
          gotoDisplayingOrder();

        } else if (message.equalsIgnoreCase(NewOrderView.ADD_SIDE_KEY)) {

          // Get a new side from the AddSideController, then
          // add it to the order.
          AddSideController asCont = new AddSideController(_quantityMap);
          AddSideView asView = PizzaDeliverySystem.RUN_WITH_GUI ? new AddSideViewGUI() : null;
          asCont.setView(asView);
          asView.setController(asCont);
          asCont.enterInitialState();

          // Return to this state (so we update all the information).
          gotoDisplayingOrder();

        } else if (message.equalsIgnoreCase(NewOrderView.DONE_KEY)) {

          // Print an error message if the order is empty.
          if (_currentOrder.getFoodItems().size() == 0)
            handleInputError("Orders must contain at least one item.");
          else {

            // Update the fooditem list in the order.
            updateOrderFoodItemList();

            // Send the order to the kitchen.
            Kitchen.addOrder(_currentOrder);

            // Proceed to the order confirmation.
            gotoDisplayingOrderConfirmation();
          }

        } else if (message.equalsIgnoreCase(NewOrderView.REFRESH_KEY)) {

          // Reload this state.
          gotoDisplayingOrder();

        } else {
          handleInputError("The input was invalid. Please try again.");
        }

        break;

      case ICConfirm:
        if (message.equalsIgnoreCase(NewOrderView.CANCEL_KEY)) {

          // Go back to the main prompt.
          this.active = false;
        }
        break;

      case ICListDelete:
      case ICListModify:

        // The message should be a list index.  Get the list index
        // and delete/modify the food item from the order at that index.
        int index = -1;
        try {
          index = Integer.parseInt(message);
          if (index < 0 || index >= _currentOrder.getFoodItems().size()) {
            handleInputError("Index out of range. Please try again.");
          }
        } catch (NumberFormatException e) {
          handleInputError("The input was invalid. Please try again.");
        }

        if (index >= 0 && index < _currentOrder.getFoodItems().size()) {

          FoodItem selectedItem = _currentOrder.getFoodItems().get(index);

          if (channel == NewOrderInChan.ICListDelete) {

            _currentOrder.removeFoodItem(selectedItem);

          } else if (channel == NewOrderInChan.ICListModify) {

            // Create a new AddPizza or AddSide controller, telling
            // it that we're modifying the item.
            if (selectedItem instanceof PizzaFoodItem) {

              AddPizzaController apCont;
              AddPizzaView apView;
              if (PizzaDeliverySystem.RUN_WITH_GUI) {

                apCont = new AddPizzaController(_currentOrder.getFoodItems());
                apView = new AddPizzaViewGUI((PizzaFoodItem) selectedItem);
              } else {
                apCont = new AddPizzaController((PizzaFoodItem) selectedItem, true);
                apView = new AddPizzaViewCL();
              }
              apCont.setView(apView);
              apView.setController(apCont);
              _currentOrder.getFoodItems().addAll(apCont.getPizzas());
              _currentOrder.removeFoodItem(selectedItem);

            } else {

              AddSideController asCont = new AddSideController(_quantityMap);
              AddSideView asView = PizzaDeliverySystem.RUN_WITH_GUI ? new AddSideViewGUI() : null;
              asCont.setView(asView);
              asView.setController(asCont);
              asCont.enterInitialState();
            }
          }
        }

        gotoDisplayingOrder();

        break;

      case ICBack:

        // Check for a back button.
        if (message.equalsIgnoreCase(NewOrderView.BACK_KEY)) {

          // Go back to the customer phone number prompt.
          gotoWaitingForCustInfo();
        }
        break;

      default:
        handleInputError("The input was invalid. Please try again.");
        break;
    }
  }
Ejemplo n.º 22
0
 /**
  * Test method for {@link controller.OrderInterface#addItemToOrder(model.Order, model.MenuItem)}.
  * Test with a null item param. Expect error
  */
 @Test(expected = model.PizzaException.class)
 public void testAddItemToOrderNullItem() throws PizzaException {
   Order temp = test.getOrderInterface().createNewOrder(itemList, pizzaList);
   test.getOrderInterface().addItemToOrder(temp, null);
   assertTrue(temp.getItems().size() == 0);
 }
Ejemplo n.º 23
0
 public void addOrder(Order tmp) {
   orders.put(tmp.getOrderNo(), tmp);
 }
Ejemplo n.º 24
0
  /**
   * Handles input in the WaitingForPhoneNumber state.
   *
   * @param message The string message.
   * @param channel The channel from which the input was received.
   */
  private void handleWaitingForPhoneNumber(String message, NewOrderInChan channel) {

    // Only one channel to get input.
    switch ((NewOrderInChan) channel) {
      case ICMenuOption:
        // Do nothing
        break;

      case ICCustomerPhone:

        // Check the phone number input for validity.
        if (Customer.isValidPhoneNumber(message)) {

          // Check for the customer in the database.
          Customer foundCust = null;
          for (Customer cust : Customer.getDb().list()) {
            if (cust.getPhoneNumber().equals(message)) {
              foundCust = cust;
              break;
            }
          }

          // Search for the customer in the database.
          if (foundCust != null) {

            // Set this as the current customer for the order
            // and proceed to the displaying order state.
            _currentOrder.setCustomer(foundCust);
            gotoDisplayingOrder();

          } else {

            // If the customer is not in the database, go to the add
            // customer state.
            _currentOrder.getCustomer().setPhoneNumber(message);
            gotoWaitingForCustInfo();
          }

        } else {

          // Report an error.
          handleInputError(
              "<html>Phone numbers must be numeric and 10 characters in length.</html>");
        }
        break;

      case ICBack:

        // Check for a back button.
        if (message.equalsIgnoreCase(NewOrderView.BACK_KEY)) {

          // Set active to false.  In the GUI version, pop the current
          // view.
          this.active = false;

          if (PizzaDeliverySystem.RUN_WITH_GUI) {
            PDSViewManager.popView();
          }
        }
        break;

      default:
        handleInputError("The input was invalid. Please try again.");
        break;
    }
  }