Esempio n. 1
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    String type = req.getParameter(PARAM_TYPE);
    String id = req.getParameter(PARAM_ID);
    String op = req.getParameter(PARAM_OP);

    OutputStream os = resp.getOutputStream();
    if (validateParameters(type, id, op)) {
      Set<NotificationInstance> instances = factory.createNotification(type, id, op);
      // System.out.println("Nb. of instances : "+instances.size());
      for (NotificationInstance instance : instances) {
        if (NotificationConstants.SMSMethod.equals(instance.getMethod()))
          smsService.sendNotification(instance);
        else if (NotificationConstants.MailMethod.equals(instance.getMethod()))
          emailService.sendNotification(instance);
        else
          logger.warn(
              "The notification method with the code '"
                  + instance.getMethod()
                  + "' is not implemented.");
      }
    } else {
      resp.setStatus(HttpServletResponse.SC_PRECONDITION_FAILED);
      os.write(BAD_PARAMTERS.getBytes());
    }
    os.flush();
    os.close();
  }
  public String buildServiceOptions(String rule) throws SQLException {
    List services = NotificationFactory.getInstance().getServiceNames();
    Collections.sort(
        services,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((String) o1).compareToIgnoreCase((String) o2);
          }
        });
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < services.size(); i++) {
      if (rule != null && rule.indexOf((String) services.get(i)) > 0) {
        buffer.append(
            "<option selected VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>");
      } else {
        buffer.append("<option VALUE='" + services.get(i) + "'>" + services.get(i) + "</option>");
      }
    }

    return buffer.toString();
  }
  public String buildServiceList(String rule) throws SQLException {
    if (rule == null) {
      return "";
    }

    List services = NotificationFactory.getInstance().getServiceNames();
    Collections.sort(
        services,
        new Comparator() {
          public int compare(Object o1, Object o2) {
            return ((String) o1).compareToIgnoreCase((String) o2);
          }
        });
    StringBuffer buffer = new StringBuffer();

    for (int i = 0; i < services.size(); i++) {
      if (rule.indexOf((String) services.get(i)) > 0) {
        buffer.append(services.get(i)).append("</br>");
      }
    }

    return buffer.toString();
  }