예제 #1
0
  @RequestMapping(value = "/waiter/bills/{billId}", method = RequestMethod.GET)
  public String showBillInWaiter(
      @PathVariable("billId") String billId, Model uiModel, Locale locale) {

    // warmup stuff
    Bill bill = warmupRestaurant(billId, uiModel);
    Restaurant resto = bill.getDiningTable().getRestaurant();

    List<Order> allPreparedOrders = orderService.findPreparedOrdersForRestaurant(resto);
    uiModel.addAttribute("allPreparedOrders", allPreparedOrders);

    List<Bill> allSubmittedBills = billService.findSubmittedBillsForRestaurant(resto);
    uiModel.addAttribute("allSubmittedBills", allSubmittedBills);

    uiModel.addAttribute(
        "message",
        new Message(
            "info",
            messageSource.getMessage("label_bill_amount", new Object[] {}, locale)
                + ": "
                + bill.getPriceAllOrders()
                + " "
                + messageSource.getMessage("label_currency", new Object[] {}, locale)));

    return "hartigehap/waiter";
  }
예제 #2
0
  @RequestMapping(value = "/waiter/orders/{orderId}", method = RequestMethod.GET)
  public String showOrderInWaiter(
      @PathVariable("orderId") String orderId, Model uiModel, Locale locale) {

    // warmup stuff
    Order order = warmupRestaurantByOrder(orderId, uiModel);
    Restaurant resto = order.getBill().getDiningTable().getRestaurant();

    List<Order> allPreparedOrders = orderService.findPreparedOrdersForRestaurant(resto);
    uiModel.addAttribute("allPreparedOrders", allPreparedOrders);

    List<Bill> allSubmittedBills = billService.findSubmittedBillsForRestaurant(resto);
    uiModel.addAttribute("allSubmittedBills", allSubmittedBills);

    String orderContent = "";
    for (OrderItem orderItem : order.getOrderItems()) {
      orderContent +=
          orderItem.getMenuItem().getId() + " (" + orderItem.getQuantity() + "x)" + "; ";
    }

    uiModel.addAttribute(
        "message",
        new Message(
            "info",
            messageSource.getMessage("label_order_content", new Object[] {}, locale)
                + ": "
                + orderContent));

    return "hartigehap/waiter";
  }
  @RequestMapping(value = "/restaurants/{restaurantName}/kitchen", method = RequestMethod.GET)
  public String showKitchen(@PathVariable("restaurantName") String restaurantName, Model uiModel) {

    // warmup stuff
    Collection<Restaurant> restaurants = restaurantService.findAll();
    uiModel.addAttribute("restaurants", restaurants);
    Restaurant restaurant = restaurantService.fetchWarmedUp(restaurantName);
    uiModel.addAttribute("restaurant", restaurant);

    List<Order> allSubmittedOrders = orderService.findSubmittedOrdersForRestaurant(restaurant);
    uiModel.addAttribute("allSubmittedOrders", allSubmittedOrders);

    List<Order> allPlannedOrders = orderService.findPlannedOrdersForRestaurant(restaurant);
    uiModel.addAttribute("allPlannedOrders", allPlannedOrders);

    return "hartigehap/kitchen";
  }
예제 #4
0
 private Order warmupRestaurantByOrder(String orderId, Model uiModel) {
   Order order = orderService.findById(Long.valueOf(orderId));
   Collection<Restaurant> restaurants = restaurantService.findAll();
   uiModel.addAttribute("restaurants", restaurants);
   Restaurant restaurant =
       restaurantService.fetchWarmedUp(order.getBill().getDiningTable().getRestaurant().getId());
   uiModel.addAttribute("restaurant", restaurant);
   return order;
 }
예제 #5
0
 private void orderHasBeenServed(Order order) {
   try {
     orderService.orderServed(order);
   } catch (StateException e) {
     log.error(
         "Internal error has occurred! Order "
             + Long.valueOf(order.getId())
             + "has not been changed to served state!",
         e);
   }
 }
  // this method serves kitchen subsystem and waiter subsystem requests,
  // which is quite confusing!
  // Reason is that the actual resource "orders/{orderId}" that is asked for,
  // is the same for kitchen subsystem and waiter subsystem,
  // meaning that the request URI is the same (according to REST).
  // You cannot have two methods with the same request URI mapping.
  // It is because the "event" request parameter (which is the distinguishing
  // parameter) is part of the HTTP body and can therefore not be
  // used for the request mapping.
  @RequestMapping(value = "/orders/{orderId}", method = RequestMethod.PUT)
  public String receiveEvent(
      @PathVariable("orderId") String orderId,
      @RequestParam String event,
      Model uiModel,
      Locale locale) {

    Order order = orderService.findById(Long.valueOf(orderId));
    Restaurant restaurant = warmupRestaurant(order, uiModel);

    switch (event) {
      case "planOrder":
        try {
          orderService.planOrder(order);
        } catch (StateException e) {
          logger.error(
              "Internal error has occurred! Order "
                  + Long.valueOf(orderId)
                  + "has not been changed to planned state!",
              e);

          // StateException triggers a rollback; consequently all Entities are invalidated by
          // Hibernate
          // So new warmup needed
          warmupRestaurant(order, uiModel);
          return "hartigehap/kitchen";
        }
        return "redirect:/restaurants/" + restaurant.getId() + "/kitchen";
        // break unreachable

      case "orderHasBeenPrepared":
        try {
          orderService.orderPrepared(order);
        } catch (StateException e) {
          logger.error(
              "Internal error has occurred! Order "
                  + Long.valueOf(orderId)
                  + "has not been changed to prepared state!",
              e);

          // StateException triggers a rollback; consequently all Entities are invalidated by
          // Hibernate
          // So new warmup needed
          warmupRestaurant(order, uiModel);
          return "hartigehap/kitchen";
        }
        return "redirect:/restaurants/" + restaurant.getId() + "/kitchen";
        // break unreachable

      case "orderHasBeenServed":
        try {
          orderService.orderServed(order);
        } catch (StateException e) {
          logger.error(
              "Internal error has occurred! Order "
                  + Long.valueOf(orderId)
                  + "has not been changed to served state!",
              e);

          // StateException triggers a rollback; consequently all Entities are invalidated by
          // Hibernate
          // So new warmup needed
          warmupRestaurant(order, uiModel);
          return "hartigehap/waiter";
        }
        return "redirect:/restaurants/" + restaurant.getId() + "/waiter";
        // break unreachable

      default:
        logger.error("Internal error: event " + event + " not recognized");
        return "redirect:/restaurants/" + restaurant.getId();
    }
  }