示例#1
0
  public static void informInterestedParties(
      HttpServletRequest request, String number, String message, String context) {
    // String context="context0";
    // context=ServletUtilities.getContext(request);
    Shepherd myShepherd = new Shepherd(context);
    myShepherd.beginDBTransaction();

    if (myShepherd.isEncounter(number)) {

      Encounter enc = myShepherd.getEncounter(number);
      if (enc.getInterestedResearchers() != null) {
        Vector notifyMe = enc.getInterestedResearchers();
        int size = notifyMe.size();
        String[] interested = new String[size];
        for (int i = 0; i < size; i++) {
          interested[i] = (String) notifyMe.get(i);
        }
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
        if (size > 0) {
          Vector e_images = new Vector();
          String mailMe = interested[0];
          String email =
              getText("dataUpdate.txt")
                  .replaceAll(
                      "INSERTTEXT",
                      ("Encounter "
                          + number
                          + ": "
                          + message
                          + "\n\nLink to encounter: http://"
                          + CommonConfiguration.getURLLocation(request)
                          + "/encounters/encounter.jsp?number="
                          + number));
          email +=
              ("\n\nWant to stop tracking this set of encounter data? Use this link.\nhttp://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/dontTrack?number="
                  + number
                  + "&email=");
          ThreadPoolExecutor es = MailThreadExecutorService.getExecutorService();
          es.execute(
              new NotificationMailer(
                  CommonConfiguration.getMailHost(context),
                  CommonConfiguration.getAutoEmailAddress(context),
                  mailMe,
                  ("Encounter data update: " + number),
                  (email + mailMe),
                  e_images,
                  context));

          // NotificationMailer mailer=new NotificationMailer(CommonConfiguration.getMailHost(),
          // CommonConfiguration.getAutoEmailAddress(), mailMe, ("Encounter data update: "+number),
          // (email+mailMe), e_images);
          for (int j = 1; j < size; j++) {
            mailMe = interested[j];
            es.execute(
                new NotificationMailer(
                    CommonConfiguration.getMailHost(context),
                    CommonConfiguration.getAutoEmailAddress(context),
                    mailMe,
                    ("Encounter data update: " + number),
                    (email + mailMe),
                    e_images,
                    context));
          }
        }
      } else {
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
      }

    } else {
      myShepherd.rollbackDBTransaction();
      myShepherd.closeDBTransaction();
    }
  }
示例#2
0
  // inform researchers that have logged an interest with the encounter or marked individual
  public static void informInterestedIndividualParties(
      HttpServletRequest request, String shark, String message, String context) {
    Shepherd myShepherd = new Shepherd(context);
    myShepherd.beginDBTransaction();

    if (myShepherd.isMarkedIndividual(shark)) {
      MarkedIndividual sharkie = myShepherd.getMarkedIndividual(shark);
      if (sharkie.getInterestedResearchers() != null) {
        Vector notifyMe = sharkie.getInterestedResearchers();
        int size = notifyMe.size();
        String[] interested = new String[size];
        for (int i = 0; i < size; i++) {
          interested[i] = (String) notifyMe.get(i);
        }
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
        if (size > 0) {

          ThreadPoolExecutor es = MailThreadExecutorService.getExecutorService();

          Vector e_images = new Vector();
          String mailMe = interested[0];
          String email =
              getText("dataUpdate.txt")
                  .replaceAll(
                      "INSERTTEXT",
                      ("Tag "
                          + shark
                          + ": "
                          + message
                          + "\n\nLink to individual: http://"
                          + CommonConfiguration.getURLLocation(request)
                          + "/individuals.jsp?number="
                          + shark));
          email +=
              ("\n\nWant to stop tracking this set of this individual's data? Use this link.\n\nhttp://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/dontTrack?shark="
                  + shark
                  + "&email=");

          es.execute(
              new NotificationMailer(
                  CommonConfiguration.getMailHost(context),
                  CommonConfiguration.getAutoEmailAddress(context),
                  mailMe,
                  ("Marked individual data update: " + shark),
                  (email + mailMe),
                  e_images,
                  context));
          for (int j = 1; j < size; j++) {
            mailMe = interested[j];
            es.execute(
                new NotificationMailer(
                    CommonConfiguration.getMailHost(context),
                    CommonConfiguration.getAutoEmailAddress(context),
                    mailMe,
                    ("Individual data update: " + shark),
                    (email + mailMe),
                    e_images,
                    context));
          }
        }
      } else {
        myShepherd.rollbackDBTransaction();
        myShepherd.closeDBTransaction();
      }
    } else {
      myShepherd.rollbackDBTransaction();
      myShepherd.closeDBTransaction();
    }
  }
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    String context = "context0";
    context = ServletUtilities.getContext(request);
    String langCode = ServletUtilities.getLanguageCode(request);
    Shepherd myShepherd = new Shepherd(context);
    // set up for response
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    boolean locked = false;
    boolean isOwner = true;

    if (request.getParameter("number") != null) {
      myShepherd.beginDBTransaction();
      Encounter enc2reject = myShepherd.getEncounter(request.getParameter("number"));
      setDateLastModified(enc2reject);
      boolean isOK = enc2reject.isAssignedToMarkedIndividual().equals("Unassigned");
      myShepherd.rollbackDBTransaction();
      if (isOK) {

        myShepherd.beginDBTransaction();
        try {

          // enc2reject.reject();
          enc2reject.setState("unidentifiable");
          enc2reject.addComments(
              "<p><em>"
                  + request.getRemoteUser()
                  + " on "
                  + (new java.util.Date()).toString()
                  + "</em><br>Set this encounter as unidentifiable in the database.</p>");
          // enc2reject.approved = false;
          enc2reject.setState("unidentifiable");
        } catch (Exception le) {
          locked = true;
          le.printStackTrace();
          myShepherd.rollbackDBTransaction();
        }

        if (!locked) {
          String submitterEmail = enc2reject.getSubmitterEmail();
          myShepherd.commitDBTransaction();
          out.println(ServletUtilities.getHeader(request));
          out.println(
              "<strong>Success:</strong> I have set encounter "
                  + request.getParameter("number")
                  + " as unidentifiable in the database.");
          out.println(
              "<p><a href=\"http://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/encounters/encounter.jsp?number="
                  + request.getParameter("number")
                  + "\">View unidentifiable encounter #"
                  + request.getParameter("number")
                  + "</a></p>\n");
          ArrayList<String> allStates =
              CommonConfiguration.getSequentialPropertyValues("encounterState", context);
          int allStatesSize = allStates.size();
          if (allStatesSize > 0) {
            for (int i = 0; i < allStatesSize; i++) {
              String stateName = allStates.get(i);
              out.println(
                  "<p><a href=\"encounters/searchResults.jsp?state="
                      + stateName
                      + "\">View all "
                      + stateName
                      + " encounters</a></font></p>");
            }
          }
          out.println(ServletUtilities.getFooter(context));
          String message =
              "Encounter "
                  + request.getParameter("number")
                  + " was set as unidentifiable in the database.";
          ServletUtilities.informInterestedParties(
              request, request.getParameter("number"), message, context);

          // Email submitter about change
          Map<String, String> tagMap = NotificationMailer.createBasicTagMap(request, enc2reject);
          tagMap.put("@TEXT_CONTENT@", message);
          ThreadPoolExecutor es = MailThreadExecutorService.getExecutorService();
          NotificationMailer mailer =
              new NotificationMailer(context, null, submitterEmail, "encounterDataUpdate", tagMap);
          es.execute(mailer);
          es.shutdown();

        } else {
          out.println(ServletUtilities.getHeader(request));
          out.println(
              "<strong>Failure:</strong> I have NOT modified encounter "
                  + request.getParameter("number")
                  + " in the database because another user is currently modifying its entry. Please try this operation again in a few seconds.");
          out.println(
              "<p><a href=\"http://"
                  + CommonConfiguration.getURLLocation(request)
                  + "/encounters/encounter.jsp?number="
                  + request.getParameter("number")
                  + "\">View unidentifiable encounter #"
                  + request.getParameter("number")
                  + "</a></p>\n");
          ArrayList<String> allStates =
              CommonConfiguration.getSequentialPropertyValues("encounterState", context);
          int allStatesSize = allStates.size();
          if (allStatesSize > 0) {
            for (int i = 0; i < allStatesSize; i++) {
              String stateName = allStates.get(i);
              out.println(
                  "<p><a href=\"encounters/searchResults.jsp?state="
                      + stateName
                      + "\">View all "
                      + stateName
                      + " encounters</a></font></p>");
            }
          }
          out.println(ServletUtilities.getFooter(context));
        }

      } else {
        out.println(ServletUtilities.getHeader(request));
        out.println(
            "Encounter# "
                + request.getParameter("number")
                + " is assigned to an individual and cannot be set as unidentifiable until it has been removed from that individual.");
        out.println(ServletUtilities.getFooter(context));
      }
    } else {
      out.println(ServletUtilities.getHeader(request));
      out.println(
          "<strong>Error:</strong> I do not know which encounter you are trying to remove.");
      out.println(ServletUtilities.getFooter(context));
    }

    out.close();
    myShepherd.closeDBTransaction();
  }