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