Exemplo n.º 1
0
  /** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String bids = request.getParameter("bid");
    Integer bid = null;

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1.
    response.setHeader("Pragma", "no-cache"); // HTTP 1.0.
    response.setDateHeader("Expires", 0); // Proxies.

    if (bids != null) {

      try {
        bid = Integer.parseInt(bids);
      } catch (Exception e) {
        bid = 0;
      }
    }

    // Displays welcome page
    if (bid == null || bid == 0) {
      List<Brassin> brewList = brassinService.getAllElements();
      logger.fine("Got : " + brewList);
      request.setAttribute("brewList", brewList);
      request.getRequestDispatcher("accueil_viewer.jsp").forward(request, response);
    }

    // Displays brew page
    else if (bid > 0) {

      logger.fine("Retrieving brew from DB for id : " + bid);
      Brassin currentBrew = brassinService.getElementById(bid);

      if (currentBrew != null) {
        logger.fine("Found 1 brew : " + currentBrew);
      }
      request.setAttribute("brassin", currentBrew);

      logger.fine("Steps for brew : " + currentBrew.getBra_etapes());

      List<Actioner> availableActioners = new ArrayList<Actioner>();

      availableActioners = DeviceParser.getInstance().getDevices(Constants.DEVICES_PROPERTIES);
      for (Actioner act : availableActioners) {

        logger.fine(
            "Device : "
                + act.getAct_nom()
                + ", pin="
                + act.getAct_raspi_pin()
                + ", uuid="
                + act.getAct_uuid());
      }

      for (Etape step : currentBrew.getBra_etapes()) {

        logger.fine("||" + step.getEtp_nom() + " " + step.getEtp_id() + " " + step.getEtp_numero());
      }

      request.setAttribute(
          "stepCounter", Math.ceil((double) currentBrew.getBra_etapes().size()) - 1);
      request.setAttribute("steps", currentBrew.getBra_etapes());
      request.setAttribute("availableActioners", availableActioners);
      request.setAttribute(
          "tempServlet",
          ConfigLoader.getConfigByKey(Constants.CONFIG_PROPERTIES, "servlets.temperature.graph"));

      request.setAttribute(
          "actionerServiceAddress",
          ConfigLoader.getConfigByKey(
              Constants.CONFIG_PROPERTIES, "servlets.actioners.activation"));

      request.getRequestDispatcher("brew.jsp").forward(request, response);
    }
  }