Search in sources :

Example 26 with JSONObject

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

the class JSONObjectExactMatchingRule method valuesMatch.

/**
 * {@inheritDoc}
 */
@Override()
public boolean valuesMatch(@NotNull final ASN1OctetString value1, @NotNull final ASN1OctetString value2) throws LDAPException {
    final JSONObject o1;
    try {
        o1 = new JSONObject(value1.stringValue());
    } catch (final JSONException e) {
        Debug.debugException(e);
        throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, e.getMessage(), e);
    }
    final JSONObject o2;
    try {
        o2 = new JSONObject(value2.stringValue());
    } catch (final JSONException e) {
        Debug.debugException(e);
        throw new LDAPException(ResultCode.INVALID_ATTRIBUTE_SYNTAX, e.getMessage(), e);
    }
    return o1.equals(o2, false, true, false);
}
Also used : JSONObject(com.unboundid.util.json.JSONObject) LDAPException(com.unboundid.ldap.sdk.LDAPException) JSONException(com.unboundid.util.json.JSONException)

Example 27 with JSONObject

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

the class JSONObjectFilter method getFilters.

/**
 * Retrieves the value of the specified field from the provided JSON object as
 * a list of JSON object filters.  The specified field must be a top-level
 * field in the JSON object and it must have a value that is an array of
 * JSON objects that represent valid JSON object filters.
 *
 * @param  o          The JSON object to examine.  It must not be
 *                    {@code null}.
 * @param  fieldName  The name of a top-level field in the JSON object that is
 *                    expected to have a value that is an array of JSON
 *                    objects that represent valid JSON object filters.  It
 *                    must not be {@code null}.
 *
 * @return  The list of JSON object filters retrieved from the JSON object.
 *
 * @throws  JSONException  If the object doesn't have the specified field, or
 *                         if the value of that field is not an array of
 *                         JSON objects that represent valid JSON object
 *                         filters.
 */
@NotNull()
protected List<JSONObjectFilter> getFilters(@NotNull final JSONObject o, @NotNull final String fieldName) throws JSONException {
    final JSONValue value = o.getField(fieldName);
    if (value == null) {
        throw new JSONException(ERR_OBJECT_FILTER_MISSING_REQUIRED_FIELD.get(String.valueOf(o), getFilterType(), fieldName));
    }
    if (!(value instanceof JSONArray)) {
        throw new JSONException(ERR_OBJECT_FILTER_VALUE_NOT_ARRAY.get(String.valueOf(o), getFilterType(), fieldName));
    }
    final List<JSONValue> values = ((JSONArray) value).getValues();
    final ArrayList<JSONObjectFilter> filterList = new ArrayList<>(values.size());
    for (final JSONValue arrayValue : values) {
        if (!(arrayValue instanceof JSONObject)) {
            throw new JSONException(ERR_OBJECT_FILTER_ARRAY_ELEMENT_NOT_OBJECT.get(String.valueOf(o), getFilterType(), fieldName));
        }
        final JSONObject filterObject = (JSONObject) arrayValue;
        try {
            filterList.add(decode(filterObject));
        } catch (final JSONException e) {
            Debug.debugException(e);
            throw new JSONException(ERR_OBJECT_FILTER_ARRAY_ELEMENT_NOT_FILTER.get(String.valueOf(o), getFilterType(), String.valueOf(filterObject), fieldName, e.getMessage()), e);
        }
    }
    return filterList;
}
Also used : JSONValue(com.unboundid.util.json.JSONValue) JSONObject(com.unboundid.util.json.JSONObject) JSONArray(com.unboundid.util.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(com.unboundid.util.json.JSONException) NotNull(com.unboundid.util.NotNull)

Example 28 with JSONObject

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

the class LessThanJSONObjectFilter method toJSONObject.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public JSONObject toJSONObject() {
    final LinkedHashMap<String, JSONValue> fields = new LinkedHashMap<>(StaticUtils.computeMapCapacity(6));
    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_VALUE, value);
    if (allowEquals) {
        fields.put(FIELD_ALLOW_EQUALS, JSONBoolean.TRUE);
    }
    if (matchAllElements) {
        fields.put(FIELD_MATCH_ALL_ELEMENTS, JSONBoolean.TRUE);
    }
    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)

Example 29 with JSONObject

use of com.unboundid.util.json.JSONObject 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 30 with JSONObject

use of com.unboundid.util.json.JSONObject 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)

Aggregations

JSONObject (com.unboundid.util.json.JSONObject)253 Test (org.testng.annotations.Test)205 JSONString (com.unboundid.util.json.JSONString)105 JSONField (com.unboundid.util.json.JSONField)97 JSONArray (com.unboundid.util.json.JSONArray)89 File (java.io.File)67 JSONValue (com.unboundid.util.json.JSONValue)40 LinkedHashMap (java.util.LinkedHashMap)32 NotNull (com.unboundid.util.NotNull)27 ArrayList (java.util.ArrayList)26 JSONNumber (com.unboundid.util.json.JSONNumber)23 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)22 TestLogHandler (com.unboundid.util.TestLogHandler)21 LogException (com.unboundid.ldap.sdk.unboundidds.logs.LogException)20 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)11 PasswordPolicyStateJSONField (com.unboundid.ldap.sdk.unboundidds.PasswordPolicyStateJSONField)11 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)10 Entry (com.unboundid.ldap.sdk.Entry)9 JSONException (com.unboundid.util.json.JSONException)9 Date (java.util.Date)9