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; }
// 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(); } }