Example #1
0
 public void parseSearchParams(Element request, String searchQuery) throws ServiceException {
   if (request == null || mSoapContext == null) {
     createSearchParams(searchQuery);
     return;
   }
   setRequest(request);
   // bug 69338
   // SearchParams.parse relies on A_SEARCH_TYPES on the request to determine search type,
   // which will then determine if cursor should be used to narrow db query.
   // If A_SEARCH_TYPES is not set, default type is conversation, cursor is not used to
   // narrow db query for conversations.   We do not require clients to set types
   // on GAL soap APIs.  Set it to "contact" here.
   request.addAttribute(MailConstants.A_SEARCH_TYPES, MailItem.Type.CONTACT.toString());
   mSearchParams = SearchParams.parse(request, mSoapContext, searchQuery);
   mSearchParams.setTypes(EnumSet.of(MailItem.Type.CONTACT));
   setLimit(mSearchParams.getLimit());
 }
Example #2
0
  @Override
  public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Mailbox mbox = getRequestedMailbox(zsc);
    Account account = getRequestedAccount(zsc);
    OperationContext octxt = getOperationContext(zsc, context);

    SearchRequest req = JaxbUtil.elementToJaxb(request);
    if (Objects.firstNonNull(req.getWarmup(), false)) {
      mbox.index.getIndexStore().warmup();
      return zsc.createElement(MailConstants.SEARCH_RESPONSE);
    }

    SearchParams params = SearchParams.parse(req, zsc, account.getPrefMailInitialSearch());
    if (params.getLocale() == null) {
      params.setLocale(mbox.getAccount().getLocale());
    }
    if (params.inDumpster() && params.getTypes().contains(MailItem.Type.CONVERSATION)) {
      throw ServiceException.INVALID_REQUEST("cannot search for conversations in dumpster", null);
    }

    if (LC.calendar_cache_enabled.booleanValue()) {
      List<String> apptFolderIds = getFolderIdListIfSimpleAppointmentsQuery(params, zsc);
      if (apptFolderIds != null) {
        Account authAcct = getAuthenticatedAccount(zsc);
        Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
        runSimpleAppointmentQuery(response, params, octxt, zsc, authAcct, mbox, apptFolderIds);
        return response;
      }
    }

    ZimbraQueryResults results = mbox.index.search(zsc.getResponseProtocol(), octxt, params);
    try {
      // create the XML response Element
      Element response = zsc.createElement(MailConstants.SEARCH_RESPONSE);
      // must use results.getSortBy() because the results might have ignored our sortBy
      // request and used something else...
      response.addAttribute(MailConstants.A_SORTBY, results.getSortBy().toString());
      putHits(zsc, octxt, response, results, params);
      return response;
    } finally {
      Closeables.closeQuietly(results);
    }
  }