Search in sources :

Example 1 with WaitSetError

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

the class WaitSetRequest method parseAddUpdateAccounts.

/**
     * @param allowedAccountIds NULL means "all allowed" (admin)
     */
static List<WaitSetAccount> parseAddUpdateAccounts(ZimbraSoapContext zsc, Element elt, Set<MailItem.Type> defaultInterest) throws ServiceException {
    List<WaitSetAccount> toRet = new ArrayList<WaitSetAccount>();
    if (elt != null) {
        for (Iterator<Element> iter = elt.elementIterator(MailConstants.E_A); iter.hasNext(); ) {
            Element a = iter.next();
            String id;
            String name = a.getAttribute(MailConstants.A_NAME, null);
            if (name != null) {
                Account acct = Provisioning.getInstance().get(AccountBy.name, name);
                if (acct != null) {
                    id = acct.getId();
                } else {
                    WaitSetError err = new WaitSetError(name, WaitSetError.Type.NO_SUCH_ACCOUNT);
                    continue;
                }
            } else {
                id = a.getAttribute(MailConstants.A_ID);
            }
            WaitSetMgr.checkRightForAdditionalAccount(id, zsc);
            String tokenStr = a.getAttribute(MailConstants.A_TOKEN, null);
            SyncToken token = tokenStr != null ? new SyncToken(tokenStr) : null;
            Set<MailItem.Type> interests = parseInterestStr(a.getAttribute(MailConstants.A_TYPES, null), defaultInterest);
            toRet.add(new WaitSetAccount(id, token, interests));
        }
    }
    return toRet;
}
Also used : WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) Account(com.zimbra.cs.account.Account) SyncToken(com.zimbra.cs.service.util.SyncToken) WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) WaitSetError(com.zimbra.cs.session.WaitSetError)

Example 2 with WaitSetError

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

the class WaitSetRequest method encodeErrors.

public static final void encodeErrors(Element parent, List<WaitSetError> errors) {
    for (WaitSetError error : errors) {
        Element errorElt = parent.addElement(MailConstants.E_ERROR);
        errorElt.addAttribute(MailConstants.A_ID, error.accountId);
        errorElt.addAttribute(MailConstants.A_TYPE, error.error.name());
    }
}
Also used : Element(com.zimbra.common.soap.Element) WaitSetError(com.zimbra.cs.session.WaitSetError)

Example 3 with WaitSetError

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

the class CreateWaitSet method staticHandle.

public static Element staticHandle(DocumentHandler handler, Element request, Map<String, Object> context, Element response) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    String defInterestStr = request.getAttribute(MailConstants.A_DEFTYPES);
    Set<MailItem.Type> defaultInterests = WaitSetRequest.parseInterestStr(defInterestStr, EnumSet.noneOf(MailItem.Type.class));
    boolean adminAllowed = zsc.getAuthToken().isAdmin();
    boolean allAccts = request.getAttributeBool(MailConstants.A_ALL_ACCOUNTS, false);
    if (allAccts) {
        WaitSetMgr.checkRightForAllAccounts(zsc);
    }
    List<WaitSetAccount> add = WaitSetRequest.parseAddUpdateAccounts(zsc, request.getOptionalElement(MailConstants.E_WAITSET_ADD), defaultInterests);
    // workaround for 27480: load the mailboxes NOW, before we grab the waitset lock
    List<Mailbox> referencedMailboxes = new ArrayList<Mailbox>();
    for (WaitSetAccount acct : add) {
        try {
            MailboxManager.FetchMode fetchMode = MailboxManager.FetchMode.AUTOCREATE;
            Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(acct.getAccountId(), fetchMode);
            referencedMailboxes.add(mbox);
        } catch (ServiceException e) {
            ZimbraLog.session.debug("Caught exception preloading mailbox for waitset", e);
        }
    }
    Pair<String, List<WaitSetError>> result = WaitSetMgr.create(zsc.getRequestedAccountId(), adminAllowed, defaultInterests, allAccts, add);
    String wsId = result.getFirst();
    List<WaitSetError> errors = result.getSecond();
    response.addAttribute(MailConstants.A_WAITSET_ID, wsId);
    response.addAttribute(MailConstants.A_DEFTYPES, WaitSetRequest.interestToStr(defaultInterests));
    response.addAttribute(MailConstants.A_SEQ, 0);
    WaitSetRequest.encodeErrors(response, errors);
    return response;
}
Also used : WaitSetAccount(com.zimbra.cs.session.WaitSetAccount) ArrayList(java.util.ArrayList) WaitSetError(com.zimbra.cs.session.WaitSetError) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) Mailbox(com.zimbra.cs.mailbox.Mailbox) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

WaitSetError (com.zimbra.cs.session.WaitSetError)3 Element (com.zimbra.common.soap.Element)2 WaitSetAccount (com.zimbra.cs.session.WaitSetAccount)2 ArrayList (java.util.ArrayList)2 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 MailboxManager (com.zimbra.cs.mailbox.MailboxManager)1 SyncToken (com.zimbra.cs.service.util.SyncToken)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 List (java.util.List)1