/**
   * {@inheritDoc}
   *
   * @see edu.hm.lip.pizza.api.communication.request.IOrderService#getNextOrderStage(int)
   */
  @Override
  public String getNextOrderStage(int id) {
    EntityOrder eOrder = orderDAOBean.read(id);
    List<EntityOrderStage> eOrderStages = eOrder.getStages();
    EntityOrderStage nextStage = OrderStageManager.next(eOrderStages);

    if (nextStage == null) {
      return null;
    }
    return "{\"nextStage\": " + nextStage.getStage().name() + "}";
  }
  /**
   * {@inheritDoc}
   *
   * @see edu.hm.lip.pizza.api.communication.request.IOrderService#createNextOrderStage(int)
   */
  @Override
  @Interceptors({OrderStageMailInterceptor.class, BillingPrintMailInterceptor.class})
  public Order createNextOrderStage(int id) {
    EntityOrder eOrder = orderDAOBean.read(id);
    List<EntityOrderStage> eOrderStages = eOrder.getStages();

    EntityOrderStage nextStage = OrderStageManager.next(eOrderStages);
    if (nextStage != null) {
      nextStage.setOrder(eOrder);
      eOrderStages.add(nextStage);
      orderDAOBean.update(eOrder);
    }

    return OrderConverter.convertEntityToServiceOrder(eOrder);
  }
  /**
   * {@inheritDoc}
   *
   * @see edu.hm.lip.pizza.api.communication.request.IOrderService#updateOrderToDelivered(int)
   */
  @Override
  @Interceptors(OrderDeliveredActiveMQInterceptor.class)
  public Order updateOrderToDelivered(int id) {
    EntityOrder eOrder = orderDAOBean.read(id);
    List<EntityOrderStage> eOrderStages = eOrder.getStages();

    EntityOrderStage nextStage = OrderStageManager.next(eOrderStages);
    if (nextStage != null && nextStage.getStage() == Stage.DELIVERED) {
      nextStage.setOrder(eOrder);

      eOrderStages.add(nextStage);

      orderDAOBean.update(eOrder);
    }

    return OrderConverter.convertEntityToServiceOrder(eOrder);
  }