Search in sources :

Example 1 with CursorInfo

use of com.zimbra.soap.type.CursorInfo in project zm-mailbox by Zimbra.

the class SearchParams method parse.

/**
 * Parse the search parameters from a {@code <SearchRequest>} or similar element.
 *
 * @param request {@code <SearchRequest>} itself, or similar element ({@code <SearchConvRequest>}, etc)
 * @param requestedAccount account who's mailbox we should search in
 * @param zsc SoapContext of the request
 */
public static SearchParams parse(SearchParameters soapParams, ZimbraSoapContext zsc, String defaultQueryStr) throws ServiceException {
    SearchParams params = new SearchParams();
    params.requestContext = zsc;
    params.setHopCount(zsc.getHopCount());
    params.setCalItemExpandStart(MoreObjects.firstNonNull(soapParams.getCalItemExpandStart(), -1L));
    params.setCalItemExpandEnd(MoreObjects.firstNonNull(soapParams.getCalItemExpandEnd(), -1L));
    String query = soapParams.getQuery() == null ? defaultQueryStr : soapParams.getQuery();
    if (query == null) {
        throw ServiceException.INVALID_REQUEST("no query submitted and no default query found", null);
    }
    params.setQueryString(query);
    params.setInDumpster(MoreObjects.firstNonNull(soapParams.getInDumpster(), false));
    params.setQuick(MoreObjects.firstNonNull(soapParams.getQuick(), false));
    String types = soapParams.getSearchTypes() == null ? soapParams.getGroupBy() : soapParams.getSearchTypes();
    if (Strings.isNullOrEmpty(types)) {
        params.setTypes(EnumSet.of(params.isQuick() ? MailItem.Type.MESSAGE : MailItem.Type.CONVERSATION));
    } else {
        params.setTypes(types);
    }
    params.setSortBy(soapParams.getSortBy());
    if (soapParams.getSortBy() != null && query.toLowerCase().contains("is:unread") && isSortByReadFlag(SortBy.of(soapParams.getSortBy()))) {
        params.setSortBy(SortBy.DATE_DESC);
    } else {
        params.setSortBy(soapParams.getSortBy());
    }
    params.setIncludeTagDeleted(MoreObjects.firstNonNull(soapParams.getIncludeTagDeleted(), false));
    params.setIncludeTagMuted(MoreObjects.firstNonNull(soapParams.getIncludeTagMuted(), true));
    String allowableTasks = soapParams.getAllowableTaskStatus();
    if (allowableTasks != null) {
        params.allowableTaskStatuses = new HashSet<TaskHit.Status>();
        for (String task : Splitter.on(',').split(allowableTasks)) {
            try {
                TaskHit.Status status = TaskHit.Status.valueOf(task.toUpperCase());
                params.allowableTaskStatuses.add(status);
            } catch (IllegalArgumentException e) {
                ZimbraLog.index.debug("Skipping unknown task completion status: %s", task);
            }
        }
    }
    params.setInlineRule(ExpandResults.valueOf(soapParams.getFetch(), zsc));
    if (params.getInlineRule() != ExpandResults.NONE) {
        params.setMarkRead(MoreObjects.firstNonNull(soapParams.getMarkRead(), false));
        params.setMaxInlinedLength(MoreObjects.firstNonNull(soapParams.getMaxInlinedLength(), -1));
        params.setWantHtml(MoreObjects.firstNonNull(soapParams.getWantHtml(), false));
        params.setWantExpandGroupInfo(MoreObjects.firstNonNull(soapParams.getNeedCanExpand(), false));
        params.setNeuterImages(MoreObjects.firstNonNull(soapParams.getNeuterImages(), true));
        for (AttributeName hdr : soapParams.getHeaders()) {
            params.addInlinedHeader(hdr.getName());
        }
    }
    params.setWantRecipients(soapParams.getWantRecipients());
    CalTZInfoInterface calTZ = soapParams.getCalTz();
    if (calTZ != null) {
        params.setTimeZone(parseTimeZonePart(calTZ));
    }
    String locale = soapParams.getLocale();
    if (locale != null) {
        params.setLocale(parseLocale(locale));
    }
    params.setPrefetch(MoreObjects.firstNonNull(soapParams.getPrefetch(), true));
    String resultMode = soapParams.getResultMode();
    if (!Strings.isNullOrEmpty(resultMode)) {
        try {
            params.setFetchMode(Fetch.valueOf(resultMode.toUpperCase()));
        } catch (IllegalArgumentException e) {
            throw ServiceException.INVALID_REQUEST(String.format("Invalid %s \"%s\"", MailConstants.A_RESULT_MODE, resultMode), e);
        }
    }
    String field = params.getDefaultField();
    if (field != null) {
        params.setDefaultField(field);
    }
    params.setLimit(parseLimit(soapParams.getLimit()));
    params.setOffset(MoreObjects.firstNonNull(soapParams.getOffset(), 0));
    CursorInfo cursor = soapParams.getCursor();
    if (cursor != null) {
        params.parseCursor(cursor, zsc.getRequestedAccountId(), params);
    }
    if (soapParams instanceof MailSearchParams) {
        MailSearchParams mailParams = (MailSearchParams) soapParams;
        params.setFullConversation(ZmBoolean.toBool(mailParams.getFullConversation(), false));
        params.setWantContent(MoreObjects.firstNonNull(mailParams.getWantContent(), MsgContent.full));
        params.setIncludeMemberOf(mailParams.getIncludeMemberOf());
    }
    return params;
}
Also used : CursorInfo(com.zimbra.soap.type.CursorInfo) ZimbraSearchParams(com.zimbra.common.mailbox.ZimbraSearchParams) MailSearchParams(com.zimbra.soap.mail.type.MailSearchParams) AttributeName(com.zimbra.soap.type.AttributeName) CalTZInfoInterface(com.zimbra.soap.base.CalTZInfoInterface) MailSearchParams(com.zimbra.soap.mail.type.MailSearchParams)

Aggregations

ZimbraSearchParams (com.zimbra.common.mailbox.ZimbraSearchParams)1 CalTZInfoInterface (com.zimbra.soap.base.CalTZInfoInterface)1 MailSearchParams (com.zimbra.soap.mail.type.MailSearchParams)1 AttributeName (com.zimbra.soap.type.AttributeName)1 CursorInfo (com.zimbra.soap.type.CursorInfo)1