Search in sources :

Example 11 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class TestLdapProvGal method searchGal.

@Test
public void searchGal() throws Exception {
    SKIP_FOR_INMEM_LDAP_SERVER(SkipTestReason.DN_SUBTREE_MATCH_FILTER);
    int NUM_ACCTS = 10;
    int SIZE_LIMIT = 5;
    Account user = null;
    for (int i = 0; i < NUM_ACCTS; i++) {
        String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart(String.valueOf(i)));
        Account acct = createAccount(ACCT_NAME_LOCALPART);
        // use the first one as the user
        if (user == null) {
            user = acct;
        }
    }
    GalSearchType type = GalSearchType.account;
    String query = "searchGal";
    GalSearchParams params = new GalSearchParams(user);
    SearchGalResult result = SearchGalResult.newSearchGalResult(null);
    params.setOp(GalOp.search);
    params.setType(type);
    params.createSearchConfig(GalSearchConfig.GalType.zimbra);
    params.setQuery(query);
    params.setLimit(SIZE_LIMIT);
    params.setGalResult(result);
    prov.searchGal(params);
    assertEquals(SIZE_LIMIT, result.getMatches().size());
    assertTrue(result.getHadMore());
    result = prov.searchGal(domain, query, type, 0, null);
    assertEquals(NUM_ACCTS, result.getMatches().size());
    assertFalse(result.getHadMore());
}
Also used : Account(com.zimbra.cs.account.Account) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) GalSearchType(com.zimbra.soap.type.GalSearchType)

Example 12 with GalSearchParams

use of com.zimbra.cs.gal.GalSearchParams in project zm-mailbox by Zimbra.

the class ContactAutoComplete method queryGal.

private void queryGal(String str, AutoCompleteResult result) {
    ZimbraLog.gal.debug("querying gal");
    GalSearchParams params = new GalSearchParams(mRequestedAcct, mZsc);
    params.setQuery(str);
    params.setType(mSearchType);
    params.setLimit(200);
    params.setNeedCanExpand(mNeedCanExpand);
    params.setResultCallback(new AutoCompleteCallback(str, result, params));
    try {
        try {
            GalSearchControl gal = new GalSearchControl(params);
            gal.autocomplete();
        } catch (ServiceException e) {
            if (ServiceException.PERM_DENIED.equals(e.getCode())) {
                // do not log stack
                ZimbraLog.gal.debug("cannot autocomplete gal: %s", e.getMessage());
            } else {
                throw e;
            }
        }
    } catch (Exception e) {
        ZimbraLog.gal.warn("cannot autocomplete gal", e);
        return;
    }
}
Also used : GalSearchControl(com.zimbra.cs.gal.GalSearchControl) ServiceException(com.zimbra.common.service.ServiceException) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) ServiceException(com.zimbra.common.service.ServiceException)

Aggregations

GalSearchParams (com.zimbra.cs.gal.GalSearchParams)12 GalSearchControl (com.zimbra.cs.gal.GalSearchControl)10 GalSearchType (com.zimbra.soap.type.GalSearchType)6 Account (com.zimbra.cs.account.Account)4 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)4 Domain (com.zimbra.cs.account.Domain)3 EntrySearchFilter (com.zimbra.cs.account.EntrySearchFilter)2 Provisioning (com.zimbra.cs.account.Provisioning)2 SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)2 ServiceException (com.zimbra.common.service.ServiceException)1 Element (com.zimbra.common.soap.Element)1 GalContact (com.zimbra.cs.account.GalContact)1 MemberOfSelector (com.zimbra.soap.account.type.MemberOfSelector)1 HashMap (java.util.HashMap)1