Search in sources :

Example 1 with GalType

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

the class GalSearchControl method ldapSearch.

public void ldapSearch() throws ServiceException {
    Domain domain = mParams.getDomain();
    GalMode galMode = domain.getGalMode();
    GalSearchType stype = mParams.getType();
    Provisioning prov = Provisioning.getInstance();
    if (needResources()) {
        mParams.setType(GalSearchType.resource);
        mParams.createSearchConfig(GalType.zimbra);
        try {
            prov.searchGal(mParams);
        } catch (Exception e) {
            throw ServiceException.FAILURE("ldap search failed", e);
        }
        mParams.setType(stype);
    }
    Integer ldapLimit = mParams.getLdapLimit();
    int limit;
    if (ldapLimit == null)
        limit = mParams.getLimit();
    else
        limit = ldapLimit;
    // restrict to domain config if we are not syncing, and there is no specific ldap limit set
    if (limit == 0 && GalOp.sync != mParams.getOp() && ldapLimit == null) {
        limit = domain.getGalMaxResults();
    }
    // Return the GAL definition last modified time so that clients can use it to decide if fullsync is required.
    if ((mParams.getOp() == GalOp.sync) && (mParams.getResultCallback() != null)) {
        String galLastModified = domain.getGalDefinitionLastModifiedTimeAsString();
        if (galLastModified != null) {
            mParams.getResultCallback().setGalDefinitionLastModified(galLastModified);
        }
    }
    ZimbraLog.gal.info("Using limit %d for ldapSearch", limit);
    mParams.setLimit(limit);
    if (galMode == GalMode.both) {
        // make two gal searches for 1/2 results each
        mParams.setLimit(limit / 2);
    }
    GalType type = GalType.ldap;
    if (galMode != GalMode.ldap) {
        // do zimbra gal search
        type = GalType.zimbra;
    }
    mParams.createSearchConfig(type);
    GalSyncToken galSyncToken = mParams.getGalSyncToken();
    if (galSyncToken != null) {
        mParams.setLdapTimeStamp(galSyncToken.getIntLdapTs());
        mParams.setLdapMatchCount(galSyncToken.getIntLdapMatchCount());
        mParams.setLdapHasMore(galSyncToken.intLdapHasMore());
        mParams.setMaxLdapTimeStamp(galSyncToken.getIntMaxLdapTs());
    }
    try {
        prov.searchGal(mParams);
    } catch (Exception e) {
        throw ServiceException.FAILURE("ldap search failed", e);
    }
    String resultToken = null;
    boolean intLdapHasMore = false;
    boolean extLdapHasMore = false;
    if (mParams.getResult() != null) {
        intLdapHasMore = mParams.getResult().getHadMore();
        if (mParams.getOp() == GalOp.sync) {
            resultToken = getLdapSearchResultToken(mParams.getResult(), "");
        }
    }
    if (galMode == GalMode.both) {
        // do the second query
        mParams.createSearchConfig(GalType.ldap);
        if (galSyncToken != null) {
            mParams.setLdapTimeStamp(galSyncToken.getExtLdapTs());
            mParams.setLdapMatchCount(galSyncToken.getExtLdapMatchCount());
            mParams.setLdapHasMore(galSyncToken.extLdapHasMore());
            mParams.setMaxLdapTimeStamp(galSyncToken.getExtMaxLdapTs());
        }
        try {
            prov.searchGal(mParams);
        } catch (Exception e) {
            throw ServiceException.FAILURE("ldap search failed", e);
        }
        if (mParams.getResult() != null) {
            extLdapHasMore = mParams.getResult().getHadMore();
            if (mParams.getOp() == GalOp.sync) {
                resultToken = getLdapSearchResultToken(mParams.getResult(), resultToken);
            }
        }
    }
    if (mParams.getResultCallback() != null) {
        if (mParams.getOp() == GalOp.sync) {
            mParams.getResultCallback().setNewToken(resultToken);
        }
        mParams.getResultCallback().setHasMoreResult(intLdapHasMore || extLdapHasMore);
    }
}
Also used : GalMode(com.zimbra.common.account.ZAttrProvisioning.GalMode) GalType(com.zimbra.cs.gal.GalSearchConfig.GalType) Domain(com.zimbra.cs.account.Domain) Provisioning(com.zimbra.cs.account.Provisioning) SoapFaultException(com.zimbra.common.soap.SoapFaultException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) GalSearchType(com.zimbra.soap.type.GalSearchType)

Aggregations

GalMode (com.zimbra.common.account.ZAttrProvisioning.GalMode)1 ServiceException (com.zimbra.common.service.ServiceException)1 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Domain (com.zimbra.cs.account.Domain)1 Provisioning (com.zimbra.cs.account.Provisioning)1 GalType (com.zimbra.cs.gal.GalSearchConfig.GalType)1 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)1 GalSearchType (com.zimbra.soap.type.GalSearchType)1 IOException (java.io.IOException)1