Search in sources :

Example 1 with AlarmData

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

the class Mailbox method setCalendarItem.

/**
 * @param exceptions can be NULL
 * @return calendar item ID
 */
public CalendarItem setCalendarItem(OperationContext octxt, int folderId, int flags, String[] tags, SetCalendarItemData defaultInv, SetCalendarItemData[] exceptions, List<ReplyInfo> replies, long nextAlarm) throws ServiceException {
    flags = (flags & ~Flag.FLAGS_SYSTEM);
    SetCalendarItem redoRecorder = new SetCalendarItem(getId(), attachmentsIndexingEnabled(), flags, tags);
    boolean success = false;
    try {
        beginTransaction("setCalendarItem", octxt, redoRecorder);
        Tag.NormalizedTags ntags = new Tag.NormalizedTags(this, tags);
        // Make a single list containing default and exceptions.
        int scidLen = (defaultInv != null ? 1 : 0) + (exceptions != null ? exceptions.length : 0);
        List<SetCalendarItemData> scidList = new ArrayList<SetCalendarItemData>(scidLen);
        if (defaultInv != null) {
            defaultInv.invite.setLastFullSeqNo(defaultInv.invite.getSeqNo());
            scidList.add(defaultInv);
        }
        if (exceptions != null) {
            for (SetCalendarItemData scid : exceptions) {
                scid.invite.setLastFullSeqNo(scid.invite.getSeqNo());
                scidList.add(scid);
            }
        }
        CalendarItem calItem = null;
        // old invId information.
        if (!scidList.isEmpty()) {
            calItem = getCalendarItemByUid(octxt, scidList.get(0).invite.getUid());
            for (SetCalendarItemData scid : scidList) {
                int idBeingSet = scid.invite.getMailItemId();
                if (idBeingSet <= 0) {
                    if (calItem != null) {
                        Invite currInv = calItem.getInvite(scid.invite.getRecurId());
                        if (currInv != null) {
                            scid.invite.setInviteId(currInv.getMailItemId());
                            // Carry over local-only setting.
                            boolean currLO = currInv.isLocalOnly();
                            boolean newLO = scid.invite.isLocalOnly();
                            scid.invite.setLocalOnly(currLO && newLO);
                        } else {
                            scid.invite.setInviteId(getNextItemId(Mailbox.ID_AUTO_INCREMENT));
                        }
                    } else {
                        scid.invite.setInviteId(getNextItemId(Mailbox.ID_AUTO_INCREMENT));
                    }
                }
            }
            // if new version doesn't specify it.  (bug 41002)
            if (calItem != null && calItem.getFolderId() != Mailbox.ID_FOLDER_TRASH) {
                Invite currSeries = calItem.getDefaultInviteOrNull();
                for (SetCalendarItemData scid : scidList) {
                    if (!scid.invite.hasFreeBusy()) {
                        Invite currInv = calItem.getInvite(scid.invite.getRecurId());
                        if (currInv == null) {
                            // Inherit from series as fallback.
                            currInv = currSeries;
                        }
                        if (currInv != null && currInv.hasFreeBusy()) {
                            if (scid.invite.isTransparent()) {
                                // New invite is transparent.  New intended f/b must be free.
                                scid.invite.setFreeBusy(IcalXmlStrMap.FBTYPE_FREE);
                            } else {
                                // New invite is opaque.
                                if (IcalXmlStrMap.FBTYPE_FREE.equals(currInv.getFreeBusy())) {
                                    // An opaque invite cannot have intended f/b value of free.  Make it busy.
                                    scid.invite.setFreeBusy(IcalXmlStrMap.FBTYPE_BUSY);
                                } else {
                                    // Current intended f/b has a non-free value, so keep it.  It's better
                                    // to preserve tentative or OOO value than to unconditionally change to busy.
                                    scid.invite.setFreeBusy(currInv.getFreeBusy());
                                }
                            }
                        }
                    }
                }
            }
        }
        // trace logging
        if (!scidList.isEmpty()) {
            Invite invLog = scidList.get(0).invite;
            String idStr = calItem != null ? Integer.toString(calItem.getId()) : "(new)";
            ZimbraLog.calendar.info("setCalendarItem: id=%s, folderId=%d, subject=\"%s\", UID=%s", idStr, folderId, (invLog != null && invLog.isPublic() ? invLog.getName() : "(private)"), invLog.getUid());
        }
        redoRecorder.setData(defaultInv, exceptions, replies, nextAlarm);
        AlarmData oldAlarmData = null;
        for (SetCalendarItemData scid : scidList) {
            if (scid.message == null) {
                // the MimeMessage is fake, so we don't need to index it
                scid.invite.setDontIndexMimeMessage(true);
                String desc = scid.invite.getDescription();
                if (desc != null && desc.length() > Invite.getMaxDescInMeta()) {
                    MimeMessage mm = CalendarMailSender.createCalendarMessage(scid.invite);
                    scid.message = new ParsedMessage(mm, octxt == null ? System.currentTimeMillis() : octxt.getTimestamp(), true);
                }
            }
        }
        if (scidList.size() > 0) {
            SetCalendarItemData scid = scidList.get(0);
            if (calItem == null) {
                // ONLY create an calendar item if this is a REQUEST method...otherwise don't.
                String method = scid.invite.getMethod();
                if ("REQUEST".equals(method) || "PUBLISH".equals(method)) {
                    try {
                        calItem = createCalendarItem(folderId, flags, ntags, scid.invite.getUid(), scid.message, scid.invite, null);
                    } catch (MailServiceException e) {
                        if (e.getCode() == MailServiceException.ALREADY_EXISTS) {
                            // bug 49106 - did not find the appointment above in getCalendarItemByUid(), but the mail_item exists
                            ZimbraLog.calendar.error("failed to create calendar item; already exists. cause: " + (scidList.isEmpty() ? "no items in uid list." : "uid not found in appointment: " + scidList.get(0).invite.getUid() + " or bad mail_item type"));
                        }
                        throw e;
                    }
                } else {
                    // for now, just ignore this Invitation
                    return null;
                }
            } else {
                calItem.snapshotRevision();
                // Preserve alarm time before any modification is made to the item.
                if (calItem.getAlarmData() != null) {
                    oldAlarmData = (AlarmData) calItem.getAlarmData().clone();
                }
                calItem.setTags(flags, ntags);
                calItem.processNewInvite(scid.message, scid.invite, folderId, nextAlarm, false, /* preserveAlarms */
                true, /* replaceExistingInvites */
                false);
            }
            redoRecorder.setCalendarItemAttrs(calItem.getId(), calItem.getFolderId());
        }
        if (scidList.size() > 1) {
            // remove the first one. it is already processed
            scidList.remove(0);
            // exceptions
            calItem.processNewInviteExceptions(scidList, folderId, nextAlarm, false, false);
        }
        // Recompute alarm time after processing all Invites.
        if (nextAlarm == CalendarItem.NEXT_ALARM_KEEP_CURRENT) {
            nextAlarm = oldAlarmData != null ? oldAlarmData.getNextAt() : CalendarItem.NEXT_ALARM_FROM_NOW;
        }
        calItem.updateNextAlarm(nextAlarm, oldAlarmData, false);
        // List with one or more replies means replacing existing replies.
        if (replies != null) {
            calItem.setReplies(replies);
        }
        index.add(calItem);
        success = true;
        return calItem;
    } finally {
        endTransaction(success);
    }
}
Also used : NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) TargetConstraint(com.zimbra.cs.mailbox.MailItem.TargetConstraint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) SetCalendarItem(com.zimbra.cs.redolog.op.SetCalendarItem) MimeMessage(javax.mail.internet.MimeMessage) SetCalendarItem(com.zimbra.cs.redolog.op.SetCalendarItem) NormalizedTags(com.zimbra.cs.mailbox.Tag.NormalizedTags) AlterItemTag(com.zimbra.cs.redolog.op.AlterItemTag) CreateTag(com.zimbra.cs.redolog.op.CreateTag) DbTag(com.zimbra.cs.db.DbTag) CreateInvite(com.zimbra.cs.redolog.op.CreateInvite) Invite(com.zimbra.cs.mailbox.calendar.Invite) AlarmData(com.zimbra.cs.mailbox.CalendarItem.AlarmData)

Example 2 with AlarmData

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

the class SnoozeCalendarItemAlarm method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    String acctId = mbox.getAccountId();
    Account authAcct = getAuthenticatedAccount(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    Element response = getResponseElement(zsc);
    for (String calItemElement : sCalItemElems) {
        for (Iterator<Element> iter = request.elementIterator(calItemElement); iter.hasNext(); ) {
            Element calItemElem = iter.next();
            ItemId iid = new ItemId(calItemElem.getAttribute(MailConstants.A_ID), zsc);
            long snoozeUntil = calItemElem.getAttributeLong(MailConstants.A_CAL_ALARM_SNOOZE_UNTIL);
            // trace logging
            ZimbraLog.calendar.info("<SnoozeCalendarItemAlarm> id=%s,until=%d", iid.toString(), snoozeUntil);
            // mailbox for this calendar item; not necessarily same as requested mailbox
            Mailbox ciMbox = null;
            String ciAcctId = iid.getAccountId();
            if (ciAcctId == null || ciAcctId.equals(acctId)) {
                ciMbox = mbox;
            } else {
                // Let's see if the account is a Desktop account.
                if (AccountUtil.isZDesktopLocalAccount(zsc.getAuthtokenAccountId()))
                    ciMbox = MailboxManager.getInstance().getMailboxByAccountId(ciAcctId, false);
                if (ciMbox == null)
                    throw MailServiceException.PERM_DENIED("cannot snooze alarms of a shared calendar");
            }
            int calItemId = iid.getId();
            ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
            try {
                ciMbox.snoozeCalendarItemAlarm(octxt, calItemId, snoozeUntil);
                CalendarItem calItem = ciMbox.getCalendarItemById(octxt, calItemId);
                Element calItemRespElem;
                if (calItem instanceof Appointment)
                    calItemRespElem = response.addElement(MailConstants.E_APPOINTMENT);
                else
                    calItemRespElem = response.addElement(MailConstants.E_TASK);
                calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
                boolean hidePrivate = !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
                boolean showAll = !hidePrivate || calItem.isPublic();
                if (showAll) {
                    AlarmData alarmData = calItem.getAlarmData();
                    if (alarmData != null)
                        ToXML.encodeAlarmData(calItemRespElem, calItem, alarmData);
                }
            } catch (NoSuchItemException nsie) {
                // item must not exist in db anymore.
                // this can happen if an alarm is snoozed while a big sync is happening which deletes the item (e.g. bug 48560)
                // since item is not in db, it has effectively been snoozed; return ok and no further alarms
                Element calItemRespElem = response.addElement(calItemElement);
                calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
            }
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Appointment(com.zimbra.cs.mailbox.Appointment) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AlarmData(com.zimbra.cs.mailbox.CalendarItem.AlarmData)

Example 3 with AlarmData

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

the class DismissCalendarItemAlarm method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    String acctId = mbox.getAccountId();
    Account authAcct = getAuthenticatedAccount(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    Element response = getResponseElement(zsc);
    for (String calItemElement : sCalItemElems) {
        for (Iterator<Element> iter = request.elementIterator(calItemElement); iter.hasNext(); ) {
            Element calItemElem = iter.next();
            ItemId iid = new ItemId(calItemElem.getAttribute(MailConstants.A_ID), zsc);
            long dismissedAt = calItemElem.getAttributeLong(MailConstants.A_CAL_ALARM_DISMISSED_AT);
            // trace logging
            ZimbraLog.calendar.info("<DismissCalendarItemAlarm> id=%s, at=%d", iid.toString(), dismissedAt);
            // mailbox for this calendar item; not necessarily same as requested mailbox
            Mailbox ciMbox = null;
            String ciAcctId = iid.getAccountId();
            if (ciAcctId == null || ciAcctId.equals(acctId)) {
                ciMbox = mbox;
            } else {
                // Let's see if the account is a Desktop account.
                if (AccountUtil.isZDesktopLocalAccount(zsc.getAuthtokenAccountId()))
                    ciMbox = MailboxManager.getInstance().getMailboxByAccountId(ciAcctId, false);
                if (ciMbox == null)
                    throw MailServiceException.PERM_DENIED("cannot dismiss alarms of a shared calendar");
            }
            int calItemId = iid.getId();
            ItemIdFormatter ifmt = new ItemIdFormatter(authAcct.getId(), acctId, false);
            try {
                ciMbox.dismissCalendarItemAlarm(octxt, calItemId, dismissedAt);
                CalendarItem calItem = ciMbox.getCalendarItemById(octxt, calItemId);
                Element calItemRespElem;
                if (calItem instanceof Appointment)
                    calItemRespElem = response.addElement(MailConstants.E_APPOINTMENT);
                else
                    calItemRespElem = response.addElement(MailConstants.E_TASK);
                calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
                boolean hidePrivate = !calItem.allowPrivateAccess(authAcct, zsc.isUsingAdminPrivileges());
                boolean showAll = !hidePrivate || calItem.isPublic();
                if (showAll) {
                    AlarmData alarmData = calItem.getAlarmData();
                    if (alarmData != null)
                        ToXML.encodeAlarmData(calItemRespElem, calItem, alarmData);
                }
            } catch (NoSuchItemException nsie) {
                // item must not exist in db anymore.
                // this can happen if an alarm is dismissed while a big sync is happening which deletes the item (e.g. bug 48560)
                // since item is not in db, it has effectively been dismissed; return ok and no further alarms
                Element calItemRespElem = response.addElement(calItemElement);
                calItemRespElem.addAttribute(MailConstants.A_CAL_ID, iid.toString(ifmt));
            }
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Appointment(com.zimbra.cs.mailbox.Appointment) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AlarmData(com.zimbra.cs.mailbox.CalendarItem.AlarmData)

Example 4 with AlarmData

use of com.zimbra.cs.mailbox.CalendarItem.AlarmData 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)

Aggregations

AlarmData (com.zimbra.cs.mailbox.CalendarItem.AlarmData)4 Element (com.zimbra.common.soap.Element)3 Account (com.zimbra.cs.account.Account)3 Appointment (com.zimbra.cs.mailbox.Appointment)3 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)3 ItemId (com.zimbra.cs.service.util.ItemId)3 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)3 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)2 Mailbox (com.zimbra.cs.mailbox.Mailbox)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 Invite (com.zimbra.cs.mailbox.calendar.Invite)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 Geo (com.zimbra.common.calendar.Geo)1 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)1 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)1 DbTag (com.zimbra.cs.db.DbTag)1 TargetConstraint (com.zimbra.cs.mailbox.MailItem.TargetConstraint)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 NormalizedTags (com.zimbra.cs.mailbox.Tag.NormalizedTags)1 Task (com.zimbra.cs.mailbox.Task)1