use of com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification in project zm-mailbox by Zimbra.
the class PendingRemoteModifications method fromSOAP.
public static PendingRemoteModifications fromSOAP(PendingFolderModifications mods, Integer folderId, String acctId) {
PendingRemoteModifications prms = new PendingRemoteModifications();
for (CreateItemNotification createSpec : mods.getCreated()) {
prms.recordCreated(ModificationItem.itemUpdate(createSpec.getMessageInfo(), folderId, acctId));
}
for (ModifyItemNotification modifyItem : mods.getModifiedMsgs()) {
int change = modifyItem.getChangeBitmask();
BaseItemInfo itemUpdate = ModificationItem.itemUpdate(modifyItem.getMessageInfo(), folderId, acctId);
prms.recordModified(itemUpdate, change);
}
for (ModifyTagNotification modifyTag : mods.getModifiedTags()) {
int change = modifyTag.getChangeBitmask();
int tagId = modifyTag.getId();
String tagName = modifyTag.getName();
ZimbraTag tagRename = ModificationItem.tagRename(tagId, tagName);
prms.recordModified(tagRename, acctId, change);
}
for (RenameFolderNotification renamedFolder : mods.getRenamedFolders()) {
int change = renamedFolder.getChangeBitmask();
int renamedFolderId = renamedFolder.getFolderId();
String newPath = renamedFolder.getPath();
ModificationItem folderRename = ModificationItem.folderRename(renamedFolderId, newPath, acctId);
prms.recordModified(folderRename, change);
}
for (DeleteItemNotification delSpec : mods.getDeleted()) {
int id = delSpec.getId();
MailItem.Type type = MailItem.Type.of(delSpec.getType());
prms.recordDeleted(type, acctId, id);
}
return prms;
}
use of com.zimbra.soap.mail.type.ModifyNotification.ModifyTagNotification in project zm-mailbox by Zimbra.
the class PendingModifications method encodeIMAPFolderModifications.
@SuppressWarnings("rawtypes")
public static Map<Integer, PendingFolderModifications> encodeIMAPFolderModifications(PendingModifications accountMods, Set<Integer> folderInterests) throws ServiceException {
HashMap<Integer, PendingFolderModifications> folderMap = Maps.newHashMap();
if (accountMods != null && accountMods.created != null) {
for (Object mod : accountMods.created.values()) {
if (mod instanceof BaseItemInfo) {
Integer folderId = ((BaseItemInfo) mod).getFolderIdInMailbox();
if (folderInterests != null && !folderInterests.contains(folderId)) {
continue;
}
JaxbUtil.getFolderMods(folderId, folderMap).addCreatedItem(JaxbUtil.getCreatedItemSOAP((BaseItemInfo) mod));
}
}
}
if (accountMods != null && accountMods.modified != null) {
// aggregate tag changes so they are sent to each folder we are interested in
List<ModifyTagNotification> tagMods = new ArrayList<ModifyTagNotification>();
List<DeleteItemNotification> tagDeletes = new ArrayList<DeleteItemNotification>();
for (Object maybeTagChange : accountMods.modified.values()) {
if (maybeTagChange instanceof Change) {
Object maybeTag = ((Change) maybeTagChange).what;
if (maybeTag != null && maybeTag instanceof Tag) {
Tag tag = (Tag) maybeTag;
tagMods.add(new ModifyTagNotification(tag.getIdInMailbox(), tag.getName(), ((Change) maybeTagChange).why));
}
}
}
if (accountMods != null && accountMods.deleted != null) {
@SuppressWarnings("unchecked") Map<ModificationKey, Change> deletedMap = accountMods.deleted;
for (Map.Entry<ModificationKey, Change> entry : deletedMap.entrySet()) {
ModificationKey key = entry.getKey();
Change mod = entry.getValue();
if (mod instanceof Change) {
Object what = mod.what;
if (what != null && what instanceof MailItem.Type) {
if (what == MailItem.Type.TAG) {
// aggregate tag deletions so they are sent to each folder we are interested in
tagDeletes.add(JaxbUtil.getDeletedItemSOAP(key.getItemId(), what.toString()));
} else {
Integer folderId;
if (what == MailItem.Type.FOLDER) {
folderId = key.getItemId();
} else {
folderId = mod.getFolderId();
}
if (folderInterests != null && !folderInterests.contains(folderId)) {
continue;
}
JaxbUtil.getFolderMods(folderId, folderMap).addDeletedItem(JaxbUtil.getDeletedItemSOAP(key.getItemId(), what.toString()));
}
}
}
}
}
for (Object mod : accountMods.modified.values()) {
if (mod instanceof Change) {
Object what = ((Change) mod).what;
if (what != null && what instanceof BaseItemInfo) {
BaseItemInfo itemInfo = (BaseItemInfo) what;
Integer folderId = itemInfo.getFolderIdInMailbox();
if (itemInfo instanceof Folder) {
Integer itemId = itemInfo.getIdInMailbox();
if (folderInterests != null && !folderInterests.contains(folderId) && !folderInterests.contains(itemId)) {
continue;
}
if (!tagMods.isEmpty()) {
PendingFolderModifications folderMods = JaxbUtil.getFolderMods(itemId, folderMap);
for (ModifyTagNotification modTag : tagMods) {
folderMods.addModifiedTag(modTag);
}
} else if (!tagDeletes.isEmpty()) {
PendingFolderModifications folderMods = JaxbUtil.getFolderMods(itemId, folderMap);
for (DeleteItemNotification tagDelete : tagDeletes) {
folderMods.addDeletedItem(tagDelete);
}
}
} else if (!(itemInfo instanceof Tag)) {
if (folderInterests != null && !folderInterests.contains(folderId)) {
continue;
}
JaxbUtil.getFolderMods(folderId, folderMap).addModifiedMsg(JaxbUtil.getModifiedItemSOAP(itemInfo, ((Change) mod).why));
}
}
}
}
}
return folderMap;
}
Aggregations