Search in sources :

Example 6 with CalendarDataResult

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

the class GetCalendarItemSummaries method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    Account acct = getRequestedAccount(zsc);
    long rangeStart = request.getAttributeLong(MailConstants.A_CAL_START_TIME);
    long rangeEnd = request.getAttributeLong(MailConstants.A_CAL_END_TIME);
    if (rangeEnd < rangeStart) {
        throw ServiceException.INVALID_REQUEST("End time must be after Start time", null);
    }
    long days = (rangeEnd - rangeStart) / MSEC_PER_DAY;
    if (days > MAX_PERIOD_SIZE_IN_DAYS) {
        throw ServiceException.INVALID_REQUEST("Requested range is too large (Maximum " + MAX_PERIOD_SIZE_IN_DAYS + " days)", null);
    }
    ItemId iidFolder = new ItemId(request.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER), zsc);
    Element response = getResponseElement(zsc);
    OperationContext octxt = getOperationContext(zsc, context);
    if (LC.calendar_cache_enabled.booleanValue()) {
        ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
        int folderId = iidFolder.getId();
        if (folderId != Mailbox.ID_AUTO_INCREMENT) {
            CalendarDataResult result = mbox.getCalendarSummaryForRange(octxt, folderId, getItemType(), rangeStart, rangeEnd);
            if (result != null) {
                for (Iterator<CalendarItemData> itemIter = result.data.calendarItemIterator(); itemIter.hasNext(); ) {
                    CalendarItemData calItemData = itemIter.next();
                    int numInstances = calItemData.getNumInstances();
                    if (numInstances > 0) {
                        Element calItemElem = CacheToXML.encodeCalendarItemData(zsc, ifmt, calItemData, result.allowPrivateAccess, true);
                        response.addElement(calItemElem);
                    }
                }
            }
        } else {
            List<CalendarDataResult> calDataResultList = mbox.getAllCalendarsSummaryForRange(octxt, getItemType(), rangeStart, rangeEnd);
            for (CalendarDataResult result : calDataResultList) {
                for (Iterator<CalendarItemData> itemIter = result.data.calendarItemIterator(); itemIter.hasNext(); ) {
                    CalendarItemData calItemData = itemIter.next();
                    int numInstances = calItemData.getNumInstances();
                    if (numInstances > 0) {
                        Element calItemElem = CacheToXML.encodeCalendarItemData(zsc, ifmt, calItemData, result.allowPrivateAccess, true);
                        response.addElement(calItemElem);
                    }
                }
            }
        }
    } else {
        Collection<CalendarItem> calItems = mbox.getCalendarItemsForRange(octxt, getItemType(), rangeStart, rangeEnd, iidFolder.getId(), null);
        for (CalendarItem calItem : calItems) {
            EncodeCalendarItemResult encoded = encodeCalendarItemInstances(zsc, octxt, calItem, acct, rangeStart, rangeEnd, false);
            if (encoded.element != null)
                response.addElement(encoded.element);
        }
    }
    return response;
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) Element(com.zimbra.common.soap.Element) CalendarDataResult(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult) ItemId(com.zimbra.cs.service.util.ItemId) CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) CalendarItemData(com.zimbra.cs.mailbox.calendar.cache.CalendarItemData)

Example 7 with CalendarDataResult

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

the class Mailbox method getAllCalendarsSummaryForRange.

public List<CalendarDataResult> getAllCalendarsSummaryForRange(OperationContext octxt, MailItem.Type type, long start, long end) throws ServiceException {
    boolean success = false;
    try {
        // folder cache is populated in beginTransaction...
        beginReadTransaction("getAllCalendarsSummaryForRange", octxt);
        success = true;
        List<CalendarDataResult> list = new ArrayList<CalendarDataResult>();
        for (Folder folder : listAllFolders()) {
            if (folder.inTrash() || folder.inSpam()) {
                continue;
            }
            // any calendar items.
            if (folder.getDefaultView() != type) {
                continue;
            }
            try {
                if (!folder.canAccess(ACL.RIGHT_READ)) {
                    continue;
                }
                CalendarDataResult result = CalendarCacheManager.getInstance().getSummaryCache().getCalendarSummary(octxt, getAccountId(), folder.getId(), type, start, end, true);
                if (result != null) {
                    list.add(result);
                }
            } catch (ServiceException se) {
                ZimbraLog.fb.info("Problem getting calendar summary cache for folder '%s' - ignoring", folder.getName(), se);
                throw se;
            }
        }
        return list;
    } finally {
        endTransaction(success);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) CalendarDataResult(com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult) CreateFolder(com.zimbra.cs.redolog.op.CreateFolder) ZFolder(com.zimbra.client.ZFolder)

Aggregations

CalendarDataResult (com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache.CalendarDataResult)7 ServiceException (com.zimbra.common.service.ServiceException)4 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)4 Account (com.zimbra.cs.account.Account)3 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 ItemId (com.zimbra.cs.service.util.ItemId)3 ArrayList (java.util.ArrayList)3 ZMailbox (com.zimbra.client.ZMailbox)2 Element (com.zimbra.common.soap.Element)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Provisioning (com.zimbra.cs.account.Provisioning)2 Server (com.zimbra.cs.account.Server)2 MailboxManager (com.zimbra.cs.mailbox.MailboxManager)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 CalSummaryCache (com.zimbra.cs.mailbox.calendar.cache.CalSummaryCache)2 CalendarItemData (com.zimbra.cs.mailbox.calendar.cache.CalendarItemData)2 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2