Exemple #1
0
  public String saveResponse(String token, Map<String, List<String>> responses)
      throws SQLException, FeedbackException {
    if (dao.saveResponse(token, responses)) {
      return "Answers saved! Thanks!";
    }

    throw new FeedbackException("A problem ocurred saving answers. Please try again.");
  }
Exemple #2
0
  public String sendPoll(Integer pollId)
      throws SQLException, IOException, NoSuchAlgorithmException {
    Poll poll = get(pollId);
    String[] contacts = poll.getContacts();

    if (sendMailTo(contacts, poll)) {
      dao.sendPoll(pollId);
      return "The poll was send to all the contacts!";
    }
    throw new RuntimeException("A problem ocurred when sending the mail to the contacts");
  }
Exemple #3
0
  private boolean sendMailTo(String[] contacts, Poll poll)
      throws IOException, NoSuchAlgorithmException, SQLException {
    try {
      String token;
      SmtpSender client = new SmtpSender(Parameters.getSMTPServer());

      Map<String, String> replacement = new HashMap<String, String>();
      replacement.put("emailTitle", poll.getEmailTitle());
      replacement.put("sign", poll.getEmailSign());
      replacement.put("content", poll.getEmailContent());

      for (String contact : contacts) {
        do {
          token =
              Utils.getUrlSafeHash(
                  contact
                      + "-"
                      + poll.getId()
                      + "-"
                      + System.currentTimeMillis()
                      + "-"
                      + Utils.getRandomString(10));
        } while (!dao.createToken(contact, poll.getId(), token));
        replacement.put("url", Parameters.getFeedbackBaseUrl() + "/#?t=" + token);
        System.out.println(
            "[*] Mail to [contact: "
                + contact
                + ", pollId: "
                + poll.getId()
                + ", token: "
                + token
                + "]");
        client.sendEmail(createEmail(contact, poll, replacement));
      }
      return true;
    } catch (MessagingException e) {
      e.printStackTrace();
      return false;
    }
  }
Exemple #4
0
 public boolean deletePoll(Integer pollId) throws SQLException {
   return dao.deletePoll(pollId);
 }
Exemple #5
0
 public Poll get(String token) throws SQLException {
   Object[] tokenIds = dao.getTokenIds(token);
   return get((Integer) tokenIds[1]);
 }
Exemple #6
0
 public List<Poll> list() throws SQLException {
   return dao.list();
 }
Exemple #7
0
 public Poll update(Integer pollId, String script) throws SQLException, InvalidScriptException {
   return dao.update(pollId, new Poll(script).getScript());
 }
Exemple #8
0
 public Poll create(String script) throws SQLException, InvalidScriptException {
   return dao.save(new Poll(script).getScript());
 }
Exemple #9
0
 public Poll get(Integer pollId) throws SQLException {
   return dao.get(pollId);
 }
Exemple #10
0
 public Poll getAnswers(Integer pollId) throws SQLException {
   Poll poll = get(pollId);
   List<Answer> answers = dao.getAnswers(pollId);
   poll.setAnswers(answers.toArray(new Answer[] {}));
   return poll;
 }