Beispiel #1
0
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      if (request.getMethod().equals("GET")) {
        HttpSession session = request.getSession();
        String username = session.getAttribute("USERNAME").toString();
        UserEntityDAO userDAO = new UserEntityDAO();
        UserEntity thisUser = userDAO.getUserDetails(username);

        UnavailableProjectDAO unavailableProjDAO = new UnavailableProjectDAO();
        List<UnavailableProjectEntity> currentProj =
            unavailableProjDAO.getAllProjectsTypeOrg(ProjectCharterDAO.ON_GOING, thisUser.getId());

        unavailableProjDAO = new UnavailableProjectDAO();
        List<UnavailableProjectEntity> currentProjList =
            unavailableProjDAO.getAllProjectsTypeOrgCommunity(
                ProjectCharterDAO.ON_GOING, thisUser.getId());

        request.setAttribute("currentProj", currentProj);
        request.setAttribute("currentProjList", currentProjList);
        session.removeAttribute("isChangeCharter");
        RequestDispatcher dispatcher = request.getRequestDispatcher("/sysOrg/CurrentProjects.jsp");
        dispatcher.forward(request, response);
      } else if (request.getMethod().equals("POST")) {
        if (request.getParameter("ViewFullProjectCharter") != null) {
          String project_id = request.getParameter("ViewFullProjectCharter");
          HttpSession session = request.getSession();
          session.setAttribute("project_id", project_id);
          response.sendRedirect("ViewFullProjectCharter");
        } else if (request.getParameter("WorkStructure") != null) {
          String project_id = request.getParameter("WorkStructure");
          String[] id_type = project_id.split("-");
          HttpSession session = request.getSession();
          session.setAttribute("project_id", id_type[0]);
          if (id_type[1].equals("Seminar")) {
            session.setAttribute("typeOfStructure", "seminar");
            response.sendRedirect("WorkStructure_Seminar");
          } else {
            session.setAttribute("typeOfStructure", "health");
            response.sendRedirect("WorkStructure_Health");
          }
        }
      }
    } finally {
      out.close();
    }
  }
  /**
   * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
   *
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
      if (request.getMethod().equals("GET")) {
        HttpSession session = request.getSession();
        int project_id = Integer.parseInt((String) session.getAttribute("project_id"));

        UnavailableProjectDAO unavailableDAO = new UnavailableProjectDAO();
        UnavailableProjectEntity unavailableProj = unavailableDAO.getUnavailableProject(project_id);
        ProjectTaskDAO taskDAO = new ProjectTaskDAO();
        ProjectTaskEntity preActs =
            taskDAO.getAllTasksOfTypeForProject(project_id, ProjectTaskDAO.PRE_ACTS).get(0);
        TaskDetailsDAO detailsDAO = new TaskDetailsDAO();
        List<TaskDetailsEntity> speakerList =
            detailsDAO.getAllTask(project_id, ProjectTaskDAO.SPEAKER);

        request.setAttribute("unavailableProj", unavailableProj);
        request.setAttribute("preActs", preActs);
        request.setAttribute("speakerList", speakerList);
        RequestDispatcher dispatcher =
            request.getRequestDispatcher("/sysOrg/WorkStructure_Seminar.jsp");
        dispatcher.forward(request, response);
      } else if (request.getMethod().equals("POST")) {
        HttpSession session = request.getSession();
        session.removeAttribute("lackPreacts");
        session.removeAttribute("lackSpeaker");
        int project_id = Integer.parseInt((String) session.getAttribute("project_id"));

        ProjectTaskDAO taskDAO = new ProjectTaskDAO();
        ProjectTaskEntity preActs =
            taskDAO.getAllTasksOfTypeForProject(project_id, ProjectTaskDAO.PRE_ACTS).get(0);
        TaskDetailsDAO detailsDAO = new TaskDetailsDAO();
        List<TaskDetailsEntity> speakerList =
            detailsDAO.getAllTask(project_id, ProjectTaskDAO.SPEAKER);

        boolean preacts = false;
        boolean speaker = false;

        if (preActs.getCompleted() != 0) {
          preacts = true;
        }
        for (int x = 0; x < speakerList.size(); x++) {
          if (speakerList.get(x).getCurrentcount() > 0) {
            speaker = true;
            break;
          }
        }

        if (!preacts) {
          session.setAttribute("lackPreacts", true);
        }
        if (!speaker) {
          session.setAttribute("lackSpeaker", true);
        }

        if (!preacts || !speaker) {
          response.sendRedirect("WorkStructure_Health");
        } else {
          ProjectCharterDAO charterDAO = new ProjectCharterDAO();
          boolean addDB = charterDAO.updateProjectStatus(project_id, ProjectCharterDAO.IMPLMENTED);

          if (addDB) {
            session.removeAttribute("project_id");
            response.sendRedirect("CloseProjects");
          } else {
            response.sendRedirect("ErrorInDB");
          }
        }
      }
    } finally {
      out.close();
    }
  }