Search in sources :

Example 6 with CalendarItem

use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.

the class CalendarCollection method getAppointmentsByUids.

public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
    Map<String, String> uidmap = getUidToHrefMap(hrefs);
    Mailbox mbox = getCalendarMailbox(ctxt);
    ArrayList<DavResource> appts = new ArrayList<DavResource>();
    ctxt.setCollectionPath(getUri());
    Map<String, CalendarItem> calItems = mbox.getCalendarItemsByUid(ctxt.getOperationContext(), new ArrayList<String>(uidmap.keySet()));
    for (String uid : calItems.keySet()) {
        CalendarItem calItem = calItems.get(uid);
        if (calItem == null)
            appts.add(new DavResource.InvalidResource(uidmap.get(uid), getOwner()));
        else
            appts.add(new CalendarObject.LocalCalendarObject(ctxt, calItem));
    }
    return appts;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ArrayList(java.util.ArrayList)

Example 7 with CalendarItem

use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.

the class FreeBusyQuery method prepareRequests.

private void prepareRequests(ArrayList<FreeBusy> local, RemoteFreeBusyProvider remote, ArrayList<String> external) {
    for (String id : mTargets.keySet()) {
        Account acct = mTargets.get(id);
        try {
            if (acct == null || acct.isAccountExternal() || acct.getBooleanAttr(Provisioning.A_zimbraFreebusyLocalMailboxNotActive, false)) {
                external.add(id);
                continue;
            }
            int folder = mTargetFolder.get(id);
            if (Provisioning.onLocalServer(acct)) {
                Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
                OperationContext octxt = null;
                if (mCtxt != null && mCtxt.getAuthToken() != null)
                    octxt = new OperationContext(mCtxt.getAuthToken());
                else if (mRequestor != null)
                    octxt = new OperationContext(mRequestor);
                else
                    octxt = new OperationContext(GuestAccount.ANONYMOUS_ACCT);
                Appointment exAppt = null;
                if (mExApptUid != null) {
                    CalendarItem ci = mbox.getCalendarItemByUid(octxt, mExApptUid);
                    if (ci instanceof Appointment)
                        exAppt = (Appointment) ci;
                }
                local.add(mbox.getFreeBusy(octxt, id, mStart, mEnd, folder, exAppt));
            } else {
                remote.addFreeBusyRequest(mRequestor, acct, id, mStart, mEnd, folder);
            }
        } catch (ServiceException e) {
            ZimbraLog.fb.error("cannot get free/busy for " + id, e);
        }
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Appointment(com.zimbra.cs.mailbox.Appointment) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException)

Example 8 with CalendarItem

use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.

the class CalItemReminderTaskBase method call.

/**
 * Computes a result, or throws an exception if unable to do so.
 *
 * @return computed result
 * @throws Exception if unable to compute a result
 */
public CalendarItem call() throws Exception {
    if (ZimbraLog.scheduler.isDebugEnabled())
        ZimbraLog.scheduler.debug("Running task %s", this);
    Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
    if (mbox == null) {
        ZimbraLog.scheduler.error("Mailbox with id %s does not exist", getMailboxId());
        return null;
    }
    Integer calItemId = new Integer(getProperty(CAL_ITEM_ID_PROP_NAME));
    CalendarItem calItem;
    try {
        calItem = mbox.getCalendarItemById(null, calItemId);
    } catch (ServiceException e) {
        ZimbraLog.scheduler.warn("Calendar item with id %s does not exist", calItemId);
        return null;
    }
    if (calItem.inTrash()) {
        ZimbraLog.scheduler.debug("Calendar item with id %s is in Trash", calItemId);
        return null;
    }
    Integer invId = new Integer(getProperty(INV_ID_PROP_NAME));
    Integer compNum = new Integer(getProperty(COMP_NUM_PROP_NAME));
    Invite invite = calItem.getInvite(invId, compNum);
    if (invite == null) {
        ZimbraLog.scheduler.warn("Invite with id %s and comp num %s does not exist", invId, compNum);
        return null;
    }
    sendReminder(calItem, invite);
    return calItem;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) Invite(com.zimbra.cs.mailbox.calendar.Invite)

Example 9 with CalendarItem

use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.

the class CalSummaryCache method fetchCalendarItemData.

private static CalendarItemData fetchCalendarItemData(OperationContext octxt, Mailbox mbox, int folderId, int calItemId, long rangeStart, long rangeEnd) throws ServiceException {
    CalendarItem calItem = null;
    try {
        calItem = mbox.getCalendarItemById(octxt, calItemId);
    } catch (MailServiceException e) {
        if (!e.getCode().equals(MailServiceException.NO_SUCH_ITEM) && !e.getCode().equals(MailServiceException.NO_SUCH_APPT) && !e.getCode().equals(MailServiceException.NO_SUCH_TASK))
            throw e;
    // NO_SUCH_ITEM/APPT/TASK exception is an expected condition.  This happens when a calendar item
    // was hard deleted from a sync client.  Calendar cache doesn't process the delete notification
    // because the notification doesn't indicate which folder the item is getting deleted from.
    }
    CalendarItemData calItemData = null;
    // If folder is different, this item must have been moved out of our folder.  Ignore it.
    if (calItem != null && calItem.getFolderId() == folderId)
        calItemData = reloadCalendarItemOverRange(calItem, rangeStart, rangeEnd);
    return calItemData;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) MailServiceException(com.zimbra.cs.mailbox.MailServiceException)

Example 10 with CalendarItem

use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.

the class CalSummaryCache method reloadCalendarOverRangeWithFolderScan.

// Reload by first calling Mailbox.getCalendarItemsForRange(), which runs a query on appointment table.
private static CalendarData reloadCalendarOverRangeWithFolderScan(OperationContext octxt, Mailbox mbox, int folderId, MailItem.Type type, long rangeStart, long rangeEnd, CalendarData prevCalData) throws ServiceException {
    if (rangeEnd < rangeStart)
        throw ServiceException.INVALID_REQUEST("End time must be after Start time", null);
    long days = (rangeEnd - rangeStart) / MSEC_PER_DAY;
    if (days > sMaxSearchDays)
        throw ServiceException.INVALID_REQUEST("Requested range is too large (Maximum " + sMaxSearchDays + " days)", null);
    // Ignore existing data if its range doesn't include the entire requested range.
    if (prevCalData != null && (rangeStart < prevCalData.getRangeStart() || rangeEnd > prevCalData.getRangeEnd()))
        prevCalData = null;
    Folder folder = mbox.getFolderById(octxt, folderId);
    CalendarData calData = new CalendarData(folderId, folder.getImapMODSEQ(), rangeStart, rangeEnd);
    Collection<CalendarItem> calItems = mbox.getCalendarItemsForRange(octxt, type, rangeStart, rangeEnd, folderId, null);
    for (CalendarItem calItem : calItems) {
        if (prevCalData != null) {
            // Reuse the appointment if it didn't change.
            CalendarItemData cur = prevCalData.getCalendarItemData(calItem.getId());
            if (cur != null && cur.getModMetadata() == calItem.getModifiedSequence()) {
                calData.addCalendarItem(cur);
                continue;
            }
        }
        // We couldn't reuse the existing data.  Get it the hard way.
        CalendarItemData calItemData = reloadCalendarItemOverRange(calItem, rangeStart, rangeEnd);
        if (calItemData != null)
            calData.addCalendarItem(calItemData);
    }
    // return a non-null object even if there are no items in the range
    return calData;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Folder(com.zimbra.cs.mailbox.Folder)

Aggregations

CalendarItem (com.zimbra.cs.mailbox.CalendarItem)56 Mailbox (com.zimbra.cs.mailbox.Mailbox)36 Element (com.zimbra.common.soap.Element)27 OperationContext (com.zimbra.cs.mailbox.OperationContext)24 Invite (com.zimbra.cs.mailbox.calendar.Invite)23 ItemId (com.zimbra.cs.service.util.ItemId)22 Account (com.zimbra.cs.account.Account)19 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)17 ServiceException (com.zimbra.common.service.ServiceException)15 MailItem (com.zimbra.cs.mailbox.MailItem)14 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)13 Message (com.zimbra.cs.mailbox.Message)12 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)11 Folder (com.zimbra.cs.mailbox.Folder)9 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)9 Appointment (com.zimbra.cs.mailbox.Appointment)8 ArrayList (java.util.ArrayList)8 MimeMessage (javax.mail.internet.MimeMessage)8 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)7 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)5