src/main/java/org/openimmunizationsoftware/pt/servlet/ReportDefinitionEditServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    AppReq appReq = new AppReq(request, response);
    try {
      WebUser webUser = appReq.getWebUser();
      if (appReq.isLoggedOut()) {
        forwardToHome(request, response);
        return;
      }
      Session dataSession = appReq.getDataSession();
      String action = appReq.getAction();
      PrintWriter out = appReq.getOut();
      SimpleDateFormat sdf = webUser.getDateFormat();



      ReportProfile reportProfile = null;

      Query query = dataSession.createQuery("from ReportProfile where profileId = ?");
      query.setParameter(0, Integer.parseInt(request.getParameter("profileId")));
      List<ReportProfile> reportProfileList = query.list();
      reportProfile = reportProfileList.get(0);
      ReportsServlet.loadReportProfileObject(dataSession, reportProfile);

      if (action != null) {
        if (action.equals("Save")) {
          String message = null;
          reportProfile.setDefinition(request.getParameter("definition").getBytes());
          reportProfile.clearReportDefinition();
          // TODO check report

          if (message != null) {
            appReq.setMessageProblem(message);
          } else {
            Transaction transaction = dataSession.beginTransaction();
            try {
              dataSession.saveOrUpdate(reportProfile);
            } finally {
              transaction.commit();
            }
            response.sendRedirect("ReportEditServlet?profileId=" + reportProfile.getProfileId());
            return;
          }
        }
      }

      printHtmlHead(appReq);
      out.println("<form action=\"ReportDefinitionEditServlet\" method=\"POST\">");
      if (reportProfile.getProfileId() > 0) {
        out.println("  <input type=\"hidden\" name=\"profileId\" value=\""
            + reportProfile.getProfileId() + "\">");
      }
      out.println("<table class=\"boxed\">");
      out.println("  <tr>");
      out.println("    <th class=\"title\">Report Definition</th>");
      out.println("  </tr>");
      out.println("  <tr class=\"boxed\">");
      out.println("    <td class=\"boxed\"><textarea name=\"definition\" cols=\"80\" rows=\"60\">"
          + (reportProfile.getDefinition() == null ? "" : new String(reportProfile.getDefinition()))
          + "</textarea></td>");
      out.println("  </tr>");
      out.println("  <tr class=\"boxed\">");
      out.println(
          "    <td class=\"boxed-submit\"><input type=\"submit\" name=\"action\" value=\"Save\"></td>");
      out.println("  </tr>");
      out.println("</table>");
      out.println("</form>");

      printHtmlFoot(appReq);

    } finally {
      appReq.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
   */
Processes requests for both HTTP GET and POST
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
Processes requests for both HTTP GET and POST 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 {
    AppReq appReq = new AppReq(request, response);
    try {
      WebUser webUser = appReq.getWebUser();
      if (appReq.isLoggedOut()) {
        forwardToHome(request, response);
        return;
      }
      Session dataSession = appReq.getDataSession();
      String action = appReq.getAction();
      PrintWriter out = appReq.getOut();
      SimpleDateFormat sdf = webUser.getDateFormat();
      ReportProfile reportProfile = null;
      Query query = dataSession.createQuery("from ReportProfile where profileId = ?");
      query.setParameter(0, Integer.parseInt(request.getParameter("profileId")));
      List<ReportProfile> reportProfileList = query.list();
      reportProfile = reportProfileList.get(0);
      ReportsServlet.loadReportProfileObject(dataSession, reportProfile);
      if (action != null) {
        if (action.equals("Save")) {
          String message = null;
          reportProfile.setDefinition(request.getParameter("definition").getBytes());
          reportProfile.clearReportDefinition();
          if (message != null) {
            appReq.setMessageProblem(message);
          } else {
            Transaction transaction = dataSession.beginTransaction();
            try {
              dataSession.saveOrUpdate(reportProfile);
            } finally {
              transaction.commit();
            }
            response.sendRedirect("ReportEditServlet?profileId=" + reportProfile.getProfileId());
            return;
          }
        }
      }
      printHtmlHead(appReq);
      out.println("<form action=\"ReportDefinitionEditServlet\" method=\"POST\">");
      if (reportProfile.getProfileId() > 0) {
        out.println("  <input type=\"hidden\" name=\"profileId\" value=\""
            + reportProfile.getProfileId() + "\">");
      }
      out.println("<table class=\"boxed\">");
      out.println("  <tr>");
      out.println("    <th class=\"title\">Report Definition</th>");
      out.println("  </tr>");
      out.println("  <tr class=\"boxed\">");
      out.println("    <td class=\"boxed\"><textarea name=\"definition\" cols=\"80\" rows=\"60\">"
          + (reportProfile.getDefinition() == null ? "" : new String(reportProfile.getDefinition()))
          + "</textarea></td>");
      out.println("  </tr>");
      out.println("  <tr class=\"boxed\">");
      out.println(
          "    <td class=\"boxed-submit\"><input type=\"submit\" name=\"action\" value=\"Save\"></td>");
      out.println("  </tr>");
      out.println("</table>");
      out.println("</form>");
      printHtmlFoot(appReq);
    } finally {
      appReq.close();
    }
  }
protected void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { AppReq appReq = new AppReq ( request , response ) ; try { WebUser webUser = appReq . getWebUser ( ) ; if ( appReq . isLoggedOut ( ) ) { forwardToHome ( request , response ) ; return ; } Session dataSession = appReq . getDataSession ( ) ; String action = appReq . getAction ( ) ; PrintWriter out = appReq . getOut ( ) ; SimpleDateFormat sdf = webUser . getDateFormat ( ) ; ReportProfile reportProfile = null ; Query query = dataSession . createQuery ( "from ReportProfile where profileId = ?" ) ; query . setParameter ( 0 , Integer . parseInt ( request . getParameter ( "profileId" ) ) ) ; List < ReportProfile > reportProfileList = query . list ( ) ; reportProfile = reportProfileList . get ( 0 ) ; ReportsServlet . loadReportProfileObject ( dataSession , reportProfile ) ; if ( action != null ) { if ( action . equals ( "Save" ) ) { String message = null ; reportProfile . setDefinition ( request . getParameter ( "definition" ) . getBytes ( ) ) ; reportProfile . clearReportDefinition ( ) ; if ( message != null ) { appReq . setMessageProblem ( message ) ; } else { Transaction transaction = dataSession . beginTransaction ( ) ; try { dataSession . saveOrUpdate ( reportProfile ) ; } finally { transaction . commit ( ) ; } response . sendRedirect ( "ReportEditServlet?profileId=" + reportProfile . getProfileId ( ) ) ; return ; } } } printHtmlHead ( appReq ) ; out . println ( "<form action=\"ReportDefinitionEditServlet\" method=\"POST\">" ) ; if ( reportProfile . getProfileId ( ) > 0 ) { out . println ( "  <input type=\"hidden\" name=\"profileId\" value=\"" + reportProfile . getProfileId ( ) + "\">" ) ; } out . println ( "<table class=\"boxed\">" ) ; out . println ( "  <tr>" ) ; out . println ( "    <th class=\"title\">Report Definition</th>" ) ; out . println ( "  </tr>" ) ; out . println ( "  <tr class=\"boxed\">" ) ; out . println ( "    <td class=\"boxed\"><textarea name=\"definition\" cols=\"80\" rows=\"60\">" + ( reportProfile . getDefinition ( ) == null ? "" : new String ( reportProfile . getDefinition ( ) ) ) + "</textarea></td>" ) ; out . println ( "  </tr>" ) ; out . println ( "  <tr class=\"boxed\">" ) ; out . println ( "    <td class=\"boxed-submit\"><input type=\"submit\" name=\"action\" value=\"Save\"></td>" ) ; out . println ( "  </tr>" ) ; out . println ( "</table>" ) ; out . println ( "</form>" ) ; printHtmlFoot ( appReq ) ; } finally { appReq . close ( ) ; } }
Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 methods.
Processes requests for both HTTP <code > GET< / code > and <code > POST< / code > methods .
// TODO check report