Search in sources :

Example 11 with JSONValue

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

the class LessThanJSONObjectFilter 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 12 with JSONValue

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

the class NegateJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(2));
    fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
    fields.put(FIELD_NEGATE_FILTER, negateFilter.toJSONObject());
    return new JSONObject(fields);
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONString(com.unboundid.util.json.JSONString) JSONString(com.unboundid.util.json.JSONString) LinkedHashMap(java.util.LinkedHashMap) NotNull(com.unboundid.util.NotNull)

Example 13 with JSONValue

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

the class ObjectMatchesJSONObjectFilter 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));
    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_FILTER, filter.toJSONObject());
    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 14 with JSONValue

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

the class ANDJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(2));
    fields.put(FIELD_FILTER_TYPE, new JSONString(FILTER_TYPE));
    final ArrayList<JSONValue> filterValues = new ArrayList<>(andFilters.size());
    for (final JSONObjectFilter f : andFilters) {
        filterValues.add(f.toJSONObject());
    }
    fields.put(FIELD_AND_FILTERS, new JSONArray(filterValues));
    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 15 with JSONValue

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

the class ContainsFieldJSONObjectFilter 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));
    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));
    }
    if (!expectedValueTypes.equals(ALL_EXPECTED_VALUE_TYPES)) {
        if (expectedValueTypes.size() == 1) {
            fields.put(FIELD_EXPECTED_TYPE, new JSONString(expectedValueTypes.iterator().next().toString()));
        } else {
            final ArrayList<JSONValue> expectedTypeValues = new ArrayList<>(expectedValueTypes.size());
            for (final ExpectedValueType t : expectedValueTypes) {
                expectedTypeValues.add(new JSONString(t.toString()));
            }
            fields.put(FIELD_EXPECTED_TYPE, new JSONArray(expectedTypeValues));
        }
    }
    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

JSONValue (com.unboundid.util.json.JSONValue)50 JSONString (com.unboundid.util.json.JSONString)45 JSONObject (com.unboundid.util.json.JSONObject)40 NotNull (com.unboundid.util.NotNull)33 LinkedHashMap (java.util.LinkedHashMap)31 JSONArray (com.unboundid.util.json.JSONArray)27 ArrayList (java.util.ArrayList)27 Test (org.testng.annotations.Test)9 LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)8 JSONBoolean (com.unboundid.util.json.JSONBoolean)6 Map (java.util.Map)6 JSONNumber (com.unboundid.util.json.JSONNumber)5 File (java.io.File)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)4 JSONException (com.unboundid.util.json.JSONException)4 JSONField (com.unboundid.util.json.JSONField)4 Date (java.util.Date)4 List (java.util.List)4 Entry (com.unboundid.ldap.sdk.Entry)3 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)2