Package evolaris.platform.smssvc.web.form

Examples of evolaris.platform.smssvc.web.form.EmailSendForm


   *      javax.servlet.http.HttpServletRequest,
   *      javax.servlet.http.HttpServletResponse)
   */
  @SuppressWarnings("unchecked")
  public ActionForward enter(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp)  {
    EmailSendForm emailSendForm = (EmailSendForm) form;
    emailSendForm.setSendConfirmationPending(false);

    Group group = getCurrentGroup(req);
     
   
    // template selector: first set content from the template, if selected; content will be changed later if not allowed (except destination group, which  has to be checked explicitly)
    prepareTemplate(req, emailSendForm, group, new EmailCommandEntry());

    // set defaults, if no user or template entries

    if (emailSendForm.getDestinationSelection() == null){
      emailSendForm.setDestinationSelection(-1)// none selected
    }
    if (emailSendForm.getFromEmail() == null || emailSendForm.getFromEmail().trim().length() == 0){
      if (webUser.getEmail() != null){
        EmailAddress webUserEmailAddress = new EmailAddress(webUser);
        emailSendForm.setFromEmail(webUserEmailAddress.getEmail());
        emailSendForm.setFromPersonalName(webUserEmailAddress.getPersonalName());
      }
      // no from setting if web user does not have e-mail configured => non-administrators must configure in personal settings
    }
    if (emailSendForm.getFromPersonalName() == null || emailSendForm.getFromPersonalName().trim().length() == 0){
      emailSendForm.setFromPersonalName((webUser.getFirstName() == null ? "" : webUser.getFirstName()) + " " + (webUser.getLastName() == null ? "" : webUser.getLastName()).trim());
    }

    // user sets
    UserSet userSet = prepareUserSets(req, emailSendForm, group);

View Full Code Here


    return handleSending(mapping, form, req, resp, calendar.getTime());   
  }
 
  /* handles all form evaluation and preparing of sending for direct and scheduled sending */
  private ActionForward handleSending(ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp, Date sendAt)  {
    EmailSendForm emailSendForm = (EmailSendForm)form;
    if (isTokenValid(req)) {
      resetToken(req);
      saveToken(req);
    } else {
      String invalidToken = getResources(req).getMessage(locale,"smssvc.invalidTokenOnSend");
      req.setAttribute("generalError", invalidToken);
      // reset also confirmation pending because enter will not be called
      emailSendForm.setSendConfirmationPending(false);
      return mapping.findForward("invalidToken");
    }

    EmailAddress fromAddress = new EmailAddress(webUser,emailSendForm.getFromEmail(),emailSendForm.getFromPersonalName() == null ? null : emailSendForm.getFromPersonalName());
    Long userSetId = emailSendForm.getUserSetId();
    Long userId = emailSendForm.getUserId();
    Set<User> users=null;

    Integer destinationSelection = emailSendForm.getDestinationSelection();
    switch (destinationSelection==null?0:destinationSelection){
    case 1// user set
      UserSetManager userSetManager = new UserSetManager(locale,session);
      if (userSetId.longValue() == -1){
        String noUserSetSelectedString = getResources(req).getMessage(locale,"smssvc.MessageNotSentBecauseNoUserSetSelected");
        req.setAttribute("generalError",noUserSetSelectedString);
        return mapping.findForward("notSent");
      }
      UserSet userSet =  userSetManager.getUserSet(userSetId);
      if (userSet == null){
        throw new ConfigurationException("illegal user set id: " + userSetId);
      }
      users = userSet.getUsers();
      break;
    case 2: // user
      if (userId.longValue() == -1){
        String noUserSelectedString = getResources(req).getMessage(locale,"smssvc.MessageNotSentBecauseNoUserSelected");
        req.setAttribute("generalError",noUserSelectedString);
        return mapping.findForward("notSent");
      }
      UserManager userManager = new UserManager(locale,session);
      User user = userManager.getUserDetails(userId);
      if (user == null){
        throw new ConfigurationException("illegal user id: " + user);
      }
      Set<User> oneManSet = new HashSet<User>();
      oneManSet.add(user);
      users = oneManSet;
      break;
    case 3// e-mail address
      EmailAddress toAddress = new EmailAddress(emailSendForm.getToEmail(), emailSendForm.getToPersonalName());
      SortedSet<EmailAddress> receivers = new TreeSet<EmailAddress>();
      receivers.add(toAddress);
      MessagingManager msgMgr = new MessagingManager(locale, session);
      msgMgr.sendEmail(fromAddress, receivers, getCurrentGroup(req), emailSendForm.getSubject(), emailSendForm.getMessage(), emailSendForm.getMimeType() == null ? MailSender.MIME_TYPE_PLAIN_TEXT : emailSendForm.getMimeType().intValue(), sendAt);
      Date date = new Date(System.currentTimeMillis());
      String formattedDate = DateFormat.getTimeInstance(DateFormat.MEDIUM,locale).format(date);
      String generalInformation = getResources(req).getMessage(locale, "smssvc.asyncSendStarted", new Object[] {new Integer(receivers.size()), formattedDate});
      req.setAttribute("generalInformation", generalInformation);
      return mapping.findForward("sent");
    default:
      String noDestinationSelectedString = getResources(req).getMessage(locale,"smssvc.noDestinationSelected");
      req.setAttribute("generalError",noDestinationSelectedString);
      return mapping.findForward("notSent");
    }
    if (users != null && users.size() >= CONFIRMATION_MINIMUM && !emailSendForm.isSendConfirmationPending()){
      emailSendForm.setSendConfirmationPending(true);
      String msg = getResources(req).getMessage(locale, "smssvc.ConfirmSendToManyReceivers.", users.size());
      req.setAttribute("generalError", msg);
      return mapping.findForward("confirm");
    } else {
      emailSendForm.setSendConfirmationPending(false);
      return sendToUsersWithEmail(fromAddress, users,mapping,form,req,resp, sendAt);
    }
  }
View Full Code Here

   * @param req
   * @param resp
   * @return
   */
  private ActionForward sendToUsersWithEmail(EmailAddress fromAddress, Set<User> users, ActionMapping mapping, ActionForm form,HttpServletRequest req, HttpServletResponse resp, Date sendAt) {
    EmailSendForm msgForm = (EmailSendForm) form;
    for (User user : users) {
      if (!req.isUserInRole(UserManagerBase.ADMINISTRATOR) && user.getGroup() != webUser.getGroup()){
        throw new BugException("user selected as SMS destination, who must not be accessed: " + user.getId());
      }
    }
    SortedSet<EmailAddress> receivers = EmailAddress.availableAddresses(users);
    if (receivers.size() == 0) {
      String noUsersWithEmailString = getResources(req).getMessage(locale,"smssvc.noUsersWithEmail");
      req.setAttribute("generalError",noUsersWithEmailString);
      return mapping.findForward("notSent");
    }
    MessagingManager msgMgr = new MessagingManager(locale, session);
    msgMgr.sendEmail(fromAddress, receivers, getCurrentGroup(req), msgForm.getSubject(), msgForm.getMessage(), msgForm.getMimeType() == null ? MailSender.MIME_TYPE_PLAIN_TEXT : msgForm.getMimeType().intValue(), sendAt);
    Date date = new Date(System.currentTimeMillis());
    String formattedDate = DateFormat.getTimeInstance(DateFormat.MEDIUM,locale).format(date);
    String generalInformation = getResources(req).getMessage(locale, "smssvc.asyncSendStarted", new Object[] {new Integer(receivers.size()), formattedDate});
    req.setAttribute("generalInformation", generalInformation);
    return mapping.findForward("sent");
View Full Code Here

TOP

Related Classes of evolaris.platform.smssvc.web.form.EmailSendForm

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.