Search in sources :

Example 36 with Filter

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

the class CleanerTimer method cleanup.

public int cleanup(final Map.Entry<String, Class<?>> baseDn, final Date now, final int batchSize) {
    try {
        Filter filter = Filter.createANDFilter(Filter.createEqualityFilter("del", true), Filter.createLessOrEqualFilter("exp", entryManager.encodeTime(baseDn.getKey(), now)));
        int removedCount = entryManager.remove(baseDn.getKey(), baseDn.getValue(), filter, batchSize);
        log.trace("Removed " + removedCount + " entries from " + baseDn.getKey());
        return removedCount;
    } catch (Exception e) {
        log.error("Failed to perform clean up.", e);
    }
    return 0;
}
Also used : Filter(org.gluu.search.filter.Filter)

Example 37 with Filter

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

the class MetricService method findMetricEntry.

public Map<MetricType, List<? extends MetricEntry>> findMetricEntry(ApplicationType applicationType, List<MetricType> metricTypes, Date startDate, Date endDate, String... returnAttributes) {
    prepareBranch(null, applicationType);
    Map<MetricType, List<? extends MetricEntry>> result = new HashMap<MetricType, List<? extends MetricEntry>>();
    if ((metricTypes == null) || (metricTypes.size() == 0)) {
        return result;
    }
    // Prepare list of DNs
    Set<String> metricDns = getBaseDnForPeriod(applicationType, startDate, endDate);
    if (metricDns.size() == 0) {
        return result;
    }
    for (MetricType metricType : metricTypes) {
        List<MetricEntry> metricTypeResult = new LinkedList<MetricEntry>();
        for (String metricDn : metricDns) {
            List<Filter> metricTypeFilters = new ArrayList<Filter>();
            Filter applicationTypeFilter = Filter.createEqualityFilter("oxApplicationType", applicationType.getValue());
            Filter eventTypeTypeFilter = Filter.createEqualityFilter("oxMetricType", metricType.getValue());
            Filter startDateFilter = Filter.createGreaterOrEqualFilter("oxStartDate", getEntryManager().encodeTime(metricDn, (startDate)));
            Filter endDateFilter = Filter.createLessOrEqualFilter("oxEndDate", getEntryManager().encodeTime(metricDn, endDate));
            metricTypeFilters.add(applicationTypeFilter);
            metricTypeFilters.add(eventTypeTypeFilter);
            metricTypeFilters.add(startDateFilter);
            metricTypeFilters.add(endDateFilter);
            Filter filter = Filter.createANDFilter(metricTypeFilters);
            List<? extends MetricEntry> metricTypeMonthResult = (List<? extends MetricEntry>) getEntryManager().findEntries(metricDn, metricType.getMetricEntryType(), filter, returnAttributes);
            metricTypeResult.addAll(metricTypeMonthResult);
        }
        // Sort entries to avoid calculation errors
        getEntryManager().sortListByProperties(MetricEntry.class, metricTypeResult, false, "creationDate");
        result.put(metricType, metricTypeResult);
    }
    return result;
}
Also used : MetricType(org.gluu.model.metric.MetricType) MetricEntry(org.gluu.model.metric.ldap.MetricEntry) Filter(org.gluu.search.filter.Filter)

Example 38 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 = persistenceEntryManager.findEntries(baseDn, CustomScript.class, filter, returnAttributes);
    return result;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) Filter(org.gluu.search.filter.Filter) CustomScriptType(org.gluu.model.custom.script.CustomScriptType) ArrayList(java.util.ArrayList)

Example 39 with Filter

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

the class AbstractCustomScriptService method getScriptByDisplayName.

public CustomScript getScriptByDisplayName(String name) {
    Filter searchFilter = Filter.createEqualityFilter("displayName", name);
    List<CustomScript> result = persistenceEntryManager.findEntries(baseDn(), CustomScript.class, searchFilter, 1);
    if (result != null && !result.isEmpty()) {
        return result.get(0);
    }
    return null;
}
Also used : CustomScript(org.gluu.model.custom.script.model.CustomScript) Filter(org.gluu.search.filter.Filter)

Example 40 with Filter

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

the class AbstractCustomScriptService method findOtherCustomScripts.

public List<CustomScript> findOtherCustomScripts(String pattern, int sizeLimit) {
    String[] targetArray = new String[] { pattern };
    Filter descriptionFilter = Filter.createSubstringFilter(OxConstants.DESCRIPTION, null, targetArray, null);
    Filter scriptTypeFilter = Filter.createNOTFilter(Filter.createEqualityFilter(OxConstants.SCRIPT_TYPE, CustomScriptType.PERSON_AUTHENTICATION));
    Filter displayNameFilter = Filter.createSubstringFilter(OxConstants.DISPLAY_NAME, null, targetArray, null);
    Filter searchFilter = Filter.createORFilter(descriptionFilter, displayNameFilter);
    return persistenceEntryManager.findEntries(baseDn(), CustomScript.class, Filter.createANDFilter(searchFilter, scriptTypeFilter), sizeLimit);
}
Also used : Filter(org.gluu.search.filter.Filter)

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