Exemplo n.º 1
0
  private List<Appointement> getSortedRdv() {
    try {
      client = ZMailbox.getByName(login, pass, "https://zimbra.inria.fr/service/soap/");
      XMLElement req = new XMLElement(ZimbraNamespace.E_BATCH_REQUEST);
      Element gas = req.addElement(MailConstants.GET_APPT_SUMMARIES_REQUEST);

      Calendar cal = Calendar.getInstance();
      Date today = cal.getTime();
      //		cal.add(Calendar.HOUR, -1); // to get previous year add -1
      gas.addAttribute(MailConstants.A_CAL_START_TIME, today.getTime());

      cal.add(Calendar.MONTH, 1); // to get previous year add -1
      Date nextYear = cal.getTime();

      gas.addAttribute(MailConstants.A_CAL_END_TIME, nextYear.getTime());
      gas.addAttribute(MailConstants.A_FOLDER, zimbraFolderId);
      Element resp = client.invoke(req);
      List<Appointement> lists = new ArrayList<Appointement>();

      for (Element e : resp.listElements()) {
        for (Element appt : e.listElements(MailConstants.E_APPOINTMENT)) {
          Appointement a = new Appointement();
          a.setLabel("" + appt.toXML().attribute("name").getData());
          a.setLocation("" + appt.toXML().attribute("loc").getData());
          String duration = "" + appt.toXML().attribute("d").getData();
          a.setDuration(Long.parseLong(duration) / 1000);
          ZDateTime dated =
              new ZDateTime("" + appt.toXML().element("inst").attribute("ridZ").getData());
          a.setDate(dated.getDate());
          lists.add(a);
        }
      }
      Collections.sort(
          lists,
          new Comparator<Appointement>() {

            public int compare(Appointement appt1, Appointement appt2) {
              return appt1.getDate().compareTo(appt2.getDate());
            }
          });

      return lists;
    } catch (ServiceException e) {
      e.printStackTrace();
    }
    return new ArrayList<Appointement>();
  }