/**
   * Default Method of this controller.
   *
   * @param request
   * @param response
   * @return
   */
  public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
    ModelAndView mav = new ModelAndView("change_password");

    HttpSession session = request.getSession(true);
    String currentPassword = (String) request.getParameter("currentpassword");
    String newPassword = (String) request.getParameter("newpassword");

    if (currentPassword != null && !currentPassword.equals("")) {
      try {
        long teamId = Long.parseLong((String) request.getSession().getAttribute(Constants.TEAM_ID));
        Team team = teamService.getTeamOnTeamId(teamId);
        if (team.getTeamPassword().equals(currentPassword)) {

          try {
            team.setTeamPassword(newPassword);
            teamService.updateTeam(team);

            session.setAttribute("message", "Password changed successfully.");
            session.setAttribute("status", "success");
          } catch (Exception e) {
            logger.error("Error in changing password", e);
          }

        } else {
          session.setAttribute(
              "message",
              "The current password you entered is incorrect. Is the 'Caps Lock' is turned on by mistake? Passwords are case-sensitive.");
          session.setAttribute("status", "failed");
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return mav;
  }
  public ModelAndView manageTeamOperations(
      HttpServletRequest request, HttpServletResponse response) {
    ModelAndView mav = new ModelAndView("manageTeamOperations");

    Team loggedInTeam = (Team) request.getSession().getAttribute(Constants.TEAM_OBJECT);
    int currPeriod = (Integer) request.getSession().getAttribute(Constants.CURRENT_PERIOD);

    // Code to save/update the operations data.
    String todo = request.getParameter("todo");
    if (todo != null && !("".equals(todo)) && todo.equalsIgnoreCase("saveTeamOperations")) {
      long teamCurrentBudget = (Long) request.getSession().getAttribute(Constants.CURRENT_BUDGET);
      String capacityIncreaseRadioSelection = request.getParameter("capacityIncreaseSelection");

      if (capacityIncreaseRadioSelection != null && !"".equals(capacityIncreaseRadioSelection)) {
        int increaseCapacityBy = Integer.parseInt(capacityIncreaseRadioSelection.split(":")[0]);
        int costIncurrend = Integer.parseInt(capacityIncreaseRadioSelection.split(":")[1]);

        TeamOperations teamOperations =
            operationsService.getTeamOperations(loggedInTeam, currPeriod);

        if (teamOperations != null) {
          // previously selected capacity increase (manage the budget accordingly)
          int currentExpansionCost = teamOperations.getExpansionCost();

          long updatedBudget = teamCurrentBudget + currentExpansionCost - costIncurrend;
          if (updatedBudget > 0) {
            // the updated budget is > 0, so update the TeamOperations production capacity

            teamOperations.setCapacityIncreasedBy(increaseCapacityBy);
            teamOperations.setExpansionCost(costIncurrend);
            operationsService.updateTeamOperations(teamOperations);

            // update team budget
            request.getSession().removeAttribute(Constants.CURRENT_BUDGET);
            request.getSession().setAttribute(Constants.CURRENT_BUDGET, updatedBudget);

            loggedInTeam.setTeamCurrentPeriodBudget(updatedBudget);
            teamService.updateTeam(loggedInTeam);
          }
        } else {
          // creating TeamOperations entry for the first time
          TeamOperations thisPeriodTeamOperations = new TeamOperations();

          thisPeriodTeamOperations.setCapacityIncreasedBy(increaseCapacityBy);
          thisPeriodTeamOperations.setExpansionCost(costIncurrend);
          thisPeriodTeamOperations.setMaximumCapacity(0);
          thisPeriodTeamOperations.setPeriod(currPeriod);
          thisPeriodTeamOperations.setTeam(loggedInTeam);

          long updatedBudget = teamCurrentBudget - costIncurrend;
          if (updatedBudget > 0) {
            operationsService.saveTeamOperations(thisPeriodTeamOperations);

            // update team budget
            request.getSession().removeAttribute(Constants.CURRENT_BUDGET);
            request.getSession().setAttribute(Constants.CURRENT_BUDGET, updatedBudget);

            loggedInTeam.setTeamCurrentPeriodBudget(updatedBudget);
            teamService.updateTeam(loggedInTeam);
          }
        }
      }
    }

    // Now fetching the most updated operations data from database and passing to UI
    TeamOperations teamOperations = operationsService.getTeamOperations(loggedInTeam, currPeriod);

    mav.addObject(Constants.TEAM_OPERATIONS, teamOperations);
    return mav;
  }