コード例 #1
0
  @RequestMapping(value = "/admin/mailer", method = RequestMethod.POST)
  public String handlePost(Model model, HttpSession session, HttpServletRequest request) {
    model.addAttribute("context", "mailer");
    String role = request.getParameter("role");
    String template = request.getParameter("template");
    String iso3 = request.getParameter("country");
    String customText = request.getParameter("customtext");
    String address = request.getParameter("address");
    String language = request.getParameter("userLang");
    List<User> receivers = null;
    if (role == null) {
      if (address == null) {
        composeErrorMessage(model, "reciver not specified");
        buildModel(model);
        return "admin";
      } else {
        receivers = new ArrayList<User>();
        User r = new User();
        r.setEmail(address);
        r.setUsername("TEST");
        r.setName("Test User");
        r.setLanguage(language);
        receivers.add(r);
      }
    } else {
      receivers = userService.getUsersToNotify(role, iso3, true);
    }
    if (receivers.size() == 0) {
      composeErrorMessage(model, "reciver not specified");
      buildModel(model);
      return "admin";
    }
    Status status = new Status();
    status.setCountry(iso3);
    status.setMessage(customText);
    User su = (User) session.getAttribute("sessionUser");
    try {

      notificationService.notifyUsers(su, status, receivers, template);
      composeSuccessMessage(model, receivers);
    } catch (IOException e) {
      LOGGER.error(e.getMessage(), e);
      composeErrorMessage(model, e);
    } catch (TemplateException e) {
      LOGGER.error(e.getMessage(), e);
      composeErrorMessage(model, e);

    } catch (NullPointerException e) {
      LOGGER.error(e.getMessage(), e);
      composeErrorMessage(model, e);
    } catch (Exception e) {
      LOGGER.error(e.getMessage(), e);
      composeErrorMessage(model, e);
    }
    buildModel(model);

    return "admin";
  }
コード例 #2
0
 private void buildModel(Model model) {
   Map<String, Map<String, String>> messages = notificationService.getMessages();
   model.addAttribute("templates", messages);
   model.addAttribute("context", "mailer");
   Map<String, String> roles = new HashMap<String, String>();
   roles.put("contributor", "Contributor");
   roles.put("reviewer", "Reviewer");
   roles.put("editor", "Review Editor");
   roles.put("validator", "Country Validator");
   model.addAttribute("roles", roles);
   model.addAttribute("countries", surveyService.getCountries());
   Map<String, String> lang = new HashMap<String, String>();
   lang.put("en", "English");
   lang.put("fr", "French");
   lang.put("es", "Spanish");
   model.addAttribute("mailLanguage", lang);
 }