Search in sources :

Example 1 with ZAppointmentHit

use of com.zimbra.client.ZAppointmentHit in project zm-mailbox by Zimbra.

the class ZMailboxUtil method doGetAppointmentSummaries.

/*


<CreateAppointmentRequest xmlns="urn:zimbraMail">
 <m d="1173202005230" l="10">
  <inv>
   <comp status="CONF" fb="B" transp="O" allDay="0" name="test yearly">
    <s tz="(GMT-08.00) Pacific Time (US &amp; Canada)" d="20070308T130000"/>
    <e tz="(GMT-08.00) Pacific Time (US &amp; Canada)" d="20070308T150000"/>
      <or a="user1@slapshot.liquidsys.com"/>
       <recur>
        <add>
         <rule freq="YEA">
            <interval ival="1"/>
         </rule>
        </add>
      </recur>
    </comp></inv><su>test yearly</su><mp ct="multipart/alternative"><mp ct="text/plain"><content></content></mp><mp ct="text/html"><content>&lt;html&gt;&lt;body&gt;&lt;/body&gt;&lt;/html&gt;</content></mp></mp></m></CreateAppointmentRequest>
     */
/*
    private void testCreateAppt() throws ServiceException {

        ZMailbox.ZOutgoingMessage message = new ZOutgoingMessage();
        message.setSubject("test zclient API");
        message.setMessagePart(new MessagePart("text/plain", "this is da body"));
        ZInvite invite = new ZInvite();
        ZComponent comp = new ZComponent();
        comp.setStart(new ZDateTime("20070309T170000", mMbox.getPrefs().getTimeZoneWindowsId()));
        comp.setEnd(new ZDateTime("20070309T210000", mMbox.getPrefs().getTimeZoneWindowsId()));
        comp.setOrganizer(new ZOrganizer(mMbox.getName()));
        comp.setName("test zclient API");
        comp.setLocation("Zimbra");
        invite.getComponents().add(comp);

        ZAppointmentResult response = mMbox.createAppointment(ZFolder.ID_CALENDAR, null, message, invite, null);
        stdout.printf("calItemId(%s) inviteId(%s)%n", response.getCalItemId(), response.getInviteId());
    }
*/
private void doGetAppointmentSummaries(String[] args) throws ServiceException {
    long startTime = DateUtil.parseDateSpecifier(args[0], new Date().getTime());
    long endTime = DateUtil.parseDateSpecifier(args[1], (new Date().getTime()) + Constants.MILLIS_PER_WEEK);
    String folderId = args.length == 3 ? lookupFolderId(args[2]) : null;
    List<ZApptSummaryResult> results = mMbox.getApptSummaries(null, startTime, endTime, new String[] { folderId }, TimeZone.getDefault(), ZSearchParams.TYPE_APPOINTMENT);
    if (results.size() != 1)
        return;
    ZApptSummaryResult result = results.get(0);
    stdout.print("[");
    boolean first = true;
    for (ZAppointmentHit appt : result.getAppointments()) {
        if (!first)
            stdout.println(",");
        stdout.print(ZJSONObject.toString(appt));
        if (first)
            first = false;
    }
    stdout.println("]");
}
Also used : ZAppointmentHit(com.zimbra.client.ZAppointmentHit) ZApptSummaryResult(com.zimbra.client.ZMailbox.ZApptSummaryResult) Date(java.util.Date)

Example 2 with ZAppointmentHit

use of com.zimbra.client.ZAppointmentHit in project zm-mailbox by Zimbra.

the class ZMailboxUtil method dumpSearch.

private void dumpSearch(ZSearchResult sr, boolean verbose) {
    if (verbose) {
        stdout.println(sr.dump());
        return;
    }
    int offset = mSearchPage * mSearchParams.getLimit();
    int first = offset + 1;
    int last = offset + sr.getHits().size();
    stdout.printf("num: %d, more: %s%n%n", sr.getHits().size(), sr.hasMore());
    int width = colWidth(last);
    if (sr.getHits().size() == 0) {
        return;
    }
    final int FROM_LEN = 20;
    int id_len = 4;
    for (ZSearchHit hit : sr.getHits()) {
        id_len = Math.max(id_len, hit.getId().length());
    }
    Calendar cal = Calendar.getInstance();
    String headerFormat = String.format("%%%d.%ds  %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%s%%n", width, width, id_len, id_len);
    String itemFormat = String.format("%%%d.%ds. %%%d.%ds  %%4s   %%-20.20s  %%-50.50s  %%tD %%<tR%%n", width, width, id_len, id_len);
    stdout.format(headerFormat, "", "Id", "Type", "From", "Subject", "Date");
    stdout.format(headerFormat, "", "----------------------------------------------------------------------------------------------------", "----", "--------------------", "--------------------------------------------------", "--------------");
    int i = first;
    for (ZSearchHit hit : sr.getHits()) {
        if (hit instanceof ZConversationHit) {
            ZConversationHit ch = (ZConversationHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String sub = ch.getSubject();
            String from = emailAddrs(ch.getRecipients());
            if (ch.getMessageCount() > 1) {
                String numMsg = " (" + ch.getMessageCount() + ")";
                int space = FROM_LEN - numMsg.length();
                from = ((from.length() < space) ? from : from.substring(0, space)) + numMsg;
            }
            //if (ch.getFragment() != null || ch.getFragment().length() > 0)
            //    sub += " (" + ch.getFragment()+")";
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "conv", from, sub, cal);
        } else if (hit instanceof ZContactHit) {
            ZContactHit ch = (ZContactHit) hit;
            cal.setTimeInMillis(ch.getDate());
            String from = getFirstEmail(ch);
            String sub = ch.getFileAsStr();
            mIndexToId.put(i, ch.getId());
            stdout.format(itemFormat, i++, ch.getId(), "cont", from, sub, cal);
        } else if (hit instanceof ZMessageHit) {
            ZMessageHit mh = (ZMessageHit) hit;
            cal.setTimeInMillis(mh.getDate());
            String sub = mh.getSubject();
            String from = mh.getSender() == null ? "<none>" : mh.getSender().getDisplay();
            mIndexToId.put(i, mh.getId());
            stdout.format(itemFormat, i++, mh.getId(), "mess", from, sub, cal);
        } else if (hit instanceof ZAppointmentHit) {
            ZAppointmentHit ah = (ZAppointmentHit) hit;
            if (ah.getInstanceExpanded()) {
                cal.setTimeInMillis(ah.getStartTime());
            } else {
                cal.setTimeInMillis(ah.getHitDate());
            }
            String sub = ah.getName();
            String from = "<na>";
            mIndexToId.put(i, ah.getId());
            stdout.format(itemFormat, i++, ah.getId(), ah.getIsTask() ? "task" : "appo", from, sub, cal);
        } else if (hit instanceof ZDocumentHit) {
            ZDocumentHit dh = (ZDocumentHit) hit;
            ZDocument doc = dh.getDocument();
            cal.setTimeInMillis(doc.getModifiedDate());
            String name = doc.getName();
            String editor = doc.getEditor();
            mIndexToId.put(i, dh.getId());
            stdout.format(itemFormat, i++, dh.getId(), doc.isWiki() ? "wiki" : "doc", editor, name, cal);
        }
    }
    stdout.println();
}
Also used : ZSearchHit(com.zimbra.client.ZSearchHit) ZAppointmentHit(com.zimbra.client.ZAppointmentHit) ZContactHit(com.zimbra.client.ZContactHit) ZDocument(com.zimbra.client.ZDocument) Calendar(java.util.Calendar) ZMessageHit(com.zimbra.client.ZMessageHit) ZConversationHit(com.zimbra.client.ZConversationHit) ZMountpoint(com.zimbra.client.ZMountpoint) ZDocumentHit(com.zimbra.client.ZDocumentHit)

Aggregations

ZAppointmentHit (com.zimbra.client.ZAppointmentHit)2 ZContactHit (com.zimbra.client.ZContactHit)1 ZConversationHit (com.zimbra.client.ZConversationHit)1 ZDocument (com.zimbra.client.ZDocument)1 ZDocumentHit (com.zimbra.client.ZDocumentHit)1 ZApptSummaryResult (com.zimbra.client.ZMailbox.ZApptSummaryResult)1 ZMessageHit (com.zimbra.client.ZMessageHit)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 ZSearchHit (com.zimbra.client.ZSearchHit)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1