Posted By

tvhung83 on 03/26/14


Tagged


Versions (?)

Track email response


 / Published in: Java
 

Track email response logic

  1. String cacheId = req.getParameter("cache_id");
  2. String nameInEmail = req.getParameter("name_in_email");
  3.  
  4. // find EmailMessage by cache_id
  5. EmailMessage emailMessage = emailMessageService.findBy(cacheId);
  6.  
  7. // find BroadcastReceiverChannelDestination by channel, broadcast_id, destination, receiver_id
  8. BroadcastReceiverChannelDestination brcd = brcdService.findBy("EMAIL", emailMessage.getBroadcast().getId(), emailMessage.getReceiverEmail(), emailMessage.getReceiver().getId());
  9.  
  10. // get current BroadcastResponseOption of user
  11. BroadcastResponseOption curRespOpt = brcd.getResponse();
  12.  
  13. // find BroadcastResponseOption by broadcast_id and name_in_email (received BroadcastResponseOption from user)
  14. BroadcastResponseOption newRespOpt = broadcastResponseOptionService.findBy(emailMessage.getBroadcast().getId(), nameInEmail);
  15.  
  16. // detect ResponseMessageTemplateType
  17. ResponseMessageTemplateType respType;
  18. if (broadcast.getExpiryDateTime().before(new Date())) {
  19. respType = ResponseMessageTemplateType.ResponseReceived; // received after deadline
  20. } else if (null == curRespOpt) {
  21. respType = ResponseMessageTemplateType.NewResponse; // new response
  22. } else if (!newRespOpt.getNameInEmail().equalsIgnoreCase(curRespOpt.getNameInEmail())) {
  23. respType = ResponseMessageTemplateType.ResponseChanged; // change response
  24. } else if (newRespOpt.getNameInEmail().equalsIgnoreCase(curRespOpt.getNameInEmail())) {
  25. respType = ResponseMessageTemplateType.ResponseDuplicated; // duplicated response
  26. }
  27.  
  28. // one BroadcastResponseOption has a list of ResponseMessageTemplate (NewResponse, ResponseChanged,...)
  29. List<ResponseMessageTemplate> lstRespMsgTempl = bRespOpt.getResponseOption().getResponseMessageTemplates();
  30. for (ResponseMessageTemplate respMsgTempl : lstRespMsgTempl) {
  31. if (respType == respMsgTempl.getType()) {
  32. // get email to send
  33. String emailSubject = respMsgTempl.getMessageTemplate().getEmailSubject();
  34. String emailContent = respMsgTempl.getMessageTemplate().getEmailContent();
  35.  
  36. // send email
  37. boolean sendingResult = broadcastWorker.sendEmail(emailMessage.getReceiverEmail(), emailSubject, emailContent);
  38.  
  39. // action after responding
  40. ActionAfterResponding action = respMsgTempl.getActionAfterResponding();
  41. if (null != action) {
  42. // Custom page
  43. if (ActionAfterRespondingType.Page == action.getType()) {
  44. String displayContent = action.getContent();
  45. } else if (ActionAfterRespondingType.Link == action.getType()) { // redirect to link
  46. String redirectLink = action.getContent();
  47. }
  48. }
  49. }
  50. }

Report this snippet  

You need to login to post a comment.