Search in sources :

Example 16 with ModificationKey

use of com.zimbra.cs.session.PendingModifications.ModificationKey in project zm-mailbox by Zimbra.

the class DataSourceFolderListener method notify.

@Override
public void notify(ChangeNotification notification) {
    if (notification.mods.deleted != null) {
        for (Map.Entry<ModificationKey, Change> entry : notification.mods.deleted.entrySet()) {
            MailItem.Type type = (MailItem.Type) entry.getValue().what;
            if (type == MailItem.Type.FOLDER) {
                Folder oldFolder = (Folder) entry.getValue().preModifyObj;
                if (oldFolder == null) {
                    ZimbraLog.datasource.warn("Cannot determine the old folder name for %s.", entry.getKey());
                    continue;
                }
                try {
                    ZimbraLog.datasource.info("Deleting datasources that reference %s.", oldFolder.getPath());
                    Account account = oldFolder.getAccount();
                    List<DataSource> datasources = account.getAllDataSources();
                    for (DataSource datasource : datasources) {
                        if (datasource.getFolderId() == oldFolder.getId()) {
                            ZimbraLog.datasource.debug("Deleting datasource %s.", datasource.getName());
                            account.deleteDataSource(datasource.getId());
                        }
                    }
                } catch (ServiceException e) {
                    ZimbraLog.datasource.warn("Could not delete datasources for folder.", oldFolder.getPath());
                }
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) Folder(com.zimbra.cs.mailbox.Folder) Map(java.util.Map) DataSource(com.zimbra.cs.account.DataSource)

Example 17 with ModificationKey

use of com.zimbra.cs.session.PendingModifications.ModificationKey in project zm-mailbox by Zimbra.

the class CtagInfoCache method notifyCommittedChanges.

void notifyCommittedChanges(PendingLocalModifications mods, int changeId) {
    int inboxFolder = Mailbox.ID_FOLDER_INBOX;
    Set<CalendarKey> keysToInvalidate = new HashSet<CalendarKey>();
    if (mods.created != null) {
        for (Map.Entry<ModificationKey, BaseItemInfo> entry : mods.created.entrySet()) {
            BaseItemInfo item = entry.getValue();
            if (item instanceof Message) {
                Message msg = (Message) item;
                if (msg.hasCalendarItemInfos() && msg.getFolderId() == inboxFolder) {
                    CalendarKey key = new CalendarKey(msg.getMailbox().getAccountId(), inboxFolder);
                    keysToInvalidate.add(key);
                }
            }
        }
    }
    if (mods.modified != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.modified.entrySet()) {
            Change change = entry.getValue();
            Object whatChanged = change.what;
            if (whatChanged instanceof Folder) {
                Folder folder = (Folder) whatChanged;
                MailItem.Type viewType = folder.getDefaultView();
                if (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK) {
                    CalendarKey key = new CalendarKey(folder.getMailbox().getAccountId(), folder.getId());
                    keysToInvalidate.add(key);
                }
            } else if (whatChanged instanceof Message) {
                Message msg = (Message) whatChanged;
                if (msg.hasCalendarItemInfos()) {
                    if (msg.getFolderId() == inboxFolder || (change.why & Change.FOLDER) != 0) {
                        // If message was moved, we don't know which folder it was moved from.
                        // Just invalidate the Inbox because that's the only message folder we care
                        // about in calendaring.
                        CalendarKey key = new CalendarKey(msg.getMailbox().getAccountId(), inboxFolder);
                        keysToInvalidate.add(key);
                    }
                }
            }
        }
    }
    if (mods.deleted != null) {
        for (Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
            Type type = (Type) entry.getValue().what;
            if (type == MailItem.Type.FOLDER) {
                // We only have item id.  Assume it's a folder id and issue a delete.
                String acctId = entry.getKey().getAccountId();
                if (acctId == null)
                    // just to be safe
                    continue;
                CalendarKey key = new CalendarKey(acctId, entry.getKey().getItemId());
                keysToInvalidate.add(key);
            }
        // Let's not worry about hard deletes of invite/reply emails.  It has no practical benefit.
        }
    }
    try {
        mMemcachedLookup.removeMulti(keysToInvalidate);
    } catch (ServiceException e) {
        ZimbraLog.calendar.warn("Unable to notify ctag info cache.  Some cached data may become stale.", e);
    }
}
Also used : BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) Message(com.zimbra.cs.mailbox.Message) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) Type(com.zimbra.cs.mailbox.MailItem.Type) MailItem(com.zimbra.cs.mailbox.MailItem) Type(com.zimbra.cs.mailbox.MailItem.Type) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) MemcachedMap(com.zimbra.common.util.memcached.MemcachedMap) HashSet(java.util.HashSet)

Example 18 with ModificationKey

use of com.zimbra.cs.session.PendingModifications.ModificationKey in project zm-mailbox by Zimbra.

the class CalListCache method notifyCommittedChanges.

void notifyCommittedChanges(PendingLocalModifications mods, int changeId) {
    ChangeMap changeMap = new ChangeMap(1);
    if (mods.created != null) {
        for (Map.Entry<ModificationKey, BaseItemInfo> entry : mods.created.entrySet()) {
            BaseItemInfo item = entry.getValue();
            if (item instanceof Folder) {
                Folder folder = (Folder) item;
                MailItem.Type viewType = folder.getDefaultView();
                if (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK) {
                    ChangedFolders changedFolders = changeMap.getAccount(entry.getKey().getAccountId());
                    changedFolders.created.add(folder.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 Folder) {
                Folder folder = (Folder) whatChanged;
                MailItem.Type viewType = folder.getDefaultView();
                if (viewType == MailItem.Type.APPOINTMENT || viewType == MailItem.Type.TASK) {
                    ChangedFolders changedFolders = changeMap.getAccount(entry.getKey().getAccountId());
                    int folderId = folder.getId();
                    if ((change.why & Change.FOLDER) != 0) {
                        // moving the calendar folder to another parent folder
                        int parentFolder = folder.getFolderId();
                        changedFolders.created.add(folderId);
                        if (parentFolder == Mailbox.ID_FOLDER_TRASH) {
                            changedFolders.deleted.add(folderId);
                        } else {
                            changedFolders.created.add(folderId);
                        }
                    } else {
                        // not a folder move, but something else changed, either calendar's metadata
                        // or a child item (appointment/task)
                        changedFolders.modified.add(folderId);
                    }
                }
            } else if (whatChanged instanceof Message) {
                Message msg = (Message) whatChanged;
                if (msg.hasCalendarItemInfos()) {
                    if (msg.getFolderId() == Mailbox.ID_FOLDER_INBOX || (change.why & Change.FOLDER) != 0) {
                        // If message was moved, we don't know which folder it was moved from.
                        // Just invalidate the Inbox because that's the only message folder we care
                        // about in calendaring.
                        ChangedFolders changedFolders = changeMap.getAccount(entry.getKey().getAccountId());
                        changedFolders.modified.add(Mailbox.ID_FOLDER_INBOX);
                    }
                }
            }
        }
    }
    if (mods.deleted != null) {
        for (Map.Entry<ModificationKey, Change> entry : mods.deleted.entrySet()) {
            MailItem.Type type = (MailItem.Type) entry.getValue().what;
            if (type == MailItem.Type.FOLDER) {
                // We only have item id.  Let's just assume it's a calendar folder id and check
                // against the cached list.
                ChangedFolders changedFolders = changeMap.getAccount(entry.getKey().getAccountId());
                changedFolders.deleted.add(entry.getKey().getItemId());
            }
        // Let's not worry about hard deletes of invite/reply emails.  It has no practical benefit.
        }
    }
    try {
        for (Map.Entry<String, ChangedFolders> entry : changeMap.entrySet()) {
            ChangedFolders changedFolders = entry.getValue();
            if (changedFolders.isEmpty())
                continue;
            String accountId = entry.getKey();
            AccountKey key = new AccountKey(accountId);
            CalList list = mMemcachedLookup.get(key);
            if (list != null) {
                boolean updated = false;
                CalList newList = new CalList(list);
                for (Integer folderId : changedFolders.created) {
                    if (!list.contains(folderId)) {
                        updated = true;
                        newList.add(folderId);
                    }
                }
                for (Integer folderId : changedFolders.modified) {
                    if (list.contains(folderId))
                        updated = true;
                }
                for (Integer folderId : changedFolders.deleted) {
                    if (list.contains(folderId)) {
                        updated = true;
                        newList.remove(folderId);
                    }
                }
                // There was a change.  Increment the version and put back to cache.
                if (updated) {
                    newList.incrementSeq();
                    mMemcachedLookup.put(key, newList);
                }
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.calendar.warn("Unable to notify calendar list cache.  Some cached data may become stale.", e);
    }
}
Also used : BaseItemInfo(com.zimbra.common.mailbox.BaseItemInfo) Message(com.zimbra.cs.mailbox.Message) ModificationKey(com.zimbra.cs.session.PendingModifications.ModificationKey) Change(com.zimbra.cs.session.PendingModifications.Change) Folder(com.zimbra.cs.mailbox.Folder) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) Map(java.util.Map) MemcachedMap(com.zimbra.common.util.memcached.MemcachedMap)

Aggregations

ModificationKey (com.zimbra.cs.session.PendingModifications.ModificationKey)18 Change (com.zimbra.cs.session.PendingModifications.Change)17 MailItem (com.zimbra.cs.mailbox.MailItem)15 Map (java.util.Map)15 ServiceException (com.zimbra.common.service.ServiceException)13 Folder (com.zimbra.cs.mailbox.Folder)10 HashMap (java.util.HashMap)7 BaseItemInfo (com.zimbra.common.mailbox.BaseItemInfo)6 MemcachedMap (com.zimbra.common.util.memcached.MemcachedMap)6 HashSet (java.util.HashSet)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 Message (com.zimbra.cs.mailbox.Message)4 Account (com.zimbra.cs.account.Account)3 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)3 ZFolder (com.zimbra.client.ZFolder)2 BigByteArrayMemcachedMap (com.zimbra.common.util.memcached.BigByteArrayMemcachedMap)2 Type (com.zimbra.cs.mailbox.MailItem.Type)2 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)2 PendingModifications (com.zimbra.cs.session.PendingModifications)2 IOException (java.io.IOException)2