Search in sources :

Example 81 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class LdapSample method main.

public static void main(String[] args) {
    // Prepare sample connection details
    LdapSampleEntryManager ldapSampleEntryManager = new LdapSampleEntryManager();
    // Create LDAP entry manager
    LdapEntryManager ldapEntryManager = ldapSampleEntryManager.createLdapEntryManager();
    // Find all users which have specified object classes defined in SimpleUser
    List<SimpleUser> users = ldapEntryManager.findEntries("o=gluu", SimpleUser.class, null);
    for (SimpleUser user : users) {
        LOG.debug("User with uid: " + user.getUserId());
    }
    if (users.size() > 0) {
        // Add attribute "streetAddress" to first user
        SimpleUser user = users.get(0);
        user.getCustomAttributes().add(new CustomAttribute("streetAddress", "Somewhere: " + System.currentTimeMillis()));
        ldapEntryManager.merge(user);
    }
    Filter filter = Filter.createEqualityFilter("gluuStatus", "active");
    List<SimpleAttribute> attributes = ldapEntryManager.findEntries("o=gluu", SimpleAttribute.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
    for (SimpleAttribute attribute : attributes) {
        LOG.debug("Attribute with displayName: " + attribute.getCustomAttributes().get(1));
    }
    List<SimpleSession> sessions = ldapEntryManager.findEntries("o=gluu", SimpleSession.class, filter, SearchScope.SUB, null, null, 10, 0, 0);
    LOG.debug("Found sessions: " + sessions.size());
    List<SimpleGrant> grants = ldapEntryManager.findEntries("o=gluu", SimpleGrant.class, null, SearchScope.SUB, new String[] { "oxAuthGrantId" }, null, 10, 0, 0);
    LOG.debug("Found grants: " + grants.size());
    try {
        ListViewResponse<SimpleUser> vlvResponse = ldapEntryManager.findListViewResponse("o=gluu", SimpleUser.class, null, 10, 100000, 1000, "displayName", SortOrder.ASCENDING, new String[] { "uid", "displayName", "gluuStatus" });
        LOG.debug("Found persons: " + vlvResponse.getTotalResults());
        System.out.println(vlvResponse.getResult().size());
    } catch (Exception ex) {
        LOG.error("Failed to search", ex);
    }
}
Also used : SimpleUser(org.gluu.ldap.model.SimpleUser) CustomAttribute(org.gluu.persist.model.base.CustomAttribute) SimpleAttribute(org.gluu.ldap.model.SimpleAttribute) SimpleGrant(org.gluu.ldap.model.SimpleGrant) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) Filter(org.gluu.search.filter.Filter) SimpleSession(org.gluu.ldap.model.SimpleSession)

Example 82 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class BaseEntryManager method countEntries.

@SuppressWarnings("unchecked")
public <T> int countEntries(Object entry) {
    if (entry == null) {
        throw new MappingException("Entry to count is null");
    }
    // Check entry class
    Class<T> entryClass = (Class<T>) entry.getClass();
    checkEntryClass(entryClass, false);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    Filter searchFilter = createFilterByEntry(entry, entryClass, attributes);
    return countEntries(dnValue.toString(), entryClass, searchFilter);
}
Also used : Filter(org.gluu.search.filter.Filter) LdapObjectClass(org.gluu.site.ldap.persistence.annotation.LdapObjectClass) LdapCustomObjectClass(org.gluu.site.ldap.persistence.annotation.LdapCustomObjectClass) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation)

Example 83 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class BaseEntryManager method findEntries.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> findEntries(Object entry, int sizeLimit) {
    if (entry == null) {
        throw new MappingException("Entry to find is null");
    }
    // Check entry class
    Class<T> entryClass = (Class<T>) entry.getClass();
    checkEntryClass(entryClass, false);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    Filter searchFilter = createFilterByEntry(entry, entryClass, attributes);
    return findEntries(dnValue.toString(), entryClass, searchFilter, SearchScope.SUB, null, sizeLimit, DEFAULT_PAGINATION_SIZE);
}
Also used : Filter(org.gluu.search.filter.Filter) LdapObjectClass(org.gluu.site.ldap.persistence.annotation.LdapObjectClass) LdapCustomObjectClass(org.gluu.site.ldap.persistence.annotation.LdapCustomObjectClass) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation)

Example 84 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class LookupService method buildInumFilter.

public Filter buildInumFilter(List<String> inums) {
    List<Filter> inumFilters = new ArrayList<Filter>(inums.size());
    for (String inum : inums) {
        inumFilters.add(Filter.createEqualityFilter(OxConstants.INUM, inum));
    }
    Filter searchFilter = Filter.createORFilter(inumFilters);
    return searchFilter;
}
Also used : Filter(org.gluu.search.filter.Filter) ArrayList(java.util.ArrayList)

Example 85 with Filter

use of org.gluu.search.filter.Filter in project oxCore by GluuFederation.

the class AbstractCustomScriptService method findCustomScripts.

public List<CustomScript> findCustomScripts(List<CustomScriptType> customScriptTypes, String... returnAttributes) {
    String baseDn = baseDn();
    if ((customScriptTypes == null) || (customScriptTypes.size() == 0)) {
        return findAllCustomScripts(returnAttributes);
    }
    List<Filter> customScriptTypeFilters = new ArrayList<Filter>();
    for (CustomScriptType customScriptType : customScriptTypes) {
        Filter customScriptTypeFilter = Filter.createEqualityFilter("oxScriptType", customScriptType.getValue());
        customScriptTypeFilters.add(customScriptTypeFilter);
    }
    Filter filter = Filter.createORFilter(customScriptTypeFilters);
    List<CustomScript> result = ldapEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
    return result;
}
Also used : CustomScript(org.xdi.model.custom.script.model.CustomScript) Filter(org.gluu.search.filter.Filter) CustomScriptType(org.xdi.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList)

Aggregations

Filter (org.gluu.search.filter.Filter)122 ArrayList (java.util.ArrayList)34 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)9 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)7 MappingException (org.gluu.persist.exception.mapping.MappingException)7 EntryPersistenceException (org.gluu.persist.exception.EntryPersistenceException)6 SearchException (org.gluu.persist.exception.operation.SearchException)6 List (java.util.List)5 GluuAttribute (org.gluu.model.GluuAttribute)5 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)5 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 ParseException (java.text.ParseException)4 GluuGroup (org.gluu.oxtrust.model.GluuGroup)4 PersistenceEntryManager (org.gluu.persist.PersistenceEntryManager)4 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)4 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)4 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)4 GluuAttribute (org.xdi.model.GluuAttribute)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 Date (java.util.Date)3