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