Search in sources :

Example 11 with GalSearchType

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

the class GalSearchControl method generateSearchQuery.

private void generateSearchQuery(Account galAcct) throws ServiceException {
    String query = mParams.getQuery();
    String searchByDn = mParams.getSearchEntryByDn();
    GalSearchType type = mParams.getType();
    StringBuilder searchQuery = new StringBuilder();
    if (searchByDn != null) {
        searchQuery.append("#dn:(" + searchByDn + ")");
    } else if (!Strings.isNullOrEmpty(query)) {
        searchQuery.append("contact:\"");
        // escape quotes
        searchQuery.append(query.replace("\"", "\\\""));
        searchQuery.append("\" AND");
    }
    GalSearchQueryCallback queryCallback = mParams.getExtraQueryCallback();
    if (queryCallback != null) {
        String extraQuery = queryCallback.getMailboxSearchQuery();
        if (extraQuery != null) {
            ZimbraLog.gal.debug("extra search query: " + extraQuery);
            searchQuery.append(" (").append(extraQuery).append(") AND");
        }
    }
    GalMode galMode = mParams.getDomain().getGalMode();
    boolean first = true;
    for (DataSource ds : galAcct.getAllDataSources()) {
        if (ds.getType() != DataSourceType.gal)
            continue;
        String galType = ds.getAttr(Provisioning.A_zimbraGalType);
        if (galMode == GalMode.ldap && galType.compareTo("zimbra") == 0)
            continue;
        if (galMode == GalMode.zimbra && galType.compareTo("ldap") == 0)
            continue;
        if (first)
            searchQuery.append("(");
        else
            searchQuery.append(" OR");
        first = false;
        searchQuery.append(" inid:").append(ds.getFolderId());
    }
    if (!first)
        searchQuery.append(")");
    switch(type) {
        case resource:
            searchQuery.append(" AND #zimbraAccountCalendarUserType:RESOURCE");
            break;
        case group:
            searchQuery.append(" AND #type:group");
            break;
        case account:
            searchQuery.append(" AND !(#zimbraAccountCalendarUserType:RESOURCE)");
            break;
        case all:
            break;
    }
    ZimbraLog.gal.debug("query: %s", searchQuery);
    mParams.parseSearchParams(mParams.getRequest(), searchQuery.toString());
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalSearchType(com.zimbra.soap.type.GalSearchType) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource)

Aggregations

GalSearchType (com.zimbra.soap.type.GalSearchType)11 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)6 Account (com.zimbra.cs.account.Account)4 Domain (com.zimbra.cs.account.Domain)4 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 GalMode (com.zimbra.common.account.ZAttrProvisioning.GalMode)3 Provisioning (com.zimbra.cs.account.Provisioning)3 DataSource (com.zimbra.cs.account.DataSource)2 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)2 DbDataSource (com.zimbra.cs.db.DbDataSource)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 ContainerException (com.zimbra.common.soap.Element.ContainerException)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)1 GalContact (com.zimbra.cs.account.GalContact)1 DavResource (com.zimbra.cs.dav.resource.DavResource)1 GalType (com.zimbra.cs.gal.GalSearchConfig.GalType)1 AutoCompleteResult (com.zimbra.cs.mailbox.ContactAutoComplete.AutoCompleteResult)1