use of com.zimbra.cs.fb.FreeBusy.FBInstance in project zm-mailbox by Zimbra.
the class LocalFreeBusyProvider method getFreeBusyList.
/**
* @param mbox
* @param start
* @param end
* @param folder folder to run free/busy search on; FreeBusyQuery.CALENDAR_FOLDER_ALL (-1) for all folders
* @param exAppt appointment to exclude; calculate free/busy assuming
* the specified appointment wasn't there
* @return
* @throws ServiceException
*/
public static FreeBusy getFreeBusyList(Account authAcct, boolean asAdmin, Mailbox mbox, String name, long start, long end, int folder, Appointment exAppt) throws ServiceException {
AccessManager accessMgr = AccessManager.getInstance();
boolean accountAceAllowed = accessMgr.canDo(authAcct, mbox.getAccount(), User.R_viewFreeBusy, asAdmin);
int numAllowedFolders = 0;
int exApptId = exAppt == null ? -1 : exAppt.getId();
IntervalList intervals = new IntervalList(start, end);
List<CalendarDataResult> calDataResultList;
if (folder == FreeBusyQuery.CALENDAR_FOLDER_ALL) {
calDataResultList = mbox.getAllCalendarsSummaryForRange(null, MailItem.Type.APPOINTMENT, start, end);
} else {
calDataResultList = new ArrayList<CalendarDataResult>(1);
calDataResultList.add(mbox.getCalendarSummaryForRange(null, folder, MailItem.Type.APPOINTMENT, start, end));
}
for (CalendarDataResult result : calDataResultList) {
int folderId = result.data.getFolderId();
Folder f = mbox.getFolderById(null, folderId);
if ((f.getFlagBitmask() & Flag.BITMASK_EXCLUDE_FREEBUSY) != 0) {
ZimbraLog.fb.debug("Calendar '%s' id=%s ignored - has EXCLUDE_FREEBUSY flag set", f.getName(), folderId);
continue;
}
// Free/busy must be allowed by folder or at account-level.
boolean folderFBAllowed = CalendarItem.allowFreeBusyAccess(f, authAcct, asAdmin);
if (folderFBAllowed)
++numAllowedFolders;
if (!folderFBAllowed && !accountAceAllowed) {
ZimbraLog.fb.debug("Calendar '%s' id=%s ignored - folderFBAllowed=%s accountAceAllowed=%s", f.getName(), folderId, folderFBAllowed, accountAceAllowed);
continue;
}
for (Iterator<CalendarItemData> iter = result.data.calendarItemIterator(); iter.hasNext(); ) {
CalendarItemData appt = iter.next();
int apptId = appt.getCalItemId();
if (apptId == exApptId)
continue;
FullInstanceData defaultInstance = appt.getDefaultData();
if (defaultInstance == null)
continue;
boolean isTransparent = false;
String transp = defaultInstance.getTransparency();
isTransparent = IcalXmlStrMap.TRANSP_TRANSPARENT.equals(transp);
long defaultDuration = 0;
if (defaultInstance.getDuration() != null)
defaultDuration = defaultInstance.getDuration().longValue();
String defaultFreeBusy = defaultInstance.getFreeBusyActual();
for (Iterator<InstanceData> instIter = appt.instanceIterator(); instIter.hasNext(); ) {
InstanceData instance = instIter.next();
long instStart = instance.getDtStart() != null ? instance.getDtStart().longValue() : 0;
// Skip instances that are outside the time range but were returned due to alarm being in range.
if (instStart >= end)
continue;
long dur = defaultDuration;
if (instance.getDuration() != null)
dur = instance.getDuration().longValue();
if (// Only consider instances with non-zero, positive duration.
dur <= 0)
continue;
long instEnd = instStart + dur;
long recurIdDt = 0;
// Skip if instance is TRANSPARENT to free/busy searches.
if (instance instanceof FullInstanceData) {
FullInstanceData fullInst = (FullInstanceData) instance;
String transpInst = fullInst.getTransparency();
recurIdDt = fullInst.getRecurrenceId();
if (IcalXmlStrMap.TRANSP_TRANSPARENT.equals(transpInst))
continue;
} else if (isTransparent) {
continue;
}
String freeBusy = instance.getFreeBusyActual();
if (freeBusy == null)
freeBusy = defaultFreeBusy;
if (!IcalXmlStrMap.FBTYPE_FREE.equals(freeBusy)) {
FBInstance fbInst = new FBInstance(freeBusy, instStart, instEnd, apptId, recurIdDt);
Interval ival = new Interval(instStart, instEnd, freeBusy, fbInst);
intervals.addInterval(ival);
}
}
}
}
if (!accountAceAllowed && numAllowedFolders == 0 && !LC.freebusy_disable_nodata_status.booleanValue()) {
Interval nodata = new Interval(start, end, IcalXmlStrMap.FBTYPE_NODATA);
intervals.addInterval(nodata);
}
return new FreeBusy(name, intervals, start, end);
}
use of com.zimbra.cs.fb.FreeBusy.FBInstance in project zm-mailbox by Zimbra.
the class Appointment method getBusyTimesString.
private static String getBusyTimesString(OperationContext octxt, Mailbox mbox, List<Conflict> list, TimeZone tz, Locale lc, boolean hasMoreConflicts) throws ServiceException {
StringBuilder sb = new StringBuilder();
int conflictCount = 0;
for (Conflict avail : list) {
if (!avail.isBusy())
continue;
// List conflicting appointments and their organizers.
FreeBusy fb = avail.getFreeBusy();
List<FBInstance> instances = new ArrayList<FBInstance>();
for (Iterator<Interval> iter = fb.iterator(); iter.hasNext(); ) {
Interval interval = iter.next();
// busy intervals only
if (Conflict.isBusy(interval.getStatus())) {
// busy appointments only
for (FBInstance fbinst : interval.getInstances()) {
if (Conflict.isBusy(fbinst.getFreeBusy()))
instances.add(fbinst);
}
}
}
for (FBInstance instance : instances) {
Date startDate = new Date(instance.getStartTime());
Date endDate = new Date(instance.getEndTime());
String start = CalendarMailSender.formatDateTime(startDate, tz, lc);
sb.append(" * ").append(start);
String end;
if (DateTimeUtil.sameDay(startDate, endDate, tz)) {
end = CalendarMailSender.formatTime(endDate, tz, lc);
sb.append(" - ").append(end);
} else {
end = CalendarMailSender.formatDateTime(endDate, tz, lc);
sb.append("\r\n - ").append(end);
}
int apptId = instance.getApptId();
long recurIdDt = instance.getRecurIdDt();
CalendarItem appt = mbox.getCalendarItemById(octxt, apptId);
Invite inv = appt.getInviteForRecurId(recurIdDt);
if (inv != null && inv.hasOrganizer()) {
ZOrganizer organizer = inv.getOrganizer();
String orgDispName;
if (organizer.hasCn())
orgDispName = organizer.getCn() + " <" + organizer.getAddress() + ">";
else
orgDispName = organizer.getAddress();
sb.append(L10nUtil.getMessage(MsgKey.calendarResourceConflictScheduledBy, lc, orgDispName));
}
sb.append("\r\n");
conflictCount++;
}
}
if (hasMoreConflicts)
sb.append(" * ...\r\n");
return sb.toString();
}
Aggregations