Search in sources :

Example 1 with IException

use of com.zimbra.cs.mailbox.calendar.Recurrence.IException in project zm-mailbox by Zimbra.

the class ExpandRecur method parseRecur.

protected static ParsedRecurrence parseRecur(Element request, TimeZoneMap tzmap) throws ServiceException {
    CalendarUtils.parseTimeZones(request, tzmap);
    IRecurrence recurrence = null;
    List<IException> exceptions = new ArrayList<IException>();
    for (Iterator<Element> compIter = request.elementIterator(); compIter.hasNext(); ) {
        Element elem = compIter.next();
        String elemName = elem.getName();
        boolean isCancel = false;
        if (MailConstants.E_CAL_CANCEL.equals(elemName)) {
            isCancel = true;
        } else if (!MailConstants.E_INVITE_COMPONENT.equals(elemName) && !MailConstants.E_CAL_EXCEPT.equals(elemName)) {
            continue;
        }
        RecurId recurId = null;
        Element recurIdElem = elem.getOptionalElement(MailConstants.E_CAL_EXCEPTION_ID);
        if (recurIdElem != null)
            recurId = CalendarUtils.parseRecurId(recurIdElem, tzmap);
        if (!isCancel) {
            ParsedDateTime dtStart = null;
            Element dtStartElem = elem.getElement(MailConstants.E_CAL_START_TIME);
            dtStart = CalendarUtils.parseDateTime(dtStartElem, tzmap);
            ParsedDateTime dtEnd = null;
            Element dtEndElem = elem.getOptionalElement(MailConstants.E_CAL_END_TIME);
            if (dtEndElem != null)
                dtEnd = CalendarUtils.parseDateTime(dtEndElem, tzmap);
            ParsedDuration dur = null;
            Element durElem = elem.getOptionalElement(MailConstants.E_CAL_DURATION);
            if (durElem != null)
                dur = ParsedDuration.parse(durElem);
            if (dtEnd == null && dur == null)
                throw ServiceException.INVALID_REQUEST("Must specify either " + MailConstants.E_CAL_END_TIME + " or " + MailConstants.E_CAL_DURATION + " in " + elemName, null);
            Element recurElem = elem.getOptionalElement(MailConstants.E_CAL_RECUR);
            if (recurElem != null) {
                // series with a rule
                recurrence = CalendarUtils.parseRecur(recurElem, tzmap, dtStart, dtEnd, dur, recurId);
            } else {
                // modified instance, or it has no rule and no recurrence-id
                if (dur == null && dtStart != null && dtEnd != null)
                    dur = dtEnd.difference(dtStart);
                if (recurId == null)
                    recurId = new RecurId(dtStart, RecurId.RANGE_NONE);
                exceptions.add(new ExceptionRule(recurId, dtStart, dur, null));
            }
        } else if (recurId != null) {
            // canceled instance
            exceptions.add(new CancellationRule(recurId));
        }
    }
    ParsedRecurrence parsed = new ParsedRecurrence();
    if (recurrence instanceof RecurrenceRule) {
        RecurrenceRule rrule = (RecurrenceRule) recurrence;
        for (IException exception : exceptions) {
            rrule.addException(exception);
        }
        parsed.rrule = rrule;
    } else {
        parsed.exceptions = exceptions;
    }
    return parsed;
}
Also used : RecurrenceRule(com.zimbra.cs.mailbox.calendar.Recurrence.RecurrenceRule) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) CancellationRule(com.zimbra.cs.mailbox.calendar.Recurrence.CancellationRule) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) RecurId(com.zimbra.cs.mailbox.calendar.RecurId) ExceptionRule(com.zimbra.cs.mailbox.calendar.Recurrence.ExceptionRule) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) IException(com.zimbra.cs.mailbox.calendar.Recurrence.IException) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Aggregations

ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)1 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)1 Element (com.zimbra.common.soap.Element)1 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)1 CancellationRule (com.zimbra.cs.mailbox.calendar.Recurrence.CancellationRule)1 ExceptionRule (com.zimbra.cs.mailbox.calendar.Recurrence.ExceptionRule)1 IException (com.zimbra.cs.mailbox.calendar.Recurrence.IException)1 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)1 RecurrenceRule (com.zimbra.cs.mailbox.calendar.Recurrence.RecurrenceRule)1 ArrayList (java.util.ArrayList)1