Search in sources :

Example 11 with IRecurrence

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

the class WorkingHours method getWorkingHours.

public static FreeBusy getWorkingHours(Account authAcct, boolean asAdmin, Account account, String name, long start, long end) throws ServiceException {
    // If free/busy viewing is blocked, so is viewing working hours.
    AccessManager accessMgr = AccessManager.getInstance();
    boolean accountAceAllowed = accessMgr.canDo(authAcct, account, User.R_viewFreeBusy, asAdmin);
    if (!accountAceAllowed)
        return FreeBusy.nodataFreeBusy(account.getName(), start, end);
    // Get the working hours preference and parse it.
    String workingHoursPref = account.getPrefCalendarWorkingHours();
    HoursByDay workingHoursByDay = new HoursByDay(workingHoursPref);
    // Build a recurrence rule for each day of the week and expand over the time range.
    IntervalList intervals = new IntervalList(start, end);
    ICalTimeZone tz = Util.getAccountTimeZone(account);
    TimeZoneMap tzmap = new TimeZoneMap(tz);
    StartSpec startSpec = new StartSpec(start, tz);
    for (int day = 1; day <= 7; ++day) {
        TimeRange timeRange = workingHoursByDay.getHoursForDay(day);
        if (timeRange.enabled) {
            IRecurrence rrule = getRecurrenceForDay(day, startSpec, timeRange, tz, tzmap);
            List<Instance> instances = rrule.expandInstances(0, start, end);
            for (Instance inst : instances) {
                Interval ival = new Interval(inst.getStart(), inst.getEnd(), IcalXmlStrMap.FBTYPE_BUSY_UNAVAILABLE);
                intervals.addInterval(ival);
            }
        }
    }
    // hours are shown as out-of-office.
    for (Iterator<Interval> iter = intervals.iterator(); iter.hasNext(); ) {
        Interval interval = iter.next();
        String status = interval.getStatus();
        interval.setStatus(invertStatus(status));
    }
    return new FreeBusy(name, intervals, start, end);
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) Instance(com.zimbra.cs.mailbox.CalendarItem.Instance) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) IntervalList(com.zimbra.cs.fb.FreeBusy.IntervalList) TimeZoneMap(com.zimbra.common.calendar.TimeZoneMap) ICalTimeZone(com.zimbra.common.calendar.ICalTimeZone) Interval(com.zimbra.cs.fb.FreeBusy.Interval)

Example 12 with IRecurrence

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

the class Invite method getExdates.

public List<Instance> getExdates() {
    List<Instance> exdates = Lists.newArrayList();
    IRecurrence recurrence = getRecurrence();
    if (recurrence == null) {
        return exdates;
    }
    for (Iterator<?> iter = recurrence.subRulesIterator(); iter != null && iter.hasNext(); ) {
        IRecurrence cur = (IRecurrence) iter.next();
        switch(cur.getType()) {
            case Recurrence.TYPE_SINGLE_DATES:
                Recurrence.SingleDates sd = (Recurrence.SingleDates) cur;
                RdateExdate exdate = sd.getRdateExdate();
                if (exdate.isEXDATE()) {
                    exdates.addAll(sd.expandInstances(getMailItemId()));
                } else {
                    ZimbraLog.calendar.debug("RDATE '%s' ignored", exdate);
                }
                break;
            case Recurrence.TYPE_REPEATING:
                // See http://tools.ietf.org/html/rfc5545 A.3. Deprecated Features
                // 1.  The "EXRULE" property can no longer be specified in a component.
                ZimbraLog.calendar.debug("EXRULE ignored - no longer supported in rfc5545");
                break;
        }
    }
    return exdates;
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) Instance(com.zimbra.cs.mailbox.CalendarItem.Instance)

Example 13 with IRecurrence

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

the class InviteChanges method diffInvites.

private void diffInvites(Invite inv1, Invite inv2) {
    // Subject
    if (!StringUtil.equal(inv1.getName(), inv2.getName()))
        mChanges |= SUBJECT;
    // LOCATION
    if (!StringUtil.equal(inv1.getLocation(), inv2.getLocation()))
        mChanges |= LOCATION;
    // DTSTART
    boolean dtStartChanged;
    ParsedDateTime dtStart1 = inv1.getStartTime();
    ParsedDateTime dtStart2 = inv2.getStartTime();
    if (dtStart1 == null || dtStart2 == null)
        dtStartChanged = dtStart1 != dtStart2;
    else
        dtStartChanged = !StringUtil.equal(dtStart1.getDateTimePartString(false), dtStart2.getDateTimePartString(false));
    if (dtStartChanged) {
        mChanges |= TIME;
    } else {
        // DTEND
        boolean dtEndChanged;
        ParsedDateTime dtEnd1 = inv1.getEndTime();
        ParsedDateTime dtEnd2 = inv2.getEndTime();
        if (dtEnd1 == null || dtEnd2 == null)
            dtEndChanged = dtEnd1 != dtEnd2;
        else
            dtEndChanged = !StringUtil.equal(dtEnd1.getDateTimePartString(false), dtEnd2.getDateTimePartString(false));
        if (dtEndChanged) {
            mChanges |= TIME;
        } else {
            boolean durationChanged;
            ParsedDuration dur1 = inv1.getDuration();
            ParsedDuration dur2 = inv2.getDuration();
            if (dur1 == null || dur2 == null)
                durationChanged = dur1 != dur2;
            else
                durationChanged = !dur1.equals(dur2);
            if (durationChanged)
                mChanges |= TIME;
        }
    }
    // Recurrence
    boolean recurChanged;
    IRecurrence recur1 = inv1.getRecurrence();
    IRecurrence recur2 = inv2.getRecurrence();
    if (recur1 == null || recur2 == null) {
        recurChanged = recur1 != recur2;
    } else {
        recurChanged = !Recurrence.sameSeriesRules(recur1, recur2);
    }
    if (recurChanged)
        mChanges |= RECURRENCE;
}
Also used : IRecurrence(com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence) ParsedDuration(com.zimbra.common.calendar.ParsedDuration) ParsedDateTime(com.zimbra.common.calendar.ParsedDateTime)

Aggregations

IRecurrence (com.zimbra.cs.mailbox.calendar.Recurrence.IRecurrence)13 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)10 ParsedDuration (com.zimbra.common.calendar.ParsedDuration)7 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)4 Invite (com.zimbra.cs.mailbox.calendar.Invite)4 ArrayList (java.util.ArrayList)4 ICalTok (com.zimbra.common.calendar.ZCalendar.ICalTok)3 ZProperty (com.zimbra.common.calendar.ZCalendar.ZProperty)3 Element (com.zimbra.common.soap.Element)3 RecurrenceRule (com.zimbra.cs.mailbox.calendar.Recurrence.RecurrenceRule)3 Iterator (java.util.Iterator)3 TimeZoneMap (com.zimbra.common.calendar.TimeZoneMap)2 ZComponent (com.zimbra.common.calendar.ZCalendar.ZComponent)2 ZParameter (com.zimbra.common.calendar.ZCalendar.ZParameter)2 ServiceException (com.zimbra.common.service.ServiceException)2 Instance (com.zimbra.cs.mailbox.CalendarItem.Instance)2 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)2 Recurrence (com.zimbra.cs.mailbox.calendar.Recurrence)2 ZRecur (com.zimbra.cs.mailbox.calendar.ZRecur)2 HashSet (java.util.HashSet)2