/**
   * Displays a Discussion Thread page
   *
   * <p>- Requires a cookie for the session user - Requires a threadId request parameter for the
   * HTTP GET
   *
   * @param req The HTTP Request
   * @param res The HTTP Response
   */
  public void discussionAction(HttpServletRequest req, HttpServletResponse res) {
    // Ensure there is a cookie for the session user
    if (AccountController.redirectIfNoCookie(req, res)) return;

    Map<String, Object> viewData = new HashMap<>();

    if (req.getMethod() == HttpMethod.Get) {

      // Get the thread
      GroupManager gm = new GroupManager();
      int threadId = Integer.parseInt(req.getParameter("threadId"));
      DiscussionManager discussionManager = new DiscussionManager();
      DiscussionThread thread = discussionManager.getThread(threadId);
      thread.setGroup(gm.get(thread.getGroupId()));
      thread.setPosts(discussionManager.getPosts(threadId));

      // get documents for the thread
      DocumentManager docMan = new DocumentManager();
      viewData.put("documents", docMan.getDocumentsForThread(threadId));

      viewData.put("thread", thread);
      viewData.put("title", "Discussion: " + thread.getThreadName());
      view(req, res, "/views/group/DiscussionThread.jsp", viewData);
    } else {
      httpNotFound(req, res);
    }
  }
  /**
   * Creates a Discussion Thread in the database
   *
   * @param discussion The Discussion to insert
   */
  public void createDiscussion(DiscussionThread discussion) {
    try {
      // Create a prepared statement
      PreparedStatement pstmt =
          conn.prepareStatement(
              "INSERT INTO DiscussionThreads (GroupId, ThreadName)" + "VALUES (?, ?)",
              Statement.RETURN_GENERATED_KEYS);

      // Set the required parameters and execute
      pstmt.setInt(1, discussion.getGroupId());
      pstmt.setString(2, discussion.getThreadName());
      pstmt.executeUpdate();

      // Get the generated id
      ResultSet rs = pstmt.getGeneratedKeys();
      if (rs.next()) discussion.setId(rs.getInt(1));
    } catch (Exception e) {
      logger.log(Level.SEVERE, "SQL Error", e);
    }
  }