Author: echatellier Date: 2010-03-08 16:29:40 +0100 (Mon, 08 Mar 2010) New Revision: 2903 Log: Send mail in a thread (to not block client) Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java Modified: branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java =================================================================== --- branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-08 15:19:16 UTC (rev 2902) +++ branches/pollen-1.2.3-1.2.x/pollen-ui/src/main/java/org/chorem/pollen/ui/pages/poll/PollCreation.java 2010-03-08 15:29:40 UTC (rev 2903) @@ -815,9 +815,26 @@ // Mise à jour du sondage poll = servicePoll.findPollById(poll.getId()); + addFeedEntry(); + + // on les passe en parametres car au + // moment de l'execution du thread, il y a des NPE + // à l'utilisation des valeurs + final String localSiteURL = siteURL; + final ServicePollAccount localServicePollAccount = servicePollAccount; + final PollDTO localPoll = poll; + final Configuration localConf = conf; + final Messages localMessages = messages; + // Mise à jour du flux Atom et envoi d'un mail de confirmation - addFeedEntry(); - sendMailNotification(); + // FIXME replace this ugly thread code !!! + new Thread() { + @Override + public void run() { + sendMailNotification(localSiteURL, localServicePollAccount, + localPoll, localConf, localMessages); + } + }.start(); } } @@ -825,7 +842,7 @@ private void addFeedEntry() { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll .getCreatorId()); - String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); + String voteURL = siteURL + "poll/votefor/" + poll.getPollId(); File feedFile = feedContext.getFile(poll.getPollId()); FeedUtil.createFeed(feedFile, "atom_1.0", messages.format( @@ -837,11 +854,12 @@ } /** Envoi du mail de notification */ - private void sendMailNotification() { + private void sendMailNotification(String siteURL, ServicePollAccount servicePollAccount, + PollDTO poll, Configuration conf, Messages messages) { PollAccountDTO creator = servicePollAccount.findPollAccountById(poll .getCreatorId()); - String voteURL = siteURL + "poll/VoteFor/" + poll.getPollId(); - String modifURL = siteURL + "poll/Modification/" + poll.getPollId() + String voteURL = siteURL + "poll/votefor/" + poll.getPollId(); + String modifURL = siteURL + "poll/modification/" + poll.getPollId() + ":" + creator.getAccountId(); Map<String, String> data = new HashMap<String, String>(); data.put("host", conf.getProperty("email_host")); @@ -856,6 +874,8 @@ data.put("msg", messages.format("creatorEmail_msg", poll.getTitle(), voteURL, modifURL)); + // FIXME call directly MailUtil.sendMail() + // skip fill map, get from map... PreventRuleManager.emailAction(data); } @@ -863,17 +883,17 @@ for (VotingListDTO list : poll.getVotingListDTOs()) { for (PollAccountDTO account : list.getPollAccountDTOs()) { if (account.getEmail() != null) { - String accountVoteURL = voteURL + ":" - + account.getAccountId(); + String accountVoteURL = voteURL + ":" + account.getAccountId(); data.put("to", account.getEmail()); data.put("title", messages.format("votingEmail_subject", poll.getTitle())); - data - .put("msg", messages.format("votingEmail_msg", poll + data.put("msg", messages.format("votingEmail_msg", poll .getTitle(), account.getVotingId(), accountVoteURL)); + // FIXME call directly MailUtil.sendMail() + // skip fill map, get from map... PreventRuleManager.emailAction(data); } }