Пример #1
0
  /**
   * Get an AppointmentItem using soap
   *
   * @param account
   * @param query
   * @param start
   * @param end
   * @return
   * @throws HarnessException
   */
  public static AppointmentItem importFromSOAP(
      ZimbraAccount account, String query, ZDate start, ZDate end) throws HarnessException {

    try {
      account.soapSend(
          "<SearchRequest xmlns='urn:zimbraMail' types='appointment' calExpandInstStart='"
              + start.toMillis()
              + "' calExpandInstEnd='"
              + end.toMillis()
              + "'>"
              + "<query>"
              + query
              + "</query>"
              + "</SearchRequest>");

      Element[] results = account.soapSelectNodes("//mail:SearchResponse/mail:appt");
      if (results.length != 1)
        // throw new HarnessException("Query should return 1 result, not "+ results.length);
        return null;

      String id = account.soapSelectValue("//mail:appt", "id");

      account.soapSend(
          "<GetAppointmentRequest xmlns='urn:zimbraMail' id='"
              + id
              + "' includeContent='1'>"
              + "</GetAppointmentRequest>");
      Element getAppointmentResponse = account.soapSelectNode("//mail:GetAppointmentResponse", 1);

      // Using the response, create this item
      return (importFromSOAP(getAppointmentResponse));

    } catch (Exception e) {
      throw new HarnessException(
          "Unable to import using SOAP query("
              + query
              + ") and account("
              + account.EmailAddress
              + ")",
          e);
    }
  }
Пример #2
0
  public static TaskItem importFromSOAP(ZimbraAccount account, String query)
      throws HarnessException {

    try {

      account.soapSend(
          "<SearchRequest xmlns='urn:zimbraMail' types='task' >"
              + "<query>"
              + query
              + "</query>"
              + "</SearchRequest>");

      Element[] results = account.soapSelectNodes("//mail:SearchResponse/mail:task");
      if (results.length != 1)
        throw new HarnessException("Query should return 1 result, not " + results.length);

      String invId = account.soapSelectValue("//mail:SearchResponse/mail:task", "invId");

      account.soapSend(
          "<GetMsgRequest xmlns='urn:zimbraMail'>"
              + "<m id='"
              + invId
              + "' />"
              + "</GetMsgRequest>");
      Element getMsgResponse = account.soapSelectNode("//mail:GetMsgResponse", 1);

      // Using the response, create this item
      return (importFromSOAP(getMsgResponse));

    } catch (Exception e) {
      throw new HarnessException(
          "Unable to import using SOAP query("
              + query
              + ") and account("
              + account.EmailAddress
              + ")",
          e);
    }
  }