use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class CalSummaryCache method notifyCommittedChanges.
void notifyCommittedChanges(PendingModifications mods, int changeId) {
if (mods.created != null) {
for (Map.Entry<ModificationKey, MailItem> entry : mods.created.entrySet()) {
MailItem item = entry.getValue();
if (item instanceof CalendarItem) {
int folderId = item.getFolderId();
invalidateItem(item.getMailbox(), folderId, item.getId());
}
}
}
if (mods.modified != null) {
for (Map.Entry<ModificationKey, Change> entry : mods.modified.entrySet()) {
Change change = entry.getValue();
Object whatChanged = change.what;
if (whatChanged instanceof CalendarItem) {
CalendarItem item = (CalendarItem) whatChanged;
Mailbox mbox = item.getMailbox();
int folderId = item.getFolderId();
int itemId = item.getId();
invalidateItem(mbox, folderId, itemId);
// If this is a folder move, invalidate the item from the old folder too.
if ((change.why & Change.FOLDER) != 0) {
String accountId = mbox.getAccountId();
int prevFolderId;
synchronized (mSummaryCache) {
prevFolderId = mSummaryCache.getFolderForItem(accountId, itemId);
}
if (prevFolderId != folderId && prevFolderId != SummaryLRU.FOLDER_NOT_FOUND) {
invalidateItem(mbox, prevFolderId, itemId);
}
}
}
}
}
if (mods.deleted != null) {
String lastAcctId = null;
Mailbox lastMbox = null;
for (Map.Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
MailItem.Type type = (MailItem.Type) entry.getValue().what;
if (type == MailItem.Type.APPOINTMENT || type == MailItem.Type.TASK) {
// We only have item id. Look up the folder id of the item in the cache.
Mailbox mbox = null;
String acctId = entry.getKey().getAccountId();
// just to be safe
if (acctId == null)
continue;
if (acctId.equals(lastAcctId)) {
// Deletion by id list usually happens because of a folder getting emptied.
// It's highly likely the items all belong to the same mailbox, let alone folder.
mbox = lastMbox;
} else {
try {
mbox = MailboxManager.getInstance().getMailboxByAccountId(acctId, FetchMode.DO_NOT_AUTOCREATE);
} catch (ServiceException e) {
ZimbraLog.calendar.error("Error looking up the mailbox of account in delete notification: account=" + acctId, e);
continue;
}
}
if (mbox != null) {
lastAcctId = acctId;
lastMbox = mbox;
int itemId = entry.getKey().getItemId();
String accountId = mbox.getAccountId();
int folderId;
synchronized (mSummaryCache) {
folderId = mSummaryCache.getFolderForItem(accountId, itemId);
}
if (folderId != SummaryLRU.FOLDER_NOT_FOUND) {
invalidateItem(mbox, folderId, itemId);
}
}
}
}
}
if (MemcachedConnector.isConnected()) {
mMemcachedCache.notifyCommittedChanges(mods, changeId);
}
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class FreeBusyQuery method prepareRequests.
private void prepareRequests(ArrayList<FreeBusy> local, RemoteFreeBusyProvider remote, ArrayList<String> external) {
for (String id : mTargets.keySet()) {
Account acct = mTargets.get(id);
try {
if (acct == null || acct.isAccountExternal() || acct.getBooleanAttr(Provisioning.A_zimbraFreebusyLocalMailboxNotActive, false)) {
external.add(id);
continue;
}
int folder = mTargetFolder.get(id);
if (Provisioning.onLocalServer(acct)) {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
OperationContext octxt = null;
if (mCtxt != null && mCtxt.getAuthToken() != null)
octxt = new OperationContext(mCtxt.getAuthToken());
else if (mRequestor != null)
octxt = new OperationContext(mRequestor);
else
octxt = new OperationContext(GuestAccount.ANONYMOUS_ACCT);
Appointment exAppt = null;
if (mExApptUid != null) {
CalendarItem ci = mbox.getCalendarItemByUid(octxt, mExApptUid);
if (ci instanceof Appointment)
exAppt = (Appointment) ci;
}
local.add(mbox.getFreeBusy(octxt, id, mStart, mEnd, folder, exAppt));
} else {
remote.addFreeBusyRequest(mRequestor, acct, id, mStart, mEnd, folder);
}
} catch (ServiceException e) {
ZimbraLog.fb.error("cannot get free/busy for " + id, e);
}
}
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class ModifyInvitePartStat method redo.
@Override
public void redo() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxById(getMailboxId());
CalendarItem calItem = mbox.getCalendarItemById(null, mCalItemId);
RecurId recurId = null;
if (mRecurIdDt != null)
recurId = new RecurId(ParsedDateTime.parse(mRecurIdDt, calItem.getTimeZoneMap()), mRecurIdRange);
mbox.modifyPartStat(getOperationContext(), mCalItemId, recurId, mCnStr, mAddressStr, mCUTypeStr, mRoleStr, mPartStatStr, mRsvp, mSeqNo, mDtStamp);
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class CalendarCollection method getAppointmentsByUids.
public java.util.Collection<DavResource> getAppointmentsByUids(DavContext ctxt, List<String> hrefs) throws ServiceException, DavException {
Map<String, String> uidmap = getUidToHrefMap(hrefs);
Mailbox mbox = getCalendarMailbox(ctxt);
ArrayList<DavResource> appts = new ArrayList<DavResource>();
ctxt.setCollectionPath(getUri());
Map<String, CalendarItem> calItems = mbox.getCalendarItemsByUid(ctxt.getOperationContext(), new ArrayList<String>(uidmap.keySet()));
for (String uid : calItems.keySet()) {
CalendarItem calItem = calItems.get(uid);
if (calItem == null)
appts.add(new DavResource.InvalidResource(uidmap.get(uid), getOwner()));
else
appts.add(new CalendarObject.LocalCalendarObject(ctxt, calItem));
}
return appts;
}
use of com.zimbra.cs.mailbox.CalendarItem in project zm-mailbox by Zimbra.
the class ScheduleOutbox method adjustOrganizer.
/**
* For Vanilla CalDAV access where Apple style delegation has not been enabled, attempts by the delegate
* to use a shared calendar acting as themselves are translated to appear as if acting as a delegate,
* otherwise the experience can be very poor.
* @throws ServiceException
*/
private void adjustOrganizer(DavContext ctxt, ZCalendar.ZVCalendar cal, ZComponent req, DelegationInfo delegationInfo) throws ServiceException {
// BusyCal 2.5.3 seems to post with the wrong organizer even if ical delegation is switched on - even though
// it uses the right ORGANIZER in the calendar entry.
// if (ctxt.useIcalDelegation()) { return; }
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(ctxt.getAuthAccount());
String uid = req.getPropVal(ICalTok.UID, null);
CalendarItem matchingCalendarEntry = mbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
if (matchingCalendarEntry == null) {
List<com.zimbra.cs.mailbox.Mountpoint> sharedCalendars = mbox.getCalendarMountpoints(ctxt.getOperationContext(), SortBy.NONE);
if (sharedCalendars == null) {
// Can't work out anything useful
return;
}
Set<Account> accts = Sets.newHashSet();
for (com.zimbra.cs.mailbox.Mountpoint sharedCalendar : sharedCalendars) {
accts.add(Provisioning.getInstance().get(AccountBy.id, sharedCalendar.getOwnerId()));
}
for (Account acct : accts) {
Mailbox sbox = MailboxManager.getInstance().getMailboxByAccount(acct);
matchingCalendarEntry = sbox.getCalendarItemByUid(ctxt.getOperationContext(), uid);
if (matchingCalendarEntry != null) {
break;
}
}
}
if (matchingCalendarEntry == null) {
return;
}
Invite[] invites = matchingCalendarEntry.getInvites();
if (invites == null) {
return;
}
for (Invite inv : invites) {
ZOrganizer org = inv.getOrganizer();
if (org != null) {
delegationInfo.setOwner(org.getAddress());
if (Strings.isNullOrEmpty(org.getCn())) {
Account ownerAcct = Provisioning.getInstance().get(AccountBy.name, org.getAddress());
if (!Strings.isNullOrEmpty(ownerAcct.getDisplayName())) {
delegationInfo.setOwnerCn(ownerAcct.getDisplayName());
}
} else {
delegationInfo.setOwnerCn(org.getCn());
}
break;
}
}
if (delegationInfo.getOwner() == null) {
return;
}
AccountAddressMatcher acctMatcher = new AccountAddressMatcher(ctxt.getAuthAccount());
boolean originatorIsCalEntryOrganizer = acctMatcher.matches(delegationInfo.getOwnerEmail());
if (originatorIsCalEntryOrganizer) {
return;
}
for (ZComponent component : cal.getComponents()) {
ZProperty organizerProp = component.getProperty(ICalTok.ORGANIZER);
if (organizerProp != null) {
organizerProp.setValue(delegationInfo.getOwner());
ZParameter cn = organizerProp.getParameter(ICalTok.CN);
if (cn == null) {
organizerProp.addParameter(new ZParameter(ICalTok.CN, delegationInfo.getOwnerCn()));
} else {
cn.setValue(delegationInfo.getOwnerCn());
}
ZParameter sentBy = organizerProp.getParameter(ICalTok.SENT_BY);
if (sentBy == null) {
organizerProp.addParameter(new ZParameter(ICalTok.SENT_BY, delegationInfo.getOriginator()));
} else {
sentBy.setValue(delegationInfo.getOriginator());
}
}
}
}
Aggregations