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);
}
}
Aggregations