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."); }
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"); }
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; } }
public boolean deletePoll(Integer pollId) throws SQLException { return dao.deletePoll(pollId); }
public Poll get(String token) throws SQLException { Object[] tokenIds = dao.getTokenIds(token); return get((Integer) tokenIds[1]); }
public List<Poll> list() throws SQLException { return dao.list(); }
public Poll update(Integer pollId, String script) throws SQLException, InvalidScriptException { return dao.update(pollId, new Poll(script).getScript()); }
public Poll create(String script) throws SQLException, InvalidScriptException { return dao.save(new Poll(script).getScript()); }
public Poll get(Integer pollId) throws SQLException { return dao.get(pollId); }
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; }