Search in sources :

Example 31 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataQuery method toJsonObject.

JsonObject toJsonObject() {
    JsonObject jsonObject = new JsonObject().add(FROM, from).add(LIMIT, limit);
    if (query != null) {
        jsonObject.add(QUERY, query);
    }
    if (ancestorFolderId != null) {
        jsonObject.add(ANCESTOR_FOLDER_ID, ancestorFolderId);
    }
    if (marker != null) {
        jsonObject.add(MARKER, marker);
    }
    if (!orderBy.isEmpty()) {
        JsonArray orderByJson = new JsonArray();
        orderBy.stream().map(OrderBy::toJsonObject).forEach(orderByJson::add);
        jsonObject.add(ORDER_BY, orderByJson);
    }
    if (!fields.isEmpty()) {
        JsonArray fieldsJson = new JsonArray();
        fields.forEach(fieldsJson::add);
        jsonObject.add(FIELDS, fieldsJson);
    }
    if (queryParameters.iterator().hasNext()) {
        jsonObject.add(QUERY_PARAMS, new JsonObject(queryParameters));
    }
    return jsonObject;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 32 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTemplate method getFieldJsonObject.

/**
 * Gets the JsonObject representation of the given field object.
 *
 * @param field represents a template field
 * @return the json object
 */
private static JsonObject getFieldJsonObject(Field field) {
    JsonObject fieldObj = new JsonObject();
    fieldObj.add("type", field.getType());
    fieldObj.add("key", field.getKey());
    fieldObj.add("displayName", field.getDisplayName());
    String fieldDesc = field.getDescription();
    if (fieldDesc != null) {
        fieldObj.add("description", field.getDescription());
    }
    Boolean fieldIsHidden = field.getIsHidden();
    if (fieldIsHidden != null) {
        fieldObj.add("hidden", field.getIsHidden());
    }
    JsonArray array = new JsonArray();
    List<String> options = field.getOptions();
    if (options != null && !options.isEmpty()) {
        for (String option : options) {
            JsonObject optionObj = new JsonObject();
            optionObj.add("key", option);
            array.add(optionObj);
        }
        fieldObj.add("options", array);
    }
    return fieldObj;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 33 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTemplate method getFieldOperationJsonObject.

/**
 * Gets the JsonObject representation of the Field Operation.
 *
 * @param fieldOperation represents the template update operation
 * @return the json object
 */
private static JsonObject getFieldOperationJsonObject(FieldOperation fieldOperation) {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("op", fieldOperation.getOp().toString());
    String fieldKey = fieldOperation.getFieldKey();
    if (fieldKey != null) {
        jsonObject.add("fieldKey", fieldKey);
    }
    Field field = fieldOperation.getData();
    if (field != null) {
        JsonObject fieldObj = new JsonObject();
        String type = field.getType();
        if (type != null) {
            fieldObj.add("type", type);
        }
        String key = field.getKey();
        if (key != null) {
            fieldObj.add("key", key);
        }
        String displayName = field.getDisplayName();
        if (displayName != null) {
            fieldObj.add("displayName", displayName);
        }
        String description = field.getDescription();
        if (description != null) {
            fieldObj.add("description", description);
        }
        Boolean hidden = field.getIsHidden();
        if (hidden != null) {
            fieldObj.add("hidden", hidden);
        }
        List<String> options = field.getOptions();
        if (options != null) {
            JsonArray array = new JsonArray();
            for (String option : options) {
                JsonObject optionObj = new JsonObject();
                optionObj.add("key", option);
                array.add(optionObj);
            }
            fieldObj.add("options", array);
        }
        Boolean copyInstanceOnItemCopy = field.getCopyInstanceOnItemCopy();
        if (copyInstanceOnItemCopy != null) {
            fieldObj.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);
        }
        jsonObject.add("data", fieldObj);
    }
    List<String> fieldKeys = fieldOperation.getFieldKeys();
    if (fieldKeys != null) {
        jsonObject.add("fieldKeys", getJsonArray(fieldKeys));
    }
    List<String> enumOptionKeys = fieldOperation.getEnumOptionKeys();
    if (enumOptionKeys != null) {
        jsonObject.add("enumOptionKeys", getJsonArray(enumOptionKeys));
    }
    String enumOptionKey = fieldOperation.getEnumOptionKey();
    if (enumOptionKey != null) {
        jsonObject.add("enumOptionKey", enumOptionKey);
    }
    String multiSelectOptionKey = fieldOperation.getMultiSelectOptionKey();
    if (multiSelectOptionKey != null) {
        jsonObject.add("multiSelectOptionKey", multiSelectOptionKey);
    }
    List<String> multiSelectOptionKeys = fieldOperation.getMultiSelectOptionKeys();
    if (multiSelectOptionKeys != null) {
        jsonObject.add("multiSelectOptionKeys", getJsonArray(multiSelectOptionKeys));
    }
    return jsonObject;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 34 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTemplate method updateMetadataTemplate.

/**
 * Updates the schema of an existing metadata template.
 *
 * @param api             the API connection to be used
 * @param scope           the scope of the object
 * @param template        Unique identifier of the template
 * @param fieldOperations the fields that needs to be updated / added in the template
 * @return the updated metadata template
 */
public static MetadataTemplate updateMetadataTemplate(BoxAPIConnection api, String scope, String template, List<FieldOperation> fieldOperations) {
    JsonArray array = new JsonArray();
    for (FieldOperation fieldOperation : fieldOperations) {
        JsonObject jsonObject = getFieldOperationJsonObject(fieldOperation);
        array.add(jsonObject);
    }
    URL url = METADATA_TEMPLATE_URL_TEMPLATE.buildAlpha(api.getBaseURL(), scope, template);
    BoxJSONRequest request = new BoxJSONRequest(api, url, "PUT");
    request.setBody(array.toString());
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJson = Json.parse(response.getJSON()).asObject();
    return new MetadataTemplate(responseJson);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Example 35 with JsonArray

use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.

the class MetadataTemplate method createMetadataTemplate.

/**
 * Creates new metadata template.
 *
 * @param api                    the API connection to be used.
 * @param scope                  the scope of the object.
 * @param templateKey            a unique identifier for the template.
 * @param displayName            the display name of the field.
 * @param hidden                 whether this template is hidden in the UI.
 * @param fields                 the ordered set of fields for the template
 * @param copyInstanceOnItemCopy determines whether the copy operation should copy the metadata along with the item.
 * @return the metadata template returned from the server.
 */
public static MetadataTemplate createMetadataTemplate(BoxAPIConnection api, String scope, String templateKey, String displayName, Boolean hidden, List<Field> fields, Boolean copyInstanceOnItemCopy) {
    JsonObject jsonObject = new JsonObject();
    jsonObject.add("scope", scope);
    jsonObject.add("displayName", displayName);
    if (hidden != null) {
        jsonObject.add("hidden", hidden);
    }
    if (copyInstanceOnItemCopy != null) {
        jsonObject.add("copyInstanceOnItemCopy", copyInstanceOnItemCopy);
    }
    if (templateKey != null) {
        jsonObject.add("templateKey", templateKey);
    }
    JsonArray fieldsArray = new JsonArray();
    if (fields != null && !fields.isEmpty()) {
        for (Field field : fields) {
            JsonObject fieldObj = getFieldJsonObject(field);
            fieldsArray.add(fieldObj);
        }
        jsonObject.add("fields", fieldsArray);
    }
    URL url = METADATA_TEMPLATE_SCHEMA_URL_TEMPLATE.build(api.getBaseURL());
    BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
    request.setBody(jsonObject.toString());
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    return new MetadataTemplate(responseJSON);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Aggregations

JsonArray (com.eclipsesource.json.JsonArray)111 JsonObject (com.eclipsesource.json.JsonObject)96 JsonValue (com.eclipsesource.json.JsonValue)32 Test (org.junit.Test)30 URL (java.net.URL)28 ArrayList (java.util.ArrayList)27 HashMap (java.util.HashMap)11 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)5 Map (java.util.Map)5 Link (org.eclipse.leshan.Link)4 Date (java.util.Date)3 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)3 ClientEndPointDTO (com.hazelcast.internal.management.dto.ClientEndPointDTO)2 MalformedURLException (java.net.MalformedURLException)2 DecimalFormat (java.text.DecimalFormat)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)2 Collection (java.util.Collection)2 HashSet (java.util.HashSet)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2