Search in sources :

Example 1 with ZMiniCalError

use of com.zimbra.client.ZMailbox.ZMiniCalError in project zm-mailbox by Zimbra.

the class GetMiniCal method doRemoteFolders.

private static void doRemoteFolders(ZimbraSoapContext zsc, String remoteAccountId, List<String> remoteFolders, long rangeStart, long rangeEnd, Set<String> busyDates, Element response, Map<ItemId, ItemId> reverseIidMap, ItemIdFormatter ifmt) {
    try {
        Account target = Provisioning.getInstance().get(Key.AccountBy.id, remoteAccountId);
        if (target == null)
            throw AccountServiceException.NO_SUCH_ACCOUNT(remoteAccountId);
        AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
        ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(target));
        zoptions.setTargetAccount(remoteAccountId);
        zoptions.setTargetAccountBy(AccountBy.id);
        zoptions.setNoSession(true);
        ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
        zmbx.setName(target.getName());
        /* need this when logging in using another user's auth */
        String[] remoteIds = new String[remoteFolders.size()];
        for (int i = 0; i < remoteIds.length; i++) remoteIds[i] = remoteFolders.get(i).toString();
        ZGetMiniCalResult result = zmbx.getMiniCal(rangeStart, rangeEnd, remoteIds);
        Set<String> dates = result.getDates();
        if (dates != null) {
            for (String datestamp : dates) {
                busyDates.add(datestamp);
            }
        }
        List<ZMiniCalError> errors = result.getErrors();
        if (errors != null) {
            for (ZMiniCalError error : errors) {
                try {
                    ItemId iid = new ItemId(error.getFolderId(), zsc);
                    // Error must mention folder id requested by client.
                    ItemId reqIid = reverseIidMap.get(iid);
                    String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
                    addError(response, fid, error.getErrCode(), error.getErrMsg());
                } catch (ServiceException e) {
                }
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.calendar.warn("Error making remote GetMiniCalRequest", e);
        // Mark all remote folders with the same error.
        for (String remoteFid : remoteFolders) {
            try {
                ItemId iid = new ItemId(remoteFid, zsc);
                // Error must mention folder id requested by client.
                ItemId reqIid = reverseIidMap.get(iid);
                String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
                addError(response, fid, e.getCode(), e.getMessage());
            } catch (ServiceException e2) {
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZGetMiniCalResult(com.zimbra.client.ZMailbox.ZGetMiniCalResult) ItemId(com.zimbra.cs.service.util.ItemId) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZMiniCalError(com.zimbra.client.ZMailbox.ZMiniCalError) ZMailbox(com.zimbra.client.ZMailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken)

Aggregations

ZMailbox (com.zimbra.client.ZMailbox)1 ZGetMiniCalResult (com.zimbra.client.ZMailbox.ZGetMiniCalResult)1 ZMiniCalError (com.zimbra.client.ZMailbox.ZMiniCalError)1 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)1 ItemId (com.zimbra.cs.service.util.ItemId)1