use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class GetMiniCal method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
Account authAcct = getAuthenticatedAccount(zsc);
OperationContext octxt = getOperationContext(zsc, context);
Element response = getResponseElement(zsc);
long rangeStart = request.getAttributeLong(MailConstants.A_CAL_START_TIME);
long rangeEnd = request.getAttributeLong(MailConstants.A_CAL_END_TIME);
List<ItemId> folderIids = new ArrayList<ItemId>();
for (Iterator<Element> foldersIter = request.elementIterator(MailConstants.E_FOLDER); foldersIter.hasNext(); ) {
Element fElem = foldersIter.next();
ItemId iidFolder = new ItemId(fElem.getAttribute(MailConstants.A_ID), zsc);
folderIids.add(iidFolder);
}
ICalTimeZone tz = parseTimeZone(request);
if (tz == null)
// requestor's time zone, not mailbox owner's
tz = Util.getAccountTimeZone(authAcct);
TreeSet<String> busyDates = new TreeSet<String>();
Provisioning prov = Provisioning.getInstance();
MailboxManager mboxMgr = MailboxManager.getInstance();
Server localServer = prov.getLocalServer();
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Map<ItemId, Resolved> resolved = resolveMountpoints(octxt, mbox, folderIids);
Map<ItemId, ItemId> /* requested iid */
reverseMap = new HashMap<ItemId, ItemId>();
for (Map.Entry<ItemId, Resolved> entry : resolved.entrySet()) {
ItemId requestedIid = entry.getKey();
Resolved res = entry.getValue();
if (res.error == null) {
reverseMap.put(res.iid, requestedIid);
} else {
addError(response, ifmt.formatItemId(requestedIid), res.error.getCode(), res.error.getMessage());
}
}
Map<Server, Map<String, List<Integer>>> /* folder ids */
groupedByServer = Search.groupByServer(groupFoldersByAccount(resolved));
// Look up in calendar cache first.
if (LC.calendar_cache_enabled.booleanValue()) {
CalSummaryCache calCache = CalendarCacheManager.getInstance().getSummaryCache();
Calendar cal = new GregorianCalendar(tz);
for (Iterator<Map.Entry<Server, Map<String, List<Integer>>>> serverIter = groupedByServer.entrySet().iterator(); serverIter.hasNext(); ) {
Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry = serverIter.next();
Map<String, List<Integer>> accountFolders = serverMapEntry.getValue();
// for each account
for (Iterator<Map.Entry<String, List<Integer>>> acctIter = accountFolders.entrySet().iterator(); acctIter.hasNext(); ) {
Map.Entry<String, List<Integer>> acctEntry = acctIter.next();
String acctId = acctEntry.getKey();
List<Integer> folderIds = acctEntry.getValue();
// for each folder
for (Iterator<Integer> iterFolderId = folderIds.iterator(); iterFolderId.hasNext(); ) {
int folderId = iterFolderId.next();
try {
CalendarDataResult result = calCache.getCalendarSummary(octxt, acctId, folderId, MailItem.Type.APPOINTMENT, rangeStart, rangeEnd, true);
if (result != null) {
// Found data in cache.
iterFolderId.remove();
addBusyDates(cal, result.data, rangeStart, rangeEnd, busyDates);
}
} catch (ServiceException e) {
iterFolderId.remove();
ItemId iid = new ItemId(acctId, folderId);
// Error must mention folder id requested by client.
ItemId reqIid = reverseMap.get(iid);
if (reqIid != null) {
ZimbraLog.calendar.warn("Error accessing calendar folder " + ifmt.formatItemId(reqIid), e);
addError(response, ifmt.formatItemId(reqIid), e.getCode(), e.getMessage());
} else {
ZimbraLog.calendar.warn("Error accessing calendar folder; resolved id=" + ifmt.formatItemId(iid) + " (missing reverse mapping)", e);
addError(response, ifmt.formatItemId(iid), e.getCode(), e.getMessage());
}
}
}
if (folderIds.isEmpty())
acctIter.remove();
}
if (accountFolders.isEmpty())
serverIter.remove();
}
}
// For any remaining calendars, we have to get the data the hard way.
for (Map.Entry<Server, Map<String, List<Integer>>> serverMapEntry : groupedByServer.entrySet()) {
Server server = serverMapEntry.getKey();
Map<String, List<Integer>> accountFolders = serverMapEntry.getValue();
if (server.equals(localServer)) {
// local server
for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
String acctId = entry.getKey();
List<Integer> folderIds = entry.getValue();
Account targetAcct = prov.get(AccountBy.id, acctId);
if (targetAcct == null) {
ZimbraLog.calendar.warn("Skipping unknown account " + acctId + " during minical search");
continue;
}
Mailbox targetMbox = mboxMgr.getMailboxByAccount(targetAcct);
for (int folderId : folderIds) {
try {
doLocalFolder(octxt, tz, targetMbox, folderId, rangeStart, rangeEnd, busyDates);
} catch (ServiceException e) {
ItemId iid = new ItemId(acctId, folderId);
// Error must mention folder id requested by client.
ItemId reqIid = reverseMap.get(iid);
if (reqIid != null) {
ZimbraLog.calendar.warn("Error accessing calendar folder " + ifmt.formatItemId(reqIid), e);
addError(response, ifmt.formatItemId(reqIid), e.getCode(), e.getMessage());
} else {
ZimbraLog.calendar.warn("Error accessing calendar folder; resolved id=" + ifmt.formatItemId(iid) + " (missing reverse mapping)", e);
addError(response, ifmt.formatItemId(iid), e.getCode(), e.getMessage());
}
}
}
}
} else {
// remote server
// mail service soap requests want to see a target account
String nominalTargetAcctId = null;
List<String> folderList = new ArrayList<String>();
for (Map.Entry<String, List<Integer>> entry : accountFolders.entrySet()) {
String acctId = entry.getKey();
if (nominalTargetAcctId == null)
nominalTargetAcctId = acctId;
ItemIdFormatter ifmtRemote = new ItemIdFormatter(authAcct.getId(), acctId, false);
List<Integer> folderIds = entry.getValue();
for (int folderId : folderIds) {
folderList.add(ifmtRemote.formatItemId(folderId));
}
}
doRemoteFolders(zsc, nominalTargetAcctId, folderList, rangeStart, rangeEnd, busyDates, response, reverseMap, ifmt);
}
}
for (String datestamp : busyDates) {
Element dateElem = response.addElement(MailConstants.E_CAL_MINICAL_DATE);
dateElem.setText(datestamp);
}
return response;
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class GetMiniCal method parseTimeZone.
private static ICalTimeZone parseTimeZone(Element request) throws ServiceException {
Element tzElem = request.getOptionalElement(MailConstants.E_CAL_TZ);
if (tzElem != null) {
String tzid = tzElem.getAttribute(MailConstants.A_ID, null);
if (tzid != null) {
ICalTimeZone knownTZ = WellKnownTimeZones.getTimeZoneById(tzid);
if (knownTZ != null)
return knownTZ;
}
// custom timezone
String stdOffset = tzElem.getAttribute(MailConstants.A_CAL_TZ_STDOFFSET, null);
if (stdOffset == null)
throw ServiceException.INVALID_REQUEST("Unknown TZ: \"" + tzid + "\" and no " + MailConstants.A_CAL_TZ_STDOFFSET + " specified", null);
return CalendarUtils.parseTzElement(tzElem);
} else {
return null;
}
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Invite method newToICalendar.
public ZVCalendar newToICalendar(boolean useOutlookCompatMode, boolean includePrivateData) throws ServiceException {
ZVCalendar vcal = new ZVCalendar();
vcal.addVersionAndProdId();
vcal.addProperty(new ZProperty(ICalTok.METHOD, mMethod.toString()));
// timezones
if (!isAllDayEvent() || useOutlookCompatMode) {
// Don't write any VTIMEZONE for all-day appointments.
for (Iterator<ICalTimeZone> iter = mTzMap.tzIterator(); iter.hasNext(); ) {
ICalTimeZone cur = iter.next();
vcal.addComponent(cur.newToVTimeZone());
}
}
vcal.addComponent(newToVComponent(useOutlookCompatMode, includePrivateData));
return vcal;
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Recurrence method getReferencedTZIDs.
// Get the set of TZIDs referenced in a recurrence. RDATE and EXDATE can use TZID parameter.
public static Set<String> getReferencedTZIDs(IRecurrence recur) {
Set<String> tzids = new HashSet<String>();
// RDATE
for (Iterator iter = recur.addRulesIterator(); iter != null && iter.hasNext(); ) {
IRecurrence cur = (IRecurrence) iter.next();
if (cur.getType() == Recurrence.TYPE_SINGLE_DATES) {
Recurrence.SingleDates sd = (Recurrence.SingleDates) cur;
RdateExdate rdate = sd.getRdateExdate();
ICalTimeZone tz = rdate.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
}
// EXDATE
for (Iterator iter = recur.subRulesIterator(); iter != null && iter.hasNext(); ) {
IRecurrence cur = (IRecurrence) iter.next();
if (cur.getType() == Recurrence.TYPE_SINGLE_DATES) {
Recurrence.SingleDates sd = (Recurrence.SingleDates) cur;
RdateExdate exdate = sd.getRdateExdate();
ICalTimeZone tz = exdate.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
}
ParsedDateTime recurStart = recur.getStartTime();
if (recurStart != null) {
ICalTimeZone tz = recurStart.getTimeZone();
if (tz != null)
tzids.add(tz.getID());
}
return tzids;
}
use of com.zimbra.common.calendar.ICalTimeZone in project zm-mailbox by Zimbra.
the class Util method getAccountTimeZone.
/**
* Returns the time zone for the given account.
*/
public static ICalTimeZone getAccountTimeZone(Account account) {
String tzid = account.getAttr(Provisioning.A_zimbraPrefTimeZoneId);
tzid = TZIDMapper.canonicalize(tzid);
ICalTimeZone timeZone = WellKnownTimeZones.getTimeZoneById(tzid);
if (timeZone == null) {
return ICalTimeZone.getUTC();
}
return timeZone;
}
Aggregations