Search in sources :

Example 1 with InstanceData

use of com.zimbra.cs.mailbox.calendar.cache.InstanceData 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);
}
Also used : AccessManager(com.zimbra.cs.account.AccessManager) FullInstanceData(com.zimbra.cs.mailbox.calendar.cache.FullInstanceData) CalendarDataResult(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult) Folder(com.zimbra.cs.mailbox.Folder) InstanceData(com.zimbra.cs.mailbox.calendar.cache.InstanceData) FullInstanceData(com.zimbra.cs.mailbox.calendar.cache.FullInstanceData) IntervalList(com.zimbra.cs.fb.FreeBusy.IntervalList) CalendarItemData(com.zimbra.cs.mailbox.calendar.cache.CalendarItemData) FBInstance(com.zimbra.cs.fb.FreeBusy.FBInstance) Interval(com.zimbra.cs.fb.FreeBusy.Interval)

Example 2 with InstanceData

use of com.zimbra.cs.mailbox.calendar.cache.InstanceData in project zm-mailbox by Zimbra.

the class GetMiniCal method addBusyDates.

private static void addBusyDates(Calendar cal, CalendarData calData, long rangeStart, long rangeEnd, Set<String> busyDates) throws ServiceException {
    for (Iterator<CalendarItemData> itemIter = calData.calendarItemIterator(); itemIter.hasNext(); ) {
        CalendarItemData item = itemIter.next();
        for (Iterator<InstanceData> instIter = item.instanceIterator(); instIter.hasNext(); ) {
            InstanceData inst = instIter.next();
            // ignore declined meetings.
            String partStat = inst.getPartStat();
            if (partStat == null)
                partStat = item.getDefaultData().getPartStat();
            if (IcalXmlStrMap.PARTSTAT_DECLINED.equals(partStat))
                continue;
            Long start = inst.getDtStart();
            if (start != null) {
                String datestampStart = getDatestamp(cal, start);
                busyDates.add(datestampStart);
                Long duration = inst.getDuration();
                if (duration != null) {
                    long end = start + duration;
                    String datestampEnd = getDatestamp(cal, end);
                    busyDates.add(datestampEnd);
                }
            }
        }
    }
}
Also used : InstanceData(com.zimbra.cs.mailbox.calendar.cache.InstanceData) CalendarItemData(com.zimbra.cs.mailbox.calendar.cache.CalendarItemData)

Aggregations

CalendarItemData (com.zimbra.cs.mailbox.calendar.cache.CalendarItemData)2 InstanceData (com.zimbra.cs.mailbox.calendar.cache.InstanceData)2 AccessManager (com.zimbra.cs.account.AccessManager)1 FBInstance (com.zimbra.cs.fb.FreeBusy.FBInstance)1 Interval (com.zimbra.cs.fb.FreeBusy.Interval)1 IntervalList (com.zimbra.cs.fb.FreeBusy.IntervalList)1 Folder (com.zimbra.cs.mailbox.Folder)1 CalendarDataResult (com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult)1 FullInstanceData (com.zimbra.cs.mailbox.calendar.cache.FullInstanceData)1