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