Search in sources :

Example 1 with ZLdapFilterFactory

use of com.zimbra.cs.ldap.ZLdapFilterFactory in project zm-mailbox by Zimbra.

the class GalUtil method expandKey.

private static String expandKey(String tokenize, String filterTemplate, String key) throws ServiceException {
    if (!filterTemplate.startsWith("(")) {
        if (filterTemplate.endsWith(")"))
            throw ServiceException.INVALID_REQUEST("Unbalanced parenthesis in filter:" + filterTemplate, null);
        filterTemplate = "(" + filterTemplate + ")";
    }
    String query = null;
    Map<String, String> vars = new HashMap<String, String>();
    ZLdapFilterFactory filterFactory = ZLdapFilterFactory.getInstance();
    if (tokenize != null) {
        String[] tokens = key.split("\\s+");
        if (tokens.length > 1) {
            String q;
            if (GalConstants.TOKENIZE_KEY_AND.equals(tokenize)) {
                q = "(&";
            } else if (GalConstants.TOKENIZE_KEY_OR.equals(tokenize)) {
                q = "(|";
            } else {
                throw ServiceException.FAILURE("invalid attribute value for tokenize key: " + tokenize, null);
            }
            for (String t : tokens) {
                vars.clear();
                vars.put("s", filterFactory.encodeValue(t));
                q = q + LdapUtil.expandStr(filterTemplate, vars);
            }
            q = q + ")";
            query = q;
        }
    }
    if (query == null) {
        vars.put("s", key == null ? null : filterFactory.encodeValue(key));
        query = LdapUtil.expandStr(filterTemplate, vars);
    }
    return query;
}
Also used : HashMap(java.util.HashMap) ZLdapFilterFactory(com.zimbra.cs.ldap.ZLdapFilterFactory)

Example 2 with ZLdapFilterFactory

use of com.zimbra.cs.ldap.ZLdapFilterFactory in project zm-mailbox by Zimbra.

the class BUG_68831 method upgradeDLs.

private void upgradeDLs(ZLdapContext zlc) throws ServiceException {
    String[] bases = prov.getDIT().getSearchBases(Provisioning.SD_DISTRIBUTION_LIST_FLAG);
    ZLdapFilterFactory filterFactory = ZLdapFilterFactory.getInstance();
    ZLdapFilter homeServerPresent = filterFactory.fromFilterString(FilterId.LDAP_UPGRADE, filterFactory.presenceFilter(ATTR_NAME));
    ZLdapFilter homeServerNotPresent = filterFactory.negate(homeServerPresent);
    String query = filterFactory.andWith(filterFactory.allDistributionLists(), homeServerNotPresent).toFilterString();
    upgrade(zlc, bases, query);
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZLdapFilterFactory(com.zimbra.cs.ldap.ZLdapFilterFactory)

Aggregations

ZLdapFilterFactory (com.zimbra.cs.ldap.ZLdapFilterFactory)2 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)1 HashMap (java.util.HashMap)1