Search in sources :

Example 1 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ZMailbox method internalSearch.

// ------------------------
private synchronized ZSearchResult internalSearch(String convId, ZSearchParams params, boolean nest) throws ServiceException {
    QName name;
    if (convId != null) {
        name = MailConstants.SEARCH_CONV_REQUEST;
    } else if (params.getTypes().equals(ZSearchParams.TYPE_VOICE_MAIL) || params.getTypes().equals(ZSearchParams.TYPE_CALL)) {
        name = VoiceConstants.SEARCH_VOICE_REQUEST;
    } else if (params.getTypes().equals(ZSearchParams.TYPE_GAL)) {
        name = AccountConstants.SEARCH_GAL_REQUEST;
    } else {
        name = MailConstants.SEARCH_REQUEST;
    }
    Element req = newRequestElement(name);
    if (params.getTypes().equals(ZSearchParams.TYPE_GAL)) {
        req.addAttribute(AccountConstants.A_TYPE, GalEntryType.account.name());
        req.addElement(AccountConstants.E_NAME).setText(params.getQuery());
    //req.addAttribute(MailConstants.A_SORTBY, SearchSortBy.nameAsc.name());
    }
    req.addAttribute(MailConstants.A_CONV_ID, convId);
    if (nest) {
        req.addAttribute(MailConstants.A_NEST_MESSAGES, true);
    }
    if (params.getLimit() != 0) {
        req.addAttribute(MailConstants.A_QUERY_LIMIT, params.getLimit());
    }
    if (params.getOffset() != 0) {
        req.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
    }
    if (params.getSortBy() != null) {
        req.addAttribute(MailConstants.A_SORTBY, params.getSortBy().name());
    }
    if (params.getTypes() != null) {
        req.addAttribute(MailConstants.A_SEARCH_TYPES, params.getTypes());
    }
    if (params.getFetch() != null && params.getFetch() != Fetch.none) {
        // use "1" for "first" for backward compat until DF is updated
        req.addAttribute(MailConstants.A_FETCH, params.getFetch() == Fetch.first ? "1" : params.getFetch().name());
    }
    if (params.getCalExpandInstStart() != 0) {
        req.addAttribute(MailConstants.A_CAL_EXPAND_INST_START, params.getCalExpandInstStart());
    }
    if (params.getCalExpandInstEnd() != 0) {
        req.addAttribute(MailConstants.A_CAL_EXPAND_INST_END, params.getCalExpandInstEnd());
    }
    if (params.isPreferHtml()) {
        req.addAttribute(MailConstants.A_WANT_HTML, params.isPreferHtml());
    }
    if (params.isMarkAsRead()) {
        req.addAttribute(MailConstants.A_MARK_READ, params.isMarkAsRead());
    }
    if (params.isRecipientMode()) {
        req.addAttribute(MailConstants.A_RECIPIENTS, params.isRecipientMode());
    }
    if (params.getField() != null) {
        req.addAttribute(MailConstants.A_FIELD, params.getField());
    }
    if (params.getInDumpster()) {
        req.addAttribute(MailConstants.A_IN_DUMPSTER, true);
    }
    req.addAttribute(MailConstants.E_QUERY, params.getQuery(), Element.Disposition.CONTENT);
    if (params.getCursor() != null) {
        Cursor cursor = params.getCursor();
        Element cursorEl = req.addElement(MailConstants.E_CURSOR);
        if (cursor.getPreviousId() != null) {
            cursorEl.addAttribute(MailConstants.A_ID, cursor.getPreviousId());
        }
        if (cursor.getPreviousSortValue() != null) {
            cursorEl.addAttribute(MailConstants.A_SORTVAL, cursor.getPreviousSortValue());
        }
    }
    if (params.getTypes().equals(ZSearchParams.TYPE_VOICE_MAIL) || params.getTypes().equals(ZSearchParams.TYPE_CALL)) {
        getAllPhoneAccounts();
        setVoiceStorePrincipal(req);
    }
    Element resp = invoke(req);
    if (params.getTypes().equals(ZSearchParams.TYPE_GAL)) {
        try {
            resp.getAttribute(MailConstants.A_SORTBY);
        } catch (Exception e) {
            resp.addAttribute(MailConstants.A_SORTBY, params.getSortBy().name());
        }
        try {
            resp.getAttribute(MailConstants.A_QUERY_OFFSET);
        } catch (Exception e) {
            resp.addAttribute(MailConstants.A_QUERY_OFFSET, params.getOffset());
        }
    }
    return new ZSearchResult(resp, nest, params.getTimeZone() != null ? params.getTimeZone() : getPrefs().getTimeZone());
}
Also used : QName(org.dom4j.QName) JSONElement(com.zimbra.common.soap.Element.JSONElement) Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) Cursor(com.zimbra.client.ZSearchParams.Cursor) JSONException(org.json.JSONException) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) ZClientException(com.zimbra.common.zclient.ZClientException) URISyntaxException(java.net.URISyntaxException) RemoteServiceException(com.zimbra.common.service.RemoteServiceException)

Example 2 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ZSoapProvisioning method getDomainInfo.

public ZDomain getDomainInfo(DomainBy keyType, String key) throws ServiceException {
    DomainSelector domSel = new DomainSelector(toJaxb(keyType), key);
    try {
        GetDomainInfoResponse resp = invokeJaxb(new GetDomainInfoRequest(domSel, null));
        DomainInfo domainInfo = resp.getDomain();
        return domainInfo == null ? null : new ZDomain(domainInfo);
    } catch (ServiceException e) {
        if (e.getCode().equals(Constants.ERROR_CODE_NO_SUCH_DOMAIN))
            return null;
        else
            throw e;
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) DomainSelector(com.zimbra.soap.admin.type.DomainSelector) GetDomainInfoRequest(com.zimbra.soap.admin.message.GetDomainInfoRequest) DomainInfo(com.zimbra.soap.admin.type.DomainInfo) GetDomainInfoResponse(com.zimbra.soap.admin.message.GetDomainInfoResponse)

Example 3 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ZCreateAppointmentEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        return zjo;
    } catch (ServiceException se) {
        throw new JSONException(se);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Example 4 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class ZModifyAppointmentEvent method toZJSONObject.

public ZJSONObject toZJSONObject() throws JSONException {
    try {
        ZJSONObject zjo = new ZJSONObject();
        zjo.put("id", getId());
        return zjo;
    } catch (ServiceException e) {
        throw new JSONException(e);
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) ZJSONObject(com.zimbra.client.ZJSONObject) ToZJSONObject(com.zimbra.client.ToZJSONObject) JSONException(org.json.JSONException)

Example 5 with ServiceException

use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.

the class Soap12Protocol method soapFault.

/** 
     * Given a ServiceException, wrap it in a soap fault return the 
     * soap fault document.
     */
public Element soapFault(ServiceException e) {
    String reason = e.getMessage();
    if (reason == null)
        reason = e.toString();
    QName code = e.isReceiversFault() ? RECEIVER_CODE : SENDER_CODE;
    Element eFault = mFactory.createElement(mFaultQName);
    Element eCode = eFault.addUniqueElement(CODE);
    // FIXME: should really be a qualified "attribute"
    eCode.addUniqueElement(VALUE).setText(code.getQualifiedName());
    Element eReason = eFault.addUniqueElement(REASON);
    // FIXME: should really be a qualified "attribute"
    eReason.addUniqueElement(TEXT).setText(reason);
    Element eDetail = eFault.addUniqueElement(DETAIL);
    Element error = eDetail.addUniqueElement(ZimbraNamespace.E_ERROR);
    // FIXME: should really be a qualified "attribute"
    error.addUniqueElement(ZimbraNamespace.E_CODE).setText(e.getCode());
    if (LC.soap_fault_include_stack_trace.booleanValue())
        error.addUniqueElement(ZimbraNamespace.E_TRACE).setText(ExceptionToString.ToString(e));
    else
        error.addUniqueElement(ZimbraNamespace.E_TRACE).setText(e.getThreadName());
    for (ServiceException.Argument arg : e.getArgs()) {
        if (arg.externalVisible()) {
            Element val = error.addElement(ZimbraNamespace.E_ARGUMENT);
            val.addAttribute(ZimbraNamespace.A_ARG_NAME, arg.name);
            val.addAttribute(ZimbraNamespace.A_ARG_TYPE, arg.type.toString());
            val.setText(arg.value);
        }
    }
    return eFault;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) QName(org.dom4j.QName) ExceptionToString(com.zimbra.common.util.ExceptionToString)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)772 AccountServiceException (com.zimbra.cs.account.AccountServiceException)220 Account (com.zimbra.cs.account.Account)193 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)149 IOException (java.io.IOException)127 Mailbox (com.zimbra.cs.mailbox.Mailbox)122 ArrayList (java.util.ArrayList)107 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)100 Element (com.zimbra.common.soap.Element)97 HashMap (java.util.HashMap)93 Test (org.junit.Test)89 Provisioning (com.zimbra.cs.account.Provisioning)86 Domain (com.zimbra.cs.account.Domain)60 Folder (com.zimbra.cs.mailbox.Folder)54 Server (com.zimbra.cs.account.Server)53 ItemId (com.zimbra.cs.service.util.ItemId)52 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)51 ZMailbox (com.zimbra.client.ZMailbox)50 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)46 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)44