Example #1
0
  /**
   * When browsing objects, we'd like to make it possible to interface the object type list with a
   * Dojo Data Source. To do so, we stream the objects out as a JSON object.
   *
   * @param request
   * @param response
   * @throws ServletException
   * @throws IOException
   */
  private void doObjTypeRequestJSON(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    int fromIndex, maxResult;
    Connection c;
    PreparedStatement st;
    ResultSet set;
    JsonWriter jOut;
    int recCount;

    //	Set the content up

    response.setContentType("application/json");

    //	Setup our database information

    c = null;
    st = null;
    set = null;

    //	Setup the rest of our environment

    recCount = 0;

    jOut = new JsonWriter(response.getWriter());

    try {

      //	Parse request parameters

      fromIndex = Integer.parseInt(request.getParameter("start"));
      maxResult = Integer.parseInt(request.getParameter("count"));

      //	Create connection to the database and prep the query

      c = DBResourceManager.getConnection();

      st = c.prepareStatement(OBJTYPE_LIST_JSON);
      st.setInt(1, fromIndex);
      st.setInt(2, maxResult);

      //	Execute the query

      set = st.executeQuery();

      //	Now, stream the results out as if they were an object

      jOut.beginObject();
      jOut.name("items").beginArray();

      while (set.next()) {
        //	Write each element out as an object

        jOut.beginObject();

        jOut.name("objid").value(set.getInt("id"));
        jOut.name("objname").value(set.getString("name"));
        jOut.name("objtilesrc").value(set.getString("tilesrc"));
        jOut.name("description").value(set.getString("description"));

        jOut.endObject();

        //	Increment the record count

        recCount++;
      }

      //	Terminate the array

      jOut.endArray();

      //	Note the number of rows

      jOut.name("numRows").value(recCount);

      //	End the overall object

      jOut.endObject();

      //	Flush the output

      jOut.flush();

    } catch (Exception ex) {
      ex.printStackTrace();

    } finally {

      DataTools.safeCleanUp(c, st, set);
    }
  }
Example #2
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void addObject(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    Connection c;
    PreparedStatement st;
    ResultSet set;

    String objName;
    int objTileSrc;
    int objXOff;
    int objYOff;
    int objWidth;
    int objHeight;
    String objDesc;
    int objId;
    int objAuth;
    Gson Gson;
    FormResponse resp;

    resp = null;

    c = null;
    st = null;
    set = null;

    Gson = new Gson();

    try {

      //	Verify we have authorization to do this! TODO: Set a special response code on authorization
      // failure.

      //	Perform a quick, cursory validation

      resp = validateAddForm(request);

      if (!resp.isAccepted()) {
        resp.setResult("FAIL");

      } else {

        //	Apply parameters

        objName = request.getParameter("title");
        objDesc = request.getParameter("desc");
        objTileSrc = Integer.parseInt(request.getParameter("tileset"));
        objXOff = Integer.parseInt(request.getParameter("objXOff"));
        objYOff = Integer.parseInt(request.getParameter("objYOff"));
        objWidth = Integer.parseInt(request.getParameter("objWidth"));
        objHeight = Integer.parseInt(request.getParameter("objHeight"));
        // objAuth 	= (Integer) request.getSession().getAttribute("userid");
        // TODO: Get the public flag

        System.out.println("Object name: '" + objName + "'");

        //	Generate the query

        c = DBResourceManager.getConnection();

        st = c.prepareStatement(OBJTYPE_INSERT, PreparedStatement.RETURN_GENERATED_KEYS);

        st.setString(1, objName);
        st.setInt(2, objTileSrc);
        st.setInt(3, objXOff);
        st.setInt(4, objYOff);
        st.setInt(5, objWidth);
        st.setInt(6, objHeight);
        st.setString(7, objDesc);

        st.execute();

        set = st.getGeneratedKeys();

        //	Grab the generated key

        if (set.next()) {
          objId = set.getInt(1);

          resp.setResult("OK");
          resp.addParamResult("objId", "VALUEUP:" + objId);

          //	Send the OK. Note that Dojo requires us to wrap the response
          //	in an html doc's text area for max. compatibility.

        } else {

          System.out.println("Failure to create object.");

          resp.setResult("FAIL");
        }
      }

      //	Send the resposne object no matter what

      response
          .getWriter()
          .println("<html><body><textarea>" + Gson.toJson(resp) + "</textarea></html></body>");

    } catch (Exception ex) {
      ex.printStackTrace();

      if (resp == null) {
        resp = new FormResponse();
        resp.setAcceptance(false);
      }

      resp.setResult("FAIL");
      resp.addMessage(ex.toString());

      response
          .getWriter()
          .println("<html><body><textarea>" + ex.toString() + "</textarea></html></body>");

    } finally {

      DataTools.safeCleanUp(c, st, set);
    }
  }
Example #3
0
  // New -- returns data in HashMap
  private static Map viewSignups(
      HttpServletRequest req, PrintWriter out, Connection con, boolean json_mode) {

    int wait_list_id = 0;
    int wait_list_signup_id = 0;
    int sum_players = 0;
    int date = 0;
    int pos = 1;
    int time = SystemUtils.getTime(con);
    int today_date = (int) SystemUtils.getDate(con);
    int start_time = 0;
    int end_time = 0;
    int count = 0;
    int index = 0;
    int player_index = 0;
    Map waitlist_map = new HashMap();
    waitlist_map.put("options", new HashMap());
    waitlist_map.put("signups", new LinkedHashMap());

    String sindex =
        req.getParameter(
            "index"); //  index value of day (needed by Proshop_waitlist_slot when returning)
    String id = req.getParameter("waitListId"); //  uid of the wait list we are working with
    String course = (req.getParameter("course") == null) ? "" : req.getParameter("course");
    String returnCourse =
        (req.getParameter("returnCourse") == null) ? "" : req.getParameter("returnCourse");
    String sdate = (req.getParameter("sdate") == null) ? "" : req.getParameter("sdate");
    String name = (req.getParameter("name") == null) ? "" : req.getParameter("name");
    String day_name = (req.getParameter("day_name") == null) ? "" : req.getParameter("day_name");
    String sstart_time =
        (req.getParameter("start_time") == null) ? "" : req.getParameter("start_time");
    String send_time = (req.getParameter("end_time") == null) ? "" : req.getParameter("end_time");
    // String count = (req.getParameter("count") == null) ? "" : req.getParameter("count");
    String jump = req.getParameter("jump");

    String fullName = "";
    String cw = "";
    String notes = "";
    String nineHole = "";

    PreparedStatement pstmt = null;
    PreparedStatement pstmt2 = null;

    boolean tmp_found = false;
    boolean tmp_found2 = false;
    boolean master =
        (req.getParameter("view") != null && req.getParameter("view").equals("master"));
    boolean show_notes =
        (req.getParameter("show_notes") != null && req.getParameter("show_notes").equals("yes"));
    boolean alt_row = false;
    boolean tmp_converted = false;

    try {

      date = Integer.parseInt(sdate);
      index = Integer.parseInt(sindex);
      wait_list_id = Integer.parseInt(id);
      start_time = Integer.parseInt(sstart_time);
      end_time = Integer.parseInt(send_time);
    } catch (NumberFormatException e) {
    }

    try {

      count = getWaitList.getListCount(wait_list_id, date, index, time, !master, con);

    } catch (Exception exp) {
      out.println(exp.getMessage());
    }

    //
    //  isolate yy, mm, dd
    //
    int yy = date / 10000;
    int temp = yy * 10000;
    int mm = date - temp;
    temp = mm / 100;
    temp = temp * 100;
    int dd = mm - temp;
    mm = mm / 100;

    String report_date = SystemUtils.getLongDateTime(today_date, time, " at ", con);

    if (!json_mode) {
      out.println("<br>");
      out.println(
          "<h3 align=center>"
              + ((master) ? "Master Wait List Sign-up Sheet" : "Current Wait List Sign-ups")
              + "</h3>");

      out.println("<p align=center><font size=3><b><i>\"" + name + "\"</i></b></font></p>");

      out.println("<table border=0 align=center>");

      out.println("<tr><td><font size=\"2\">");
      out.println(
          "Date:&nbsp;&nbsp;<b>"
              + day_name
              + "&nbsp;&nbsp;"
              + mm
              + "/"
              + dd
              + "/"
              + yy
              + "</b></td>");
      out.println("<td>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</td><td>");
      if (!course.equals("")) {
        out.println("<font size=\"2\">Course:&nbsp;&nbsp;<b>" + course + "</b></font>");
      }
      out.println("</td></tr>");

      out.println(
          "<tr><td><font size=\"2\">Time:&nbsp;&nbsp;<b>"
              + SystemUtils.getSimpleTime(start_time)
              + " to "
              + SystemUtils.getSimpleTime(end_time)
              + "</b></font></td>");

      out.println("<td></td>");

      out.println("<td><font size=\"2\">Signups:&nbsp;&nbsp;<b>" + count + "</b></font></td>");

      out.println("</table>");

      out.println(
          "<p align=center><font size=2><b><i>List Generated on "
              + report_date
              + "</i></b></font></p>");

      out.println("<table align=center border=1 bgcolor=\"#F5F5DC\">");

      if (master) {

        out.println(
            "<tr bgcolor=\"#8B8970\" align=center style=\"color: black; font-weight: bold\">"
                + "<td height=35>&nbsp;Pos&nbsp;</td>"
                + "<td>Sign-up Time</td>"
                + "<td>Members</td>"
                + "<td>Desired Time</td>"
                + "<td>&nbsp;Players&nbsp;</td>"
                + "<td>&nbsp;On Sheet&nbsp;</td>"
                + "<td>Converted At</td>"
                + "<td>&nbsp;Converted By&nbsp;</td>"
                + ((show_notes) ? "<td>&nbsp;Notes&nbsp;</td>" : "")
                + "</tr>");
      } else {

        out.println(
            "<tr bgcolor=\"#8B8970\" align=center style=\"color: black; font-weight: bold\">"
                + "<td height=35>&nbsp;Pos&nbsp;</td>"
                + "<td>Members</td>"
                + "<td>Desired Time</td>"
                + "<td>&nbsp;Players&nbsp;</td>"
                + ((show_notes) ? "<td>&nbsp;Notes&nbsp;</td>" : "")
                + "</tr>"); // +
        // "<td>&nbsp;On Sheet&nbsp;</td>" +
        // "</tr>");
        // ((multi == 0) ? "" : "<td>Course</td>") +
      }
      out.println(
          "<!-- wait_list_id=" + wait_list_id + ", date=" + date + ", time=" + time + " -->");
    }

    try {

      pstmt =
          con.prepareStatement(
              ""
                  + "SELECT *, "
                  + "DATE_FORMAT(created_datetime, '%c/%e/%y %r') AS created_time, "
                  + "DATE_FORMAT(converted_at, '%c/%e/%y %r') AS converted_time "
                  + // %l:%i %p
                  "FROM wait_list_signups "
                  + "WHERE wait_list_id = ? AND date = ? "
                  + ((master) ? "" : "AND converted = 0 ")
                  + ((!master && sindex.equals("0")) ? "AND ok_etime > ? " : "")
                  + "ORDER BY created_datetime");

      pstmt.clearParameters();
      pstmt.setInt(1, wait_list_id);
      pstmt.setInt(2, date);
      if (!master && sindex.equals("0")) {
        pstmt.setInt(3, time);
      }

      ResultSet rs = pstmt.executeQuery();

      while (rs.next()) {

        wait_list_signup_id = rs.getInt("wait_list_signup_id");

        if (json_mode) {
          ((Map) waitlist_map.get("signups"))
              .put("signup_id_" + wait_list_signup_id, new LinkedHashMap());
          ((Map) ((Map) waitlist_map.get("signups")).get("signup_id_" + wait_list_signup_id))
              .put("players", new LinkedHashMap());
          ((Map) ((Map) waitlist_map.get("signups")).get("signup_id_" + wait_list_signup_id))
              .put("options", new HashMap());
        } else {
          out.print(
              "<tr align=center"
                  + ((alt_row) ? " style=\"background-color:white\"" : "")
                  + "><td>"
                  + pos
                  + "</td>");
          if (master) {
            out.println("<td>&nbsp;" + rs.getString("created_time") + "&nbsp;</td>");
          }
          out.print("<td align=left>");
        }
        // if (multi == 1) out.println("<td>" + rs.getString("course") + "</td>");

        //
        //  Display players in this signup
        //
        pstmt2 =
            con.prepareStatement(
                ""
                    + "SELECT * "
                    + "FROM wait_list_signups_players "
                    + "WHERE wait_list_signup_id = ? "
                    + "ORDER BY pos");

        pstmt2.clearParameters();
        pstmt2.setInt(1, wait_list_signup_id);

        ResultSet rs2 = pstmt2.executeQuery();

        tmp_found2 = false;
        player_index = 0;

        while (rs2.next()) {

          if (json_mode) {
            player_index++;
            ((Map)
                    ((Map)
                            ((Map) waitlist_map.get("signups"))
                                .get("signup_id_" + wait_list_signup_id))
                        .get("players"))
                .put("player_" + player_index, new HashMap());
            ((Map)
                    ((Map)
                            ((Map)
                                    ((Map) waitlist_map.get("signups"))
                                        .get("signup_id_" + wait_list_signup_id))
                                .get("players"))
                        .get("player_" + player_index))
                .put("player_name", rs2.getString("player_name"));
            ((Map)
                    ((Map)
                            ((Map)
                                    ((Map) waitlist_map.get("signups"))
                                        .get("signup_id_" + wait_list_signup_id))
                                .get("players"))
                        .get("player_" + player_index))
                .put("player_name", rs2.getString("player_name"));
            ((Map)
                    ((Map)
                            ((Map)
                                    ((Map) waitlist_map.get("signups"))
                                        .get("signup_id_" + wait_list_signup_id))
                                .get("players"))
                        .get("player_" + player_index))
                .put("cw", rs2.getString("cw"));
            ((Map)
                    ((Map)
                            ((Map)
                                    ((Map) waitlist_map.get("signups"))
                                        .get("signup_id_" + wait_list_signup_id))
                                .get("players"))
                        .get("player_" + player_index))
                .put("9hole", rs2.getInt("9hole"));
          } else {
            fullName = rs2.getString("player_name");
            cw = rs2.getString("cw");
            if (rs2.getInt("9hole") == 1) {
              cw = cw + "9";
            }
            if (tmp_found2) {
              out.print(",&nbsp; ");
            } else {
              out.print("&nbsp;");
            }
            out.print(fullName + " <font style=\"font-size:9px\">(" + cw + ")</font>");
            tmp_found2 = true;
          }
          sum_players++;
          nineHole = ""; // reset
        }

        pstmt2.close();

        if (json_mode) {

          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("notes", notes);
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("created_time", rs.getInt("created_time"));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("converted", rs.getInt("converted"));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("converted_time", rs.getString("converted_time"));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("converted_by", rs.getString("converted_by"));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("start_time", SystemUtils.getSimpleTime(rs.getInt("ok_stime")));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("end_time", SystemUtils.getSimpleTime(rs.getInt("ok_etime")));
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("wait_list_signup_id", wait_list_signup_id);
          ((Map)
                  ((Map)
                          ((Map) waitlist_map.get("signups"))
                              .get("signup_id_" + wait_list_signup_id))
                      .get("options"))
              .put("player_count", sum_players);
        } else {
          out.print("</td>");
          out.println(
              "<td>&nbsp;"
                  + SystemUtils.getSimpleTime(rs.getInt("ok_stime"))
                  + " - "
                  + SystemUtils.getSimpleTime(rs.getInt("ok_etime"))
                  + "&nbsp;</td>");
          out.println("<td>" + sum_players + "</td>");

          if (master) {

            tmp_converted = rs.getInt("converted") == 1;
            out.println("<td>" + ((tmp_converted) ? "Yes" : "No") + "</td>");
            out.println(
                "<td>" + ((tmp_converted) ? rs.getString("converted_time") : "&nbsp;") + "</td>");
            out.println(
                "<td>" + ((tmp_converted) ? rs.getString("converted_by") : "&nbsp;") + "</td>");
          }

          if (show_notes) {

            notes = rs.getString("notes").trim();
            if (notes.equals("")) {
              notes = "&nbsp;";
            }
            out.println("<td>" + notes + "</td>");
          }

          out.print("</tr>");
        }

        pos++;
        sum_players = 0;
        alt_row = alt_row == false;
      }

      pstmt.close();

    } catch (Exception exc) {

      SystemUtils.buildDatabaseErrMsg(
          "Error loading wait list signups.", exc.toString(), out, false);
    }

    if (json_mode) {

      ((Map) waitlist_map.get("options")).put("index", sindex);
      ((Map) waitlist_map.get("options")).put("wait_list_id", wait_list_id);
      ((Map) waitlist_map.get("options")).put("date", "" + mm + "/" + dd + "/" + yy);
      ((Map) waitlist_map.get("options")).put("name", name);
      ((Map) waitlist_map.get("options")).put("time", time);
      ((Map) waitlist_map.get("options")).put("jump", jump);
      ((Map) waitlist_map.get("options")).put("returnCourse", returnCourse);
      ((Map) waitlist_map.get("options")).put("course", course);
      ((Map) waitlist_map.get("options")).put("master", master);
      ((Map) waitlist_map.get("options")).put("report_date", report_date);
      ((Map) waitlist_map.get("options")).put("show_notes", show_notes);

    } else {

      out.println("</table><br>");

      out.println("<table align=center><tr>");

      out.println("<form action=\"Member_jump\" method=\"POST\" target=\"_top\">");
      out.println("<input type=\"hidden\" name=\"jump\" value=\"0\">");
      out.println("<input type=\"hidden\" name=\"index\" value=" + sindex + ">");
      out.println(
          "<input type=\"hidden\" name=\"course\" value=\""
              + ((!returnCourse.equals("")) ? returnCourse : course)
              + "\">");

      out.println("<td><input type=\"submit\" value=\"Tee Sheet\"></td></form>");

      out.println("<td>&nbsp;&nbsp;</td>");

      out.println("<form action=\"Member_waitlist\" method=\"POST\">");
      out.println("<input type=\"hidden\" name=\"waitListId\" value=\"" + wait_list_id + "\">");
      out.println("<input type=\"hidden\" name=\"date\" value=\"" + date + "\">");
      out.println("<input type=\"hidden\" name=\"day\" value=\"" + day_name + "\">");
      out.println("<input type=\"hidden\" name=\"index\" value=\"" + sindex + "\">");
      out.println("<input type=\"hidden\" name=\"course\" value=\"" + course + "\">");
      out.println("<input type=\"hidden\" name=\"returnCourse\" value=\"" + returnCourse + "\">");
      out.println("<input type=\"hidden\" name=\"jump\" value=\"" + jump + "\">");

      out.println("<td><input type=\"submit\" value=\"Return\"></td></form>");

      out.println("</tr></table></form>");

      out.println("<br>");
    }

    return waitlist_map;
  } // end viewSignups