Search in sources :

Example 26 with Tag

use of com.zimbra.cs.mailbox.Tag in project zm-mailbox by Zimbra.

the class SoapSession method putRefresh.

/** Serializes basic folder/tag structure to a SOAP response header.
     *  <p>
     *  Adds a &lt;refresh> block to the existing &lt;context> element.
     *  This &lt;refresh> block contains the basic folder, tag, and mailbox
     *  size information needed to display and update the web UI's overview
     *  pane.  The &lt;refresh> block is sent when a new session is created.
     *
     *  This API implicitly clears all cached notifications and therefore
     *  should only been used during session creation.
     * @param ctxt  An existing SOAP header <context> element
     * @param zsc   The SOAP request's encapsulated context */
public void putRefresh(Element ctxt, ZimbraSoapContext zsc) throws ServiceException {
    Mailbox mbox = mailbox;
    if (mbox == null) {
        return;
    }
    synchronized (sentChanges) {
        for (QueuedNotifications ntfn : sentChanges) {
            ntfn.clearMailboxChanges();
        }
    }
    Element eRefresh = ctxt.addUniqueElement(ZimbraNamespace.E_REFRESH);
    eRefresh.addAttribute(AccountConstants.E_VERSION, BuildInfo.FULL_VERSION, Element.Disposition.CONTENT);
    OperationContext octxt = DocumentHandler.getOperationContext(zsc, this);
    ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
    // dump current mailbox status (currently just size)
    ToXML.encodeMailbox(eRefresh, octxt, mbox);
    // dump all tags under a single <tags> parent
    List<Tag> tags = mbox.getTagList(octxt);
    if (tags != null && tags.size() > 0) {
        Element eTags = eRefresh.addUniqueElement(ZimbraNamespace.E_TAGS);
        for (Tag tag : tags) {
            if (tag != null && !(tag instanceof Flag)) {
                ToXML.encodeTag(eTags, ifmt, octxt, tag);
            }
        }
    }
    // first, get the user's folder hierarchy
    FolderNode root = mbox.getFolderTree(octxt, null, false);
    OperationContextData.setNeedGranteeName(octxt, false);
    GetFolder.encodeFolderNode(root, eRefresh, ifmt, octxt);
    // The Boolean of the Pair indicates whether the mountpoint is found to be broken
    Map<ItemId, Pair<Boolean, Element>> mountpoints = new HashMap<ItemId, Pair<Boolean, Element>>();
    // for mountpoints pointing to this host, get the serialized folder subhierarchy
    expandLocalMountpoints(octxt, root, eRefresh.getFactory(), mountpoints);
    // for mountpoints pointing to other hosts, get the folder structure from the remote server
    expandRemoteMountpoints(octxt, zsc, mountpoints);
    // graft in subfolder trees from the other user's mailbox, making sure that mountpoints reflect the counts (etc.) of the target folder
    if (!mountpoints.isEmpty()) {
        transferMountpointContents(eRefresh.getOptionalElement(MailConstants.E_FOLDER), octxt, mountpoints);
    }
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) FolderNode(com.zimbra.cs.mailbox.Mailbox.FolderNode) ItemIdFormatter(com.zimbra.cs.service.util.ItemIdFormatter) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Flag(com.zimbra.cs.mailbox.Flag) ItemId(com.zimbra.cs.service.util.ItemId) Mailbox(com.zimbra.cs.mailbox.Mailbox) Tag(com.zimbra.cs.mailbox.Tag) Pair(com.zimbra.common.util.Pair)

Aggregations

Tag (com.zimbra.cs.mailbox.Tag)26 Mailbox (com.zimbra.cs.mailbox.Mailbox)15 Folder (com.zimbra.cs.mailbox.Folder)10 Test (org.junit.Test)9 Element (com.zimbra.common.soap.Element)8 ServiceException (com.zimbra.common.service.ServiceException)7 Account (com.zimbra.cs.account.Account)7 MailItem (com.zimbra.cs.mailbox.MailItem)7 OperationContext (com.zimbra.cs.mailbox.OperationContext)6 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)5 Message (com.zimbra.cs.mailbox.Message)5 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)5 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)4 ItemId (com.zimbra.cs.service.util.ItemId)4 Flag (com.zimbra.cs.mailbox.Flag)3 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)3 ArrayList (java.util.ArrayList)3 ZMailbox (com.zimbra.client.ZMailbox)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 Contact (com.zimbra.cs.mailbox.Contact)2