Search in sources :

Example 6 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class GalImport method importGal.

public void importGal(int fid, boolean fullSync, boolean force) throws ServiceException {
    mbox.beginTrackingSync();
    DataSource ds = getDataSource();
    DataSourceItem folderMapping = DbDataSource.getMapping(ds, fid);
    if (folderMapping.md == null) {
        folderMapping.itemId = fid;
        folderMapping.md = new Metadata();
        folderMapping.md.put(TYPE, FOLDER);
        DbDataSource.addMapping(ds, folderMapping);
    }
    String syncToken = fullSync ? "" : folderMapping.md.get(SYNCTOKEN, "");
    HashMap<String, DataSourceItem> allMappings = new HashMap<String, DataSourceItem>();
    if (fullSync || force)
        for (DataSourceItem dsItem : DbDataSource.getAllMappings(ds)) if (// non-folder items
        dsItem.md == null || dsItem.md.get(TYPE, null) == null)
            allMappings.put(dsItem.remoteId, dsItem);
    OperationContext octxt = new OperationContext(mbox);
    SearchGalResult result = SearchGalResult.newSearchGalResult(new GalSearchVisitor(mbox, allMappings, fid, force));
    try {
        searchGal(syncToken, result, true);
    } catch (Exception e) {
        setStatus(false);
        ZimbraLog.gal.error("Error executing gal search", e);
        return;
    }
    folderMapping.md.put(SYNCTOKEN, result.getToken());
    DbDataSource.updateMapping(ds, folderMapping);
    if (allMappings.size() == 0 || !fullSync) {
        setStatus(true);
        return;
    }
    ArrayList<Integer> deleted = new ArrayList<Integer>();
    int[] deletedIds = new int[allMappings.size()];
    int i = 0;
    for (DataSourceItem dsItem : allMappings.values()) {
        deleted.add(dsItem.itemId);
        deletedIds[i++] = dsItem.itemId;
    }
    try {
        mbox.delete(octxt, deletedIds, MailItem.Type.CONTACT, null);
    } catch (ServiceException e) {
        ZimbraLog.gal.warn("Ignoring error deleting gal contacts", e);
    }
    DbDataSource.deleteMappings(getDataSource(), deleted);
    mbox.index.optimize();
    setStatus(true);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) HashMap(java.util.HashMap) Metadata(com.zimbra.cs.mailbox.Metadata) ArrayList(java.util.ArrayList) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) ServiceException(com.zimbra.common.service.ServiceException) JSONException(org.json.JSONException) DbDataSource(com.zimbra.cs.db.DbDataSource) DataSource(com.zimbra.cs.account.DataSource) ServiceException(com.zimbra.common.service.ServiceException) DataSourceItem(com.zimbra.cs.db.DbDataSource.DataSourceItem)

Example 7 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class ProvUtil method doAutoCompleteGal.

private void doAutoCompleteGal(String[] args) throws ServiceException {
    String domain = args[1];
    String query = args[2];
    int limit = 100;
    Domain d = lookupDomain(domain);
    GalContact.Visitor visitor = new GalContact.Visitor() {

        @Override
        public void visit(GalContact gc) throws ServiceException {
            dumpContact(gc);
        }
    };
    SearchGalResult result = prov.autoCompleteGal(d, query, GalSearchType.all, limit, visitor);
}
Also used : PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult)

Example 8 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class AclReports method getMatchingPrincipals.

private ArrayList<DavResource> getMatchingPrincipals(DavContext ctxt, QName prop, String match, GalSearchType type) throws DavException, ServiceException {
    Provisioning prov = Provisioning.getInstance();
    ArrayList<DavResource> ret = new ArrayList<DavResource>();
    Account authAccount = ctxt.getAuthAccount();
    if (prop.equals(DavElements.E_DISPLAYNAME)) {
        if (!authAccount.isFeatureGalEnabled() || !authAccount.isFeatureGalAutoCompleteEnabled())
            return ret;
        SearchGalResult result = prov.searchGal(prov.getDomain(authAccount), match, type, Provisioning.GalMode.zimbra, null);
        for (GalContact ct : result.getMatches()) {
            String email = (String) ct.getAttrs().get(ContactConstants.A_email);
            if (email != null) {
                Account acct = prov.get(Key.AccountBy.name, email);
                if (acct != null)
                    ret.add(UrlNamespace.getPrincipal(ctxt, acct));
            }
        }
    } else if (prop.equals(DavElements.E_CALENDAR_HOME_SET)) {
        int index = match.lastIndexOf('/');
        if (index > 0)
            match = match.substring(index + 1);
        Account acct = prov.get(Key.AccountBy.name, match);
        if (acct != null)
            ret.add(UrlNamespace.getPrincipal(ctxt, acct));
    }
    return ret;
}
Also used : Account(com.zimbra.cs.account.Account) DavResource(com.zimbra.cs.dav.resource.DavResource) GalContact(com.zimbra.cs.account.GalContact) ArrayList(java.util.ArrayList) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Provisioning(com.zimbra.cs.account.Provisioning)

Example 9 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class TestGal method tokenizeTest.

private void tokenizeTest(GalOp galOp, String tokenizeKey, String key, String[] expectedUsers) throws Exception {
    Domain domain = mProv.get(Key.DomainBy.name, TOKENIZE_TEST_DOMAIN_NAME);
    SearchGalResult galResult = null;
    if (galOp == GalOp.GOP_AUTOCOMPLETE)
        galResult = mProv.autoCompleteGal(domain, key, // Provisioning.GAL_SEARCH_TYPE.ALL, 
        GalSearchType.account, 10, null);
    else if (galOp == GalOp.GOP_SEARCH)
        galResult = mProv.searchGal(domain, key, GalSearchType.account, 0, null);
    else
        fail();
    System.out.println("tokenizeTest: key=" + key);
    assertEquals(galResult.getTokenizeKey(), tokenizeKey);
    Set<String> results = new HashSet<String>();
    for (GalContact gc : galResult.getMatches()) {
        String r = (String) gc.getAttrs().get(ContactConstants.A_email);
        System.out.println("    " + r);
        results.add(r);
    }
    for (String mail : expectedUsers) assertTrue(results.contains(mail + "@" + TOKENIZE_TEST_DOMAIN_NAME));
    List<String> expectedUsersList = Arrays.asList(expectedUsers);
    for (String mail : results) assertTrue(expectedUsersList.contains((mail.split("@"))[0]));
    assertEquals(expectedUsers.length, galResult.getNumMatches());
}
Also used : GalContact(com.zimbra.cs.account.GalContact) SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain) HashSet(java.util.HashSet)

Example 10 with SearchGalResult

use of com.zimbra.cs.account.Provisioning.SearchGalResult in project zm-mailbox by Zimbra.

the class TestGal method autoCompleteGal.

private void autoCompleteGal(int numResultsExpected, int maxWanted) throws Exception {
    Domain domain = mProv.get(Key.DomainBy.name, DOMAIN_NAME);
    SearchGalResult galResult = mProv.autoCompleteGal(domain, QUERY, // Provisioning.GAL_SEARCH_TYPE.ALL, 
    GalSearchType.account, maxWanted, null);
    if (numResultsExpected != galResult.getNumMatches())
        dumpResult(galResult);
    assertEquals(numResultsExpected, galResult.getNumMatches());
    boolean expectedHasMore = numResultsExpected < NUM_ACCOUNTS;
    assertEquals(expectedHasMore, galResult.getHadMore());
}
Also used : SearchGalResult(com.zimbra.cs.account.Provisioning.SearchGalResult) Domain(com.zimbra.cs.account.Domain)

Aggregations

SearchGalResult (com.zimbra.cs.account.Provisioning.SearchGalResult)14 Domain (com.zimbra.cs.account.Domain)5 Account (com.zimbra.cs.account.Account)3 GalContact (com.zimbra.cs.account.GalContact)3 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)3 LdapProv (com.zimbra.cs.account.ldap.LdapProv)2 GalSearchParams (com.zimbra.cs.gal.GalSearchParams)2 GalSearchType (com.zimbra.soap.type.GalSearchType)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 Control (com.unboundid.ldap.sdk.Control)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 SearchRequest (com.unboundid.ldap.sdk.SearchRequest)1 SearchResult (com.unboundid.ldap.sdk.SearchResult)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 SearchScope (com.unboundid.ldap.sdk.SearchScope)1 AssertionRequestControl (com.unboundid.ldap.sdk.controls.AssertionRequestControl)1 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)1