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;
}
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());
}
}
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;
}
Aggregations