Search in sources :

Example 91 with JSONArray

use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.

the class GreaterThanJSONObjectFilter method matchesJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
public boolean matchesJSONObject(@NotNull final JSONObject o) {
    final List<JSONValue> candidates = getValues(o, field);
    if (candidates.isEmpty()) {
        return false;
    }
    for (final JSONValue v : candidates) {
        if (v instanceof JSONArray) {
            boolean matchOne = false;
            boolean matchAll = true;
            for (final JSONValue arrayValue : ((JSONArray) v).getValues()) {
                if (matches(arrayValue)) {
                    if (!matchAllElements) {
                        return true;
                    }
                    matchOne = true;
                } else {
                    matchAll = false;
                    if (matchAllElements) {
                        break;
                    }
                }
            }
            if (matchAllElements && matchOne && matchAll) {
                return true;
            }
        } else if (matches(v)) {
            return true;
        }
    }
    return false;
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONArray(com.unboundid.util.json.JSONArray)

Example 92 with JSONArray

use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.

the class JSONObjectFilter method getValues.

/**
 * Retrieves the set of values that match the provided field name specifier.
 *
 * @param  o               The JSON object to examine.
 * @param  fieldName       The field name specifier for the values to
 *                         retrieve.
 * @param  fieldNameIndex  The current index into the field name specifier.
 * @param  values          The list into which matching values should be
 *                         added.
 */
private static void getValues(@NotNull final JSONObject o, @NotNull final List<String> fieldName, final int fieldNameIndex, @NotNull final List<JSONValue> values) {
    final JSONValue v = o.getField(fieldName.get(fieldNameIndex));
    if (v == null) {
        return;
    }
    final int nextIndex = fieldNameIndex + 1;
    if (nextIndex < fieldName.size()) {
        // objects.
        if (v instanceof JSONObject) {
            getValues((JSONObject) v, fieldName, nextIndex, values);
        } else if (v instanceof JSONArray) {
            getValuesFromArray((JSONArray) v, fieldName, nextIndex, values);
        }
        return;
    }
    // If we've gotten here, then there is no more of the field specifier, so
    // the value we retrieved matches the specifier.  Add it to the list of
    // values.
    values.add(v);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray)

Example 93 with JSONArray

use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.

the class ORJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(3));
    fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
    final ArrayList<JSONValue> filterValues = new ArrayList<>(orFilters.size());
    for (final JSONObjectFilter f : orFilters) {
        filterValues.add(f.toJSONObject());
    }
    fields.put(FIELD_OR_FILTERS, new JSONArray(filterValues));
    if (exclusive) {
        fields.put(FIELD_EXCLUSIVE, JSONBoolean.TRUE);
    }
    return new JSONObject(fields);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 94 with JSONArray

use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.

the class EqualsAnyJSONObjectFilter method decodeFilter.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
protected EqualsAnyJSONObjectFilter decodeFilter(@NotNull final JSONObject filterObject) throws JSONException {
    final List<String> fieldPath = getStrings(filterObject, FIELD_FIELD_PATH, false, null);
    final boolean isCaseSensitive = getBoolean(filterObject, FIELD_CASE_SENSITIVE, false);
    final JSONValue arrayValue = filterObject.getField(FIELD_VALUES);
    if (arrayValue instanceof JSONArray) {
        return new EqualsAnyJSONObjectFilter(fieldPath, ((JSONArray) arrayValue).getValues(), isCaseSensitive);
    } else {
        throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(filterObject), FILTER_TYPE, FIELD_VALUES));
    }
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONArray(com.unboundid.util.json.JSONArray) JSONException(com.unboundid.util.json.JSONException) JSONString(com.unboundid.util.json.JSONString) NotNull(com.unboundid.util.NotNull)

Example 95 with JSONArray

use of com.unboundid.util.json.JSONArray in project ldapsdk by pingidentity.

the class EqualsAnyJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(4));
    fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
    if (field.size() == 1) {
        fields.put(FIELD_FIELD_PATH, new JSONString(field.get(0)));
    } else {
        final ArrayList<JSONValue> fieldNameValues = new ArrayList<>(field.size());
        for (final String s : field) {
            fieldNameValues.add(new JSONString(s));
        }
        fields.put(FIELD_FIELD_PATH, new JSONArray(fieldNameValues));
    }
    fields.put(FIELD_VALUES, new JSONArray(values));
    if (caseSensitive) {
        fields.put(FIELD_CASE_SENSITIVE, JSONBoolean.TRUE);
    }
    return new JSONObject(fields);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.unboundid.util.json.JSONArray) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONArray (com.unboundid.util.json.JSONArray)98 JSONObject (com.unboundid.util.json.JSONObject)89 JSONString (com.unboundid.util.json.JSONString)77 Test (org.testng.annotations.Test)72 JSONField (com.unboundid.util.json.JSONField)68 JSONValue (com.unboundid.util.json.JSONValue)27 JSONNumber (com.unboundid.util.json.JSONNumber)22 NotNull (com.unboundid.util.NotNull)20 ArrayList (java.util.ArrayList)19 LinkedHashMap (java.util.LinkedHashMap)18 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 PasswordQualityRequirement (com.unboundid.ldap.sdk.unboundidds.extensions.PasswordQualityRequirement)7 Entry (com.unboundid.ldap.sdk.Entry)6 Map (java.util.Map)6 LDAPSDKUsageException (com.unboundid.util.LDAPSDKUsageException)5 JSONBoolean (com.unboundid.util.json.JSONBoolean)5 JSONException (com.unboundid.util.json.JSONException)5 Date (java.util.Date)4 List (java.util.List)4 LogField (com.unboundid.ldap.sdk.unboundidds.logs.v2.LogField)3