Search in sources :

Example 66 with ParsedDateTime

use of com.zimbra.common.calendar.ParsedDateTime in project zm-mailbox by Zimbra.

the class Invite method sanitize.

public void sanitize(boolean throwException) throws ServiceException {
    if ((mUid == null || mUid.length() == 0)) {
        if (throwException)
            throw ServiceException.INVALID_REQUEST("missing UID; subject=" + mName, null);
        else
            ZimbraLog.calendar.warn("UID missing; subject=" + mName);
    }
    mUid = fixupIfOutlookUid(mUid);
    // Don't let a task have DTSTART without DUE.
    if (isTodo() && mStart != null && mEnd == null)
        mStart = null;
    // Keep all-day flag and DTSTART/DTEND/DUE in sync.
    // Use DTSTART if given.  Fall back to DTEND/DUE.
    ParsedDateTime dt = mStart != null ? mStart : mEnd;
    if (dt == null) {
        // No DTSTART.  Force non-all-day.
        setIsAllDayEvent(false);
    } else if (!dt.hasTime()) {
        // DTSTART has no time part.  Force all-day.
        setIsAllDayEvent(true);
    } else if (!dt.hasZeroTime()) {
        // Time part is not T000000.  Force non-all-day.
        setIsAllDayEvent(false);
    } else {
    // Time part is T000000.  Strictly speaking presence of any time part implies non-all-day,
    // but Outlook compatibility dictates we allow T000000 in an all-day appointment.
    // Leave current all-day flag as is.
    }
    // ORGANIZER is required if there is at least one ATTENDEE.
    if (isOrganizerMethod(mMethod) && hasOtherAttendees() && !hasOrganizer()) {
        if (throwException) {
            throw ServiceException.INVALID_REQUEST("ORGANIZER missing when ATTENDEEs are present; UID=" + mUid + ", subject=" + mName, null);
        } else {
            // If we don't know who the organizer is, remove attendees.  Some clients will assume missing
            // organizer means current user is the organizer.  If attendees were kept, these clients will
            // send cancel notice to the attendees when appointment is deleted.  The attendees will get
            // confused because the cancel notice came from someone other than the organizer.
            ZimbraLog.calendar.warn("ORGANIZER missing; clearing ATTENDEEs to avoid confusing clients; UID=" + mUid + ", subject=" + mName);
            clearAttendees();
        }
    }
    // DTEND or DUE, if specified, can't be earlier than DTSTART.
    if (mStart != null && mEnd != null && mEnd.compareTo(mStart) < 0)
        mEnd = (ParsedDateTime) mStart.clone();
    // Recurrence rule can't be set without DTSTART.
    if (mRecurrence != null && mStart == null) {
        if (throwException) {
            throw ServiceException.INVALID_REQUEST("recurrence used without DTSTART; UID=" + mUid + ", subject=" + mName, null);
        } else {
            ZimbraLog.calendar.warn("recurrence used without DTSTART; removing recurrence; UID=" + mUid + ", subject=" + mName);
            mRecurrence = null;
        }
    }
    // Don't allow using different time zones in DTSTART and DTEND for a recurrence. (prevents future problems)
    if (isRecurrence() && mStart != null && mEnd != null && !mStart.getTimeZone().equals(mEnd.getTimeZone())) {
        ZimbraLog.calendar.warn("recurrence uses different time zones in DTSTART and DTEND; forcing DTEND to DTSTART time zone; UID=" + mUid + ", subject=" + mName);
        mEnd.toTimeZone(mStart.getTimeZone());
    }
    mPercentComplete = limitIntegerRange(mPercentComplete, 0, 100, null);
    mPriority = limitIntegerRange(mPriority, 0, 9, null);
    // Clean up the time zone map to remove unreferenced TZs.
    Set<String> tzids = getReferencedTZIDs();
    mTzMap.reduceTo(tzids);
    // Set LAST-MODIFIED to DTSTAMP if unset.
    if (mLastModified == 0)
        mLastModified = mDTStamp;
}
Also used : ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Aggregations

ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)66 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)23 Invite (com.zimbra.cs.mailbox.calendar.Invite)20 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)18 ParseException (java.text.ParseException)16 ArrayList (java.util.ArrayList)16 IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)15 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)14 Element (com.zimbra.common.soap.Element)13 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)11 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)10 Account (com.zimbra.cs.account.Account)10 ZOrganizer (com.zimbra.cs.mailbox.calendar.ZOrganizer)10 ZVCalendar (com.zimbra.common.calendar.ZCalendar.ZVCalendar)9 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)8 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)8 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)7 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)7 ServiceException (com.zimbra.common.service.ServiceException)7 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)7