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);
}
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;
}
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;
}
Aggregations