Esempio n. 1
0
  private void addProject(
      HttpServletRequest request, HttpServletResponse response, boolean updateFlag)
      throws ServletException, IOException {
    // First order of business is to capture the form parameters into the project bean
    setProjectBean(request);
    // execute the insert
    String id = request.getParameter("id");
    try {
      if (updateFlag) parameterDAO.deleteProject(id);
      project = pb.insert();
    } catch (Exception e) {
      msg.append("A B O R T.  The following database error has occured:<br />");
      msg.append(
          "<strong><span style=\"background-color: #FFFF00\">" + e + "</span></strong><br />");
    } finally {
      if (project > 0) {
        // success
        msg.append(
            "Project <strong><span style=\"background-color: #FFFF00\">" + pb.getProjectname());
        if (updateFlag) {
          msg.append("</span></strong> was U P D A T E D <br />");
        } else {
          msg.append("</span></strong> was I N S E R T E D<br />");
        }

      } else {
        msg.append(
            "F A I L E D to Insert/Update Project "
                + pb.getProjectname()
                + " into database!!!!!!!!!!!<br />");
      }
    }
  }
Esempio n. 2
0
  private String getProjectsListHTML(String column, String order) {
    // System.out.println("AddProjectServlet.getPrjectsHTML filter = " + filter.toString());
    String html = parameterDAO.getProjectsListHTML(column, order, baseurl, filter);

    System.out.println("Filter FINISHED as = " + filter.toFilterString());
    // System.out.println("Filter Training FINISHED as, ParameterDAO.(Training) = " +
    // ParameterDAO.parse(filter.getTraining()));
    // System.out.println("Filter Capability Area(s) FINISHED as = " + filter.getCapabilityAreas());

    // filter=new ProjectBean();
    return html;
  }
Esempio n. 3
0
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    System.out.println("AddProjectServlet.doPost Entered...");

    init(response);
    PrintWriter out = response.getWriter();
    dataSource = (DataSource) request.getSession().getServletContext().getAttribute("DBCPool");
    baseurl = config.getServletContext().getInitParameter("baseurl"); // filesystem web-root
    parameterDAO.setDataSource(dataSource);
    pb.setParameterDAO(parameterDAO);
    filter.setParameterDAO(parameterDAO);

    System.out.println("AddProjectServlet.doPost done inits pb.set, filter.set...");

    if (ParameterDAO.parse(request.getParameter("clearmsgs"))) {
      msg = new StringBuffer();
    }

    String[] deleted = request.getParameterValues("delete");
    String addnew = request.getParameter("addnew");
    String updated = request.getParameter("updated");
    String undelete = request.getParameter("undelete");
    String searchbyx = request.getParameter("searchbyx");

    filter.setSearchString(StringUtils.trimToEmpty(request.getParameter("search")));
    String sortby = StringUtils.trimToEmpty(request.getParameter("sortby"));

    String order = "DESC";
    if (!ParameterDAO.parse(request.getParameter("order"))) order = "ASC";

    // if coming from addContacts, success or failure...
    if (ParameterDAO.parse(request.getAttribute("addcontacts"))
        || ParameterDAO.parse(request.getAttribute("addagencies"))
        || ParameterDAO.parse(request.getAttribute("uploadedfile"))) {
      msg.append(StringUtils.trimToEmpty((String) request.getAttribute("msg")));
    } else if (StringUtils.isNotBlank(filter.getSearchString())) {
      // triggers the simple search exclusive of any other action (safe from delete, by preceding in
      // if-then )
      // do absolutely nothing the search field will be populated just fine as expected.  Later, may
      // be add X number of projects
    } else if (deleted == null) {
      // System.out.println("AddProjectServlet.doPost Entered else if deleted == null");

      // coming from index.jsp
      if (ParameterDAO.parse(updated)) {
        addProject(request, response, true);
      } else if (ParameterDAO.parse(undelete)) {
        parameterDAO.unDeleteAllProjects();
      } else if (ParameterDAO.parse(addnew)) {
        addProject(request, response, false);
      } else if (ParameterDAO.parse(searchbyx)) {
        // we are just setting filter
        setProjectBean(request);
        filter = pb;
        System.out.println("Filter STARTS LIFE as = " + filter.toFilterString());
        // System.out.println("Filter Training INIT parsed as = " +
        // ParameterDAO.parse(filter.getTraining()));
        // System.out.println("Filter Capability Area(s) INIT as = " + filter.getCapabilityAreas());

        msg.append("Advanced Search Parameters = ");
        msg.append(
            "<div style=\"font-family: 'trebuchet ms', sans-serif;  font-size: 9px; font-style: italic; text-transform: lowercase; display: inline; \">");
        msg.append(filter.toFilterString());
        msg.append("</div><br />");
      }
    } else if (deleted.length == 0) {
      // came from projects list but nothing to do...later when table cells are editable, we may @TO
      // DO capture all edits/updates here
    } else {
      parameterDAO.deleteProject(deleted);
      int count = 0;
      for (int i = 0; i < deleted.length; i++) {
        count++;

        if (count == 1) {
          msg.append("Project(s) <strong><span style=\"background-color: #FFFF00\">");
        } else {
          msg.append(",&nbsp;<strong><span style=\"background-color: #FFFF00\">");
        }
        msg.append(
            StringEscapeUtils.escapeHtml(
                parameterDAO.getJustOneProject(deleted[i]).getProjectname()));
        msg.append("</span></strong>");
      }
      if (count > 0) msg.append(" D E L E T E D<BR />");
    }

    /////////////////////////////////////////////
    //  Draw the projects list table
    //
    out.println(getHeader());
    out.println(getMessageTable(msg));
    // System.out.println("AddProjectServlet.doPost drawing projects table " + filter.toString());

    if (StringUtils.isBlank(sortby)) {
      out.println(getProjectsListHTML());
    } else if (StringUtils.equalsIgnoreCase(sortby, "code")) {
      out.println(getProjectsListHTML("code", order));
    } else if (StringUtils.equalsIgnoreCase(sortby, "name")) {
      out.println(getProjectsListHTML("nametitle", order));
    } else if (StringUtils.equalsIgnoreCase(sortby, "description")) {
      out.println(getProjectsListHTML("description", order));
    } else if (StringUtils.equalsIgnoreCase(sortby, "status")) {
      out.println(getProjectsListHTML("status", order));
    } else {
      out.println(getProjectsListHTML());
    }

    out.println(getFooter());
    filter = new ProjectBean();
    // System.out.println("AddProjectServlet.doPost DONE");

  }
Esempio n. 4
0
  private void setProjectBean(HttpServletRequest request) {
    pb.setProjectname(request.getParameter("projectname"));
    pb.setTraining(request.getParameter("training"));
    pb.setEducation(request.getParameter("education"));
    pb.setOutreach(request.getParameter("outreach"));
    pb.setObserving(request.getParameter("observing"));
    pb.setDataservices(request.getParameter("dataservices"));
    pb.setVariability(request.getParameter("variability"));
    pb.setOperational(request.getParameter("operational"));
    pb.setResearch(request.getParameter("research"));
    pb.setVhistorical(request.getParameter("vhistorical"));
    pb.setVprojections(request.getParameter("vprojections"));
    pb.setAsurface(request.getParameter("asurface"));
    pb.setUpperair(request.getParameter("upperair"));
    pb.setComposition(request.getParameter("composition"));
    pb.setOsurface(request.getParameter("osurface"));
    pb.setSubsurface(request.getParameter("subsurface"));
    pb.setTerrestrial(request.getParameter("terrestrial"));
    pb.setSeasonal(request.getParameter("seasonal"));
    pb.setAnnual(request.getParameter("annual"));
    pb.setDecadal(request.getParameter("decadal"));
    pb.setEffect(request.getParameter("effect"));
    pb.setImpacts(request.getParameter("impacts"));
    pb.setEhistorical(request.getParameter("ehistorical"));
    pb.setEprojections(request.getParameter("eprojections"));
    pb.setAdaptation(request.getParameter("adaptation"));
    pb.setPhs(request.getParameter("phs"));
    pb.setFwr(request.getParameter("fwr"));
    pb.setEne(request.getParameter("ene"));
    pb.setTcc(request.getParameter("tcc"));
    pb.setCpd(request.getParameter("cpd"));
    pb.setScr(request.getParameter("scr"));
    pb.setAfi(request.getParameter("afi"));
    pb.setRat(request.getParameter("rat"));
    pb.setEco(request.getParameter("eco"));
    pb.setOth(request.getParameter("oth"));
    pb.setGuidance(request.getParameter("guidance"));
    pb.setGvariability(request.getParameter("gvariability"));
    pb.setGeffects(request.getParameter("geffects"));
    pb.setApps(request.getParameter("apps"));
    pb.setAvariability(request.getParameter("avariability"));
    pb.setAeffects(request.getParameter("aeffects"));
    pb.setPolicies(request.getParameter("policies"));
    pb.setAssessment(request.getParameter("assessment"));
    pb.setFresh(request.getParameter("fresh"));
    pb.setCoastal(request.getParameter("coastal"));
    pb.setMarine(request.getParameter("marine"));
    pb.setCentral(request.getParameter("central"));
    pb.setHawaii(request.getParameter("hawaii"));
    pb.setBig(request.getParameter("big"));
    pb.setMaui(request.getParameter("maui"));
    pb.setOahu(request.getParameter("oahu"));
    pb.setKauai(request.getParameter("kauai"));
    pb.setHother(request.getParameter("hother"));
    pb.setWestern(request.getParameter("western"));
    pb.setGuam(request.getParameter("guam"));
    pb.setCnmi(request.getParameter("cnmi"));
    pb.setFsm(request.getParameter("fsm"));
    pb.setRmi(request.getParameter("rmi"));
    pb.setPalau(request.getParameter("palau"));
    pb.setWother(request.getParameter("wother"));
    pb.setSouth(request.getParameter("south"));
    pb.setAsam(request.getParameter("asam"));
    pb.setSamoa(request.getParameter("samoa"));
    pb.setTonga(request.getParameter("tonga"));
    pb.setFiji(request.getParameter("fiji"));
    pb.setOz(request.getParameter("oz"));
    pb.setNz(request.getParameter("nz"));
    pb.setFp(request.getParameter("fp"));
    pb.setSother(request.getParameter("sother"));
    pb.setOtherregions(request.getParameter("otherregions"));
    pb.setStatus(request.getParameter("status"));
    pb.setLeadagencies(request.getParameterValues("leadagencies"));
    pb.setPartneragencies(request.getParameterValues("partneragencies"));
    pb.setProjectdescription(request.getParameter("projectdescription"));
    pb.setWorksheetfilename(request.getParameter("worksheetfilename"));
    pb.setTag(request.getParameter("tag"));
    pb.setCode(request.getParameter("code"));

    // separately handle contacts, email until figure out a better more efficient
    // way of passing names, emails as arrays to be picked up by request.getParameterValues...

    String[] contacts = new String[3];
    String[] emails = new String[3];

    contacts[0] = StringUtils.trimToEmpty(request.getParameter("contact1"));
    // System.out.println("AddProjectServlet.setProjectBean contacts[0] set to " + contacts[0] );
    contacts[1] = StringUtils.trimToEmpty(request.getParameter("contact2"));
    // System.out.println("AddProjectServlet.setProjectBean contacts[1] set to " + contacts[1] );
    contacts[2] = StringUtils.trimToEmpty(request.getParameter("contact3"));
    // System.out.println("AddProjectServlet.setProjectBean contacts[2] set to " + contacts[2] );

    emails[0] = StringUtils.trimToEmpty(request.getParameter("email1"));
    // System.out.println("AddProjectServlet.setProjectBean emails[0] set to " + emails[0] );
    emails[1] = StringUtils.trimToEmpty(request.getParameter("email2"));
    // System.out.println("AddProjectServlet.setProjectBean emails[1] set to " + emails[1] );
    emails[2] = StringUtils.trimToEmpty(request.getParameter("email3"));
    // System.out.println("AddProjectServlet.setProjectBean emails[2] set to " + emails[2] );

    pb.setContactName(contacts);
    pb.setEmailsAddress(emails);
    pb.setContactList();
    // System.out.println("Project " + pb.getProjectnumber() + ", " + pb.getProjectname() + "
    // contacts and emails have been set from request parameters " );
    // System.out.println("Contacts = " + pb.getContacts(""));

  }