Search in sources :

Example 36 with CalendarItem

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

the class FriendlyCalendaringDescription method addEventDetails.

private void addEventDetails(Invite invite) {
    if (!invite.isEvent())
        return;
    int origPlainLen = mPlainText.length();
    try {
        String uid = invite.getUid();
        String method = invite.getMethod();
        List<ZAttendee> attendees = invite.getAttendees();
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(mAccount);
        // Would be nice to be able to discover what modifications were made by the CalDAV
        // client.  Currently, this information is not stored in the Calendar.
        // Might be able to extract the information from messages in the Sent folder at
        // some point in the future?
        CalendarItem calItem = mbox.getCalendarItemByUid(null, uid);
        if (calItem != null) {
            Invite[] calInvites = calItem.getInvites();
            if ((calInvites != null) && (calInvites.length > 1))
                // At least 1 exception, so this is not a new item
                mDefinitelyModified = true;
        }
        L10nUtil.MsgKey hdrKey = null;
        if (method.equals("REQUEST")) {
            if (invite.getRecurId() != null)
                hdrKey = L10nUtil.MsgKey.zsApptInstanceModified;
            else if (mDefinitelyModified)
                hdrKey = L10nUtil.MsgKey.zsApptModified;
            else
                hdrKey = L10nUtil.MsgKey.zsApptNew;
        } else if (method.equals("CANCEL")) {
            if (invite.getRecurId() != null)
                hdrKey = L10nUtil.MsgKey.calendarCancelAppointmentInstance;
            else
                hdrKey = L10nUtil.MsgKey.calendarCancelAppointment;
        } else if (method.equals("REPLY")) {
            if ((attendees != null) && !attendees.isEmpty()) {
                ZAttendee replier = attendees.get(0);
                String partStat = replier.getPartStat();
                String replierName = replier.getFriendlyAddress().toString();
                if (partStat.equals(IcalXmlStrMap.PARTSTAT_ACCEPTED)) {
                    hdrKey = L10nUtil.MsgKey.calendarDefaultReplyAccept;
                } else if (partStat.equals(IcalXmlStrMap.PARTSTAT_TENTATIVE)) {
                    hdrKey = L10nUtil.MsgKey.calendarDefaultReplyAccept;
                } else if (partStat.equals(IcalXmlStrMap.PARTSTAT_DECLINED)) {
                    hdrKey = L10nUtil.MsgKey.calendarDefaultReplyDecline;
                }
                if (hdrKey != null) {
                    mPlainText.append(L10nUtil.getMessage(hdrKey, mLc, replierName)).append("\n\n");
                    mHtml.append("<h3>").append(L10nUtil.getMessage(hdrKey, mLc, replierName)).append("</h3>");
                    hdrKey = null;
                }
            }
        }
        if (hdrKey != null) {
            mPlainText.append(L10nUtil.getMessage(hdrKey, mLc)).append("\n\n");
            mHtml.append("<h3>").append(L10nUtil.getMessage(hdrKey, mLc)).append("</h3>");
        }
        mHtml.append("\n\n<p>\n<table border=\"0\">\n");
        addSimpleRow(L10nUtil.MsgKey.zsSubject, invite.getName());
        if (invite.hasOrganizer())
            addSimpleRow(L10nUtil.MsgKey.zsOrganizer, invite.getOrganizer().getFriendlyAddress().toString());
        mHtml.append("</table>\n<p>\n<table border=\"0\">\n");
        addSimpleRow(L10nUtil.MsgKey.zsLocation, invite.getLocation());
        ParsedDateTime startTime = invite.getStartTime();
        if (startTime != null) {
            ParsedDateTime endTime = invite.getEndTime();
            if (endTime == null) {
                ParsedDuration dur = invite.getDuration();
                if (dur == null) {
                    dur = ParsedDuration.parse(false, 0, 0, 1, /* hours */
                    0, /* mins */
                    0);
                }
                endTime = startTime.add(dur);
            }
            addSimpleRow(L10nUtil.MsgKey.zsTime, getTimeDisplayString(startTime, endTime, invite.isRecurrence(), invite.isAllDayEvent()));
            ZRecur zr = getRecur(invite);
            if (zr != null) {
                addSimpleRow(L10nUtil.MsgKey.zsRecurrence, getRecurrenceDisplayString(zr, startTime.getCalendarCopy(), mLc));
            }
        }
        if (!method.equals("REPLY") && (attendees != null) && !attendees.isEmpty()) {
            mHtml.append("</table>\n<p>\n<table border=\"0\">\n");
            StringBuilder attendeeList = new StringBuilder();
            boolean firstAdded = false;
            for (ZAttendee attendee : attendees) {
                if (firstAdded) {
                    attendeeList.append(", ");
                } else {
                    firstAdded = true;
                }
                attendeeList.append(attendee.getFriendlyAddress().toString());
            }
            addSimpleRow(L10nUtil.MsgKey.zsInvitees, attendeeList.toString());
        }
        mPlainText.append("*~*~*~*~*~*~*~*~*~*\n");
        mHtml.append("</table>\n");
        mHtml.append("<div>*~*~*~*~*~*~*~*~*~*</div><br>\n");
    } catch (ServiceException e) {
        sLog.debug("Resetting descriptions due to ServiceException", e);
        mPlainText.setLength(origPlainLen);
        mHtml.setLength(0);
    }
}
Also used : ParsedDuration(com.zimbra.common.calendar.ParsedDuration) L10nUtil(com.zimbra.common.util.L10nUtil) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Example 37 with CalendarItem

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

the class GetCalendarItem method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    GetCalendarItemRequestBase req = zsc.elementToJaxb(request);
    boolean sync = req.getSync() == null ? false : req.getSync();
    boolean includeContent = req.getIncludeContent() == null ? false : req.getIncludeContent();
    boolean includeInvites = req.getIncludeInvites() == null ? true : req.getIncludeInvites();
    ItemId iid = null;
    String uid = req.getUid();
    String id = req.getId();
    if (uid != null) {
        if (id != null) {
            throw ServiceException.INVALID_REQUEST("either id or uid should be specified, but not both", null);
        }
        LOG.info("<GetCalendarItem uid=" + uid + "> " + zsc);
    } else {
        iid = new ItemId(id, zsc);
        LOG.info("<GetCalendarItem id=" + iid.getId() + "> " + zsc);
    }
    // want to return modified date only on sync-related requests
    int fields = ToXML.NOTIFY_FIELDS;
    if (sync) {
        fields |= Change.CONFLICT;
    }
    Element response = getResponseElement(zsc);
    CalendarItem calItem = null;
    mbox.lock.lock(false);
    try {
        if (uid != null) {
            calItem = mbox.getCalendarItemByUid(octxt, uid);
            if (calItem == null) {
                throw MailServiceException.NO_SUCH_CALITEM(uid);
            }
        } else {
            calItem = mbox.getCalendarItemById(octxt, iid);
            if (calItem == null) {
                throw MailServiceException.NO_SUCH_CALITEM(iid.toString());
            }
        }
    } finally {
        mbox.lock.release();
    }
    ToXML.encodeCalendarItemSummary(response, ifmt, octxt, calItem, fields, includeInvites, includeContent);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) GetCalendarItemRequestBase(com.zimbra.soap.mail.type.GetCalendarItemRequestBase) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId)

Example 38 with CalendarItem

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

the class GetCalendarItemSummaries method encodeCalendarItemInstances.

/**
 * Encodes a calendar item
 *
 * @param parent
 * @param elementName
 *         name of element to add (MailConstants .E_APPOINTMENT or MailConstants.E_TASK)
 * @param rangeStart
 *         start period to expand instances (or -1 for no start time constraint)
 * @param rangeEnd
 *         end period to expand instances (or -1 for no end time constraint)
 * @param newFormat
 *         temporary HACK - true: SearchRequest, false: GetAppointmentSummaries
 * @return
 */
static EncodeCalendarItemResult encodeCalendarItemInstances(ZimbraSoapContext lc, OperationContext octxt, CalendarItem calItem, Account acct, long rangeStart, long rangeEnd, boolean newFormat) throws ServiceException {
    EncodeCalendarItemResult toRet = new EncodeCalendarItemResult();
    ItemIdFormatter ifmt = new ItemIdFormatter(lc);
    Account authAccount = getAuthenticatedAccount(lc);
    boolean hidePrivate = !calItem.allowPrivateAccess(authAccount, lc.isUsingAdminPrivileges());
    try {
        boolean expandRanges;
        if (calItem instanceof Task) {
            expandRanges = true;
            if (rangeStart == -1 && rangeEnd == -1) {
                rangeStart = Long.MIN_VALUE;
                rangeEnd = Long.MAX_VALUE;
            }
        } else {
            expandRanges = (rangeStart != -1 && rangeEnd != -1 && rangeStart < rangeEnd);
        }
        boolean isAppointment = calItem instanceof Appointment;
        // Use the marshalling code in calendar summary cache for uniform output, when we can.
        if (isAppointment && expandRanges) {
            CalendarItemData calItemData = CalSummaryCache.reloadCalendarItemOverRange(calItem, rangeStart, rangeEnd);
            if (calItemData != null) {
                int numInstances = calItemData.getNumInstances();
                if (numInstances > 0) {
                    Element calItemElem = CacheToXML.encodeCalendarItemData(lc, ifmt, calItemData, !hidePrivate, !newFormat);
                    toRet.element = calItemElem;
                    toRet.numInstancesExpanded = numInstances;
                }
            }
            return toRet;
        }
        // But there are other cases (e.g. tasks, no time range) that require the legacy code below.
        // don't initialize until we find at least one valid instance
        Element calItemElem = null;
        Invite defaultInvite = calItem.getDefaultInviteOrNull();
        if (defaultInvite == null) {
            mLog.info("Could not load defaultinfo for calendar item with id=" + calItem.getId() + " SKIPPING");
            return toRet;
        }
        ParsedDuration defDuration = defaultInvite.getEffectiveDuration();
        // events and 1 second for non all-day.  (bug 28615)
        if (defDuration == null && !defaultInvite.isTodo()) {
            if (defaultInvite.isAllDayEvent()) {
                defDuration = ParsedDuration.ONE_DAY;
            } else {
                defDuration = ParsedDuration.ONE_SECOND;
            }
        }
        long defDurationMsecs = 0;
        if (defaultInvite.getStartTime() != null && defDuration != null) {
            ParsedDateTime s = defaultInvite.getStartTime();
            long et = s.add(defDuration).getUtcTime();
            defDurationMsecs = et - s.getUtcTime();
        }
        String defaultFba = null;
        if (calItem instanceof Appointment) {
            defaultFba = ((Appointment) calItem).getEffectiveFreeBusyActual(defaultInvite, null);
        }
        String defaultPtSt = calItem.getEffectivePartStat(defaultInvite, null);
        AlarmData alarmData = calItem.getAlarmData();
        // add all the instances:
        int numInRange = 0;
        if (expandRanges) {
            Collection<CalendarItem.Instance> instances = calItem.expandInstances(rangeStart, rangeEnd, true);
            long alarmTime = 0;
            long alarmInst = 0;
            if (alarmData != null) {
                alarmTime = alarmData.getNextAt();
                alarmInst = alarmData.getNextInstanceStart();
            }
            for (CalendarItem.Instance inst : instances) {
                try {
                    InviteInfo invId = inst.getInviteInfo();
                    Invite inv = calItem.getInvite(invId.getMsgId(), invId.getComponentId());
                    boolean showAll = !hidePrivate || inv.isPublic();
                    // figure out which fields are different from the default and put their data here...
                    ParsedDuration invDuration = inv.getEffectiveDuration();
                    long instStart = inst.getStart();
                    // For an instance whose alarm time is within the time range, we must
                    // include it even if its start time is after the range.
                    long startOrAlarm = instStart == alarmInst ? alarmTime : instStart;
                    // events and 1 second for non all-day.  (bug 28615)
                    if (invDuration == null) {
                        if (inv.isAllDayEvent())
                            invDuration = ParsedDuration.ONE_DAY;
                        else
                            invDuration = ParsedDuration.ONE_SECOND;
                    }
                    if (!inst.hasStart() || (startOrAlarm < rangeEnd && invDuration.addToTime(instStart) > rangeStart)) {
                        numInRange++;
                    } else {
                        continue;
                    }
                    if (calItemElem == null) {
                        calItemElem = lc.createElement(isAppointment ? MailConstants.E_APPOINTMENT : MailConstants.E_TASK);
                        if (showAll) {
                            // flags and tags
                            ToXML.recordItemTags(calItemElem, calItem, octxt);
                        }
                        // Organizer
                        if (inv.hasOrganizer()) {
                            ZOrganizer org = inv.getOrganizer();
                            org.toXml(calItemElem);
                        }
                        calItemElem.addAttribute("x_uid", calItem.getUid());
                        calItemElem.addAttribute(MailConstants.A_UID, calItem.getUid());
                    }
                    Element instElt = calItemElem.addElement(MailConstants.E_INSTANCE);
                    if (showAll) {
                        if (isAppointment && inv.isEvent()) {
                            String instFba = ((Appointment) calItem).getEffectiveFreeBusyActual(inv, inst);
                            if (instFba != null && (!instFba.equals(defaultFba) || inst.isException()))
                                instElt.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, instFba);
                        }
                        String instPtSt = calItem.getEffectivePartStat(inv, inst);
                        if (!defaultPtSt.equals(instPtSt) || inst.isException())
                            instElt.addAttribute(MailConstants.A_CAL_PARTSTAT, instPtSt);
                    }
                    if (inst.hasStart()) {
                        instElt.addAttribute(MailConstants.A_CAL_START_TIME, instStart);
                        if (inv.isAllDayEvent())
                            instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET, inst.getStartTzOffset());
                    }
                    if (inst.isException() && inv.hasRecurId()) {
                        RecurId rid = inv.getRecurId();
                        instElt.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, rid.getDtZ());
                    } else {
                        instElt.addAttribute(MailConstants.A_CAL_RECURRENCE_ID_Z, inst.getRecurIdZ());
                    }
                    if (inst.isException()) {
                        instElt.addAttribute(MailConstants.A_CAL_IS_EXCEPTION, true);
                        instElt.addAttribute(MailConstants.A_CAL_INV_ID, ifmt.formatItemId(calItem, inst.getMailItemId()));
                        instElt.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, inst.getComponentNum());
                        if (showAll) {
                            // fragment has already been sanitized...
                            String frag = inv.getFragment();
                            if (frag != null && !frag.equals(""))
                                instElt.addAttribute(MailConstants.E_FRAG, frag, Element.Disposition.CONTENT);
                            if (inv.getPriority() != null)
                                instElt.addAttribute(MailConstants.A_CAL_PRIORITY, inv.getPriority());
                            if (inv.isEvent()) {
                                if (inv.getFreeBusy() != null)
                                    instElt.addAttribute(MailConstants.A_APPT_FREEBUSY, inv.getFreeBusy());
                                if (inv.getTransparency() != null)
                                    instElt.addAttribute(MailConstants.A_APPT_TRANSPARENCY, inv.getTransparency());
                            }
                            if (inv.isTodo()) {
                                if (inv.getPercentComplete() != null)
                                    instElt.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, inv.getPercentComplete());
                            }
                            if (inv.getName() != null)
                                instElt.addAttribute(MailConstants.A_NAME, inv.getName());
                            if (inv.getLocation() != null)
                                instElt.addAttribute(MailConstants.A_CAL_LOCATION, inv.getLocation());
                            List<String> categories = inv.getCategories();
                            if (categories != null) {
                                for (String cat : categories) {
                                    instElt.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
                                }
                            }
                            Geo geo = inv.getGeo();
                            if (geo != null)
                                geo.toXml(instElt);
                            if (inv.hasOtherAttendees())
                                instElt.addAttribute(MailConstants.A_CAL_OTHER_ATTENDEES, true);
                            if (inv.hasAlarm())
                                instElt.addAttribute(MailConstants.A_CAL_ALARM, true);
                        }
                        instElt.addAttribute(MailConstants.A_CAL_ISORG, inv.isOrganizer());
                        if (inv.isTodo()) {
                            if (inst.hasEnd()) {
                                instElt.addAttribute(MailConstants.A_TASK_DUE_DATE, inst.getEnd());
                                if (inv.isAllDayEvent())
                                    instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET_DUE, inst.getEndTzOffset());
                            }
                        } else {
                            if (inst.hasStart() && inst.hasEnd()) {
                                instElt.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, inst.getEnd() - inst.getStart());
                            }
                        }
                        if (inv.getStatus() != null)
                            instElt.addAttribute(MailConstants.A_CAL_STATUS, inv.getStatus());
                        if (inv.getClassProp() != null)
                            instElt.addAttribute(MailConstants.A_CAL_CLASS, inv.getClassProp());
                        if (inv.isAllDayEvent())
                            instElt.addAttribute(MailConstants.A_CAL_ALLDAY, true);
                        if (inv.isDraft())
                            instElt.addAttribute(MailConstants.A_CAL_DRAFT, true);
                        if (inv.isNeverSent())
                            instElt.addAttribute(MailConstants.A_CAL_NEVER_SENT, true);
                        if (inv.isRecurrence())
                            instElt.addAttribute(MailConstants.A_CAL_RECUR, true);
                    } else {
                        if (inv.isTodo()) {
                            if (inst.hasEnd()) {
                                instElt.addAttribute(MailConstants.A_TASK_DUE_DATE, inst.getEnd());
                                if (inv.isAllDayEvent())
                                    instElt.addAttribute(MailConstants.A_CAL_TZ_OFFSET_DUE, inst.getEndTzOffset());
                            }
                        } else {
                            // the default duration due to daylight savings time transitions.
                            if (inst.hasStart() && inst.hasEnd() && defDurationMsecs != inst.getEnd() - inst.getStart()) {
                                instElt.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, inst.getEnd() - inst.getStart());
                            }
                        }
                    }
                } catch (MailServiceException.NoSuchItemException e) {
                    mLog.info("Error could not get instance " + inst.getMailItemId() + "-" + inst.getComponentNum() + " for appt " + calItem.getId(), e);
                }
            }
        // iterate all the instances
        }
        if (!expandRanges || numInRange > 0) {
            // if we found any calItems at all, we have to encode the "Default" data here
            boolean showAll = !hidePrivate || defaultInvite.isPublic();
            if (calItemElem == null) {
                calItemElem = lc.createElement(isAppointment ? MailConstants.E_APPOINTMENT : MailConstants.E_TASK);
                calItemElem.addAttribute("x_uid", calItem.getUid());
                calItemElem.addAttribute(MailConstants.A_UID, calItem.getUid());
                if (showAll) {
                    // flags and tags
                    ToXML.recordItemTags(calItemElem, calItem, octxt);
                }
                // Organizer
                if (defaultInvite.hasOrganizer()) {
                    ZOrganizer org = defaultInvite.getOrganizer();
                    org.toXml(calItemElem);
                }
            }
            if (showAll) {
                if (alarmData != null)
                    ToXML.encodeAlarmData(calItemElem, calItem, alarmData);
                String defaultPriority = defaultInvite.getPriority();
                if (defaultPriority != null)
                    calItemElem.addAttribute(MailConstants.A_CAL_PRIORITY, defaultPriority);
                calItemElem.addAttribute(MailConstants.A_CAL_PARTSTAT, defaultPtSt);
                if (defaultInvite.isEvent()) {
                    calItemElem.addAttribute(MailConstants.A_APPT_FREEBUSY, defaultInvite.getFreeBusy());
                    calItemElem.addAttribute(MailConstants.A_APPT_FREEBUSY_ACTUAL, defaultFba);
                    calItemElem.addAttribute(MailConstants.A_APPT_TRANSPARENCY, defaultInvite.getTransparency());
                }
                if (defaultInvite.isTodo()) {
                    String pctComplete = defaultInvite.getPercentComplete();
                    if (pctComplete != null)
                        calItemElem.addAttribute(MailConstants.A_TASK_PERCENT_COMPLETE, pctComplete);
                }
                calItemElem.addAttribute(MailConstants.A_NAME, defaultInvite.getName());
                calItemElem.addAttribute(MailConstants.A_CAL_LOCATION, defaultInvite.getLocation());
                List<String> categories = defaultInvite.getCategories();
                if (categories != null) {
                    for (String cat : categories) {
                        calItemElem.addElement(MailConstants.E_CAL_CATEGORY).setText(cat);
                    }
                }
                Geo geo = defaultInvite.getGeo();
                if (geo != null)
                    geo.toXml(calItemElem);
                // fragment has already been sanitized...
                String fragment = defaultInvite.getFragment();
                if (!fragment.equals(""))
                    calItemElem.addAttribute(MailConstants.E_FRAG, fragment, Element.Disposition.CONTENT);
                if (defaultInvite.hasOtherAttendees()) {
                    calItemElem.addAttribute(MailConstants.A_CAL_OTHER_ATTENDEES, defaultInvite.hasOtherAttendees());
                }
                if (defaultInvite.hasAlarm()) {
                    calItemElem.addAttribute(MailConstants.A_CAL_ALARM, defaultInvite.hasAlarm());
                }
            }
            calItemElem.addAttribute(MailConstants.A_CAL_ISORG, defaultInvite.isOrganizer());
            calItemElem.addAttribute(MailConstants.A_ID, ifmt.formatItemId(calItem));
            calItemElem.addAttribute(MailConstants.A_CAL_INV_ID, ifmt.formatItemId(calItem, defaultInvite.getMailItemId()));
            calItemElem.addAttribute(MailConstants.A_CAL_COMPONENT_NUM, defaultInvite.getComponentNum());
            calItemElem.addAttribute(MailConstants.A_FOLDER, ifmt.formatItemId(new ItemId(calItem.getMailbox().getAccountId(), calItem.getFolderId())));
            calItemElem.addAttribute(MailConstants.A_CAL_STATUS, defaultInvite.getStatus());
            calItemElem.addAttribute(MailConstants.A_CAL_CLASS, defaultInvite.getClassProp());
            if (!defaultInvite.isTodo())
                calItemElem.addAttribute(newFormat ? MailConstants.A_CAL_NEW_DURATION : MailConstants.A_CAL_DURATION, defDurationMsecs);
            if (defaultInvite.isAllDayEvent())
                calItemElem.addAttribute(MailConstants.A_CAL_ALLDAY, defaultInvite.isAllDayEvent());
            if (defaultInvite.isDraft())
                calItemElem.addAttribute(MailConstants.A_CAL_DRAFT, defaultInvite.isDraft());
            if (defaultInvite.isNeverSent())
                calItemElem.addAttribute(MailConstants.A_CAL_NEVER_SENT, defaultInvite.isNeverSent());
            if (defaultInvite.isRecurrence())
                calItemElem.addAttribute(MailConstants.A_CAL_RECUR, defaultInvite.isRecurrence());
            if (calItem.hasExceptions()) {
                calItemElem.addAttribute(MailConstants.A_CAL_HAS_EXCEPTIONS, true);
            }
            toRet.element = calItemElem;
        }
        toRet.numInstancesExpanded = numInRange;
    } catch (MailServiceException.NoSuchItemException e) {
        mLog.info("Error could not get default invite for calendar item: " + calItem.getId(), e);
    } catch (RuntimeException e) {
        mLog.info("Caught Exception " + e + " while getting summary info for calendar item: " + calItem.getId(), e);
    }
    return toRet;
}
Also used : Appointment(com.zimbra.cs.mailbox.Appointment) Account(com.zimbra.cs.account.Account) InviteInfo(com.zimbra.cs.mailbox.calendar.InviteInfo) Task(com.zimbra.cs.mailbox.Task) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) Element(com.zimbra.common.soap.Element) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) CalendarItemData(com.zimbra.cs.mailbox.calendar.cache.CalendarItemData) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) ZOrganizer(com.zimbra.cs.mailbox.calendar.ZOrganizer) Geo(com.zimbra.common.calendar.Geo) Invite(com.zimbra.cs.mailbox.calendar.Invite) AlarmData(com.zimbra.cs.mailbox.CalendarItem.AlarmData)

Example 39 with CalendarItem

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

the class GetCalendarItemSummaries method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    Account acct = getRequestedAccount(zsc);
    long rangeStart = request.getAttributeLong(MailConstants.A_CAL_START_TIME);
    long rangeEnd = request.getAttributeLong(MailConstants.A_CAL_END_TIME);
    if (rangeEnd < rangeStart) {
        throw ServiceException.INVALID_REQUEST("End time must be after Start time", null);
    }
    long days = (rangeEnd - rangeStart) / MSEC_PER_DAY;
    if (days > MAX_PERIOD_SIZE_IN_DAYS) {
        throw ServiceException.INVALID_REQUEST("Requested range is too large (Maximum " + MAX_PERIOD_SIZE_IN_DAYS + " days)", null);
    }
    ItemId iidFolder = new ItemId(request.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER), zsc);
    Element response = getResponseElement(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    if (LC.calendar_cache_enabled.booleanValue()) {
        ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
        int folderId = iidFolder.getId();
        if (folderId != Mailbox.ID_AUTO_INCREMENT) {
            CalendarDataResult result = mbox.getCalendarSummaryForRange(octxt, folderId, getItemType(), rangeStart, rangeEnd);
            if (result != null) {
                for (Iterator<CalendarItemData> itemIter = result.data.calendarItemIterator(); itemIter.hasNext(); ) {
                    CalendarItemData calItemData = itemIter.next();
                    int numInstances = calItemData.getNumInstances();
                    if (numInstances > 0) {
                        Element calItemElem = CacheToXML.encodeCalendarItemData(zsc, ifmt, calItemData, result.allowPrivateAccess, true);
                        response.addElement(calItemElem);
                    }
                }
            }
        } else {
            List<CalendarDataResult> calDataResultList = mbox.getAllCalendarsSummaryForRange(octxt, getItemType(), rangeStart, rangeEnd);
            for (CalendarDataResult result : calDataResultList) {
                for (Iterator<CalendarItemData> itemIter = result.data.calendarItemIterator(); itemIter.hasNext(); ) {
                    CalendarItemData calItemData = itemIter.next();
                    int numInstances = calItemData.getNumInstances();
                    if (numInstances > 0) {
                        Element calItemElem = CacheToXML.encodeCalendarItemData(zsc, ifmt, calItemData, result.allowPrivateAccess, true);
                        response.addElement(calItemElem);
                    }
                }
            }
        }
    } else {
        Collection<CalendarItem> calItems = mbox.getCalendarItemsForRange(octxt, getItemType(), rangeStart, rangeEnd, iidFolder.getId(), null);
        for (CalendarItem calItem : calItems) {
            EncodeCalendarItemResult encoded = encodeCalendarItemInstances(zsc, octxt, calItem, acct, rangeStart, rangeEnd, false);
            if (encoded.element != null)
                response.addElement(encoded.element);
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) CalendarDataResult(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CalendarItemData(com.zimbra.cs.mailbox.calendar.cache.CalendarItemData)

Example 40 with CalendarItem

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

the class CounterCalendarItem method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account acct = getRequestedAccount(zsc);
    Mailbox mbox = getRequestedMailbox(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    Invite oldInv = null;
    // proxy handling
    String idStr = request.getAttribute(MailConstants.A_ID, null);
    if (idStr != null) {
        ItemId iid = new ItemId(idStr, zsc);
        if (!iid.belongsTo(acct))
            return proxyRequest(request, context, iid.getAccountId());
        CalendarItem calItem = mbox.getCalendarItemById(octxt, iid.getId());
        if (calItem == null) {
            throw MailServiceException.NO_SUCH_CALITEM(iid.toString(), "Could not find calendar item");
        }
        // Conflict detection.  Do it only if requested by client.  (for backward compat)
        int modSeq = (int) request.getAttributeLong(MailConstants.A_MODIFIED_SEQUENCE, 0);
        int revision = (int) request.getAttributeLong(MailConstants.A_REVISION, 0);
        if (modSeq != 0 && revision != 0 && (modSeq < calItem.getModifiedSequence() || revision < calItem.getSavedSequence()))
            throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
        int compNum = (int) request.getAttributeLong(MailConstants.A_CAL_COMP, 0);
        if (compNum != 0) {
            oldInv = calItem.getInvite(iid.getSubpartId(), compNum);
            if (oldInv == null)
                throw MailServiceException.INVITE_OUT_OF_DATE(iid.toString());
        }
    }
    Element msgElem = request.getElement(MailConstants.E_MSG);
    InviteParser parser = new InviteParser(oldInv);
    CalSendData dat = handleMsgElement(zsc, octxt, msgElem, acct, mbox, parser);
    MailSender mailSender = mbox.getMailSender();
    mailSender.sendMimeMessage(octxt, mbox, dat.mMm);
    Element response = getResponseElement(zsc);
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Element(com.zimbra.common.soap.Element) MailSender(com.zimbra.cs.mailbox.MailSender) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Invite(com.zimbra.cs.mailbox.calendar.Invite)

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