Search in sources :

Example 81 with JsonValue

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

the class BoxZipDownloadStatus method parseJSONMember.

@Override
void parseJSONMember(JsonObject.Member member) {
    JsonValue value = member.getValue();
    String memberName = member.getName();
    if (memberName.equals("total_file_count")) {
        this.totalFileCount = value.asInt();
    } else if (memberName.equals("download_file_count")) {
        this.downloadFileCount = value.asInt();
    } else if (memberName.equals("skipped_file_count")) {
        this.skippedFileCount = value.asInt();
    } else if (memberName.equals("skipped_folder_count")) {
        this.skippedFolderCount = value.asInt();
    } else if (memberName.equals("state")) {
        this.state = State.fromJSONValue(value.asString());
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Example 82 with JsonValue

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

the class BoxFolder method updateExistingTemplate.

private Metadata updateExistingTemplate(String templateName, String scope, Metadata metadata) {
    Metadata metadataToUpdate = new Metadata(scope, templateName);
    for (JsonValue value : metadata.getOperations()) {
        if (value.asObject().get("value").isNumber()) {
            metadataToUpdate.add(value.asObject().get("path").asString(), value.asObject().get("value").asDouble());
        } else if (value.asObject().get("value").isString()) {
            metadataToUpdate.add(value.asObject().get("path").asString(), value.asObject().get("value").asString());
        } else if (value.asObject().get("value").isArray()) {
            ArrayList<String> list = new ArrayList<>();
            for (JsonValue jsonValue : value.asObject().get("value").asArray()) {
                list.add(jsonValue.asString());
            }
            metadataToUpdate.add(value.asObject().get("path").asString(), list);
        }
    }
    return this.updateMetadata(metadataToUpdate);
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) ArrayList(java.util.ArrayList)

Example 83 with JsonValue

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

the class BoxFolder method getChildrenRange.

/**
 * Retrieves a specific range of child items in this folder.
 *
 * @param offset the index of the first child item to retrieve.
 * @param limit  the maximum number of children to retrieve after the offset.
 * @param fields the fields to retrieve.
 * @return a partial collection containing the specified range of child items.
 */
public PartialCollection<BoxItem.Info> getChildrenRange(long offset, long limit, String... fields) {
    QueryStringBuilder builder = new QueryStringBuilder().appendParam("limit", limit).appendParam("offset", offset);
    if (fields.length > 0) {
        builder.appendParam("fields", fields);
    }
    URL url = GET_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), builder.toString(), getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    String totalCountString = responseJSON.get("total_count").toString();
    long fullSize = Double.valueOf(totalCountString).longValue();
    PartialCollection<BoxItem.Info> children = new PartialCollection<>(offset, limit, fullSize);
    JsonArray jsonArray = responseJSON.get("entries").asArray();
    for (JsonValue value : jsonArray) {
        JsonObject jsonObject = value.asObject();
        BoxItem.Info parsedItemInfo = (BoxItem.Info) BoxResource.parseInfo(this.getAPI(), jsonObject);
        if (parsedItemInfo != null) {
            children.add(parsedItemInfo);
        }
    }
    return children;
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 84 with JsonValue

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

the class BoxCollection method getItemsRange.

/**
 * Retrieves a specific range of items in this collection.
 *
 * @param offset the index of the first item to retrieve.
 * @param limit  the maximum number of items to retrieve after the offset.
 * @param fields the fields to retrieve.
 * @return a partial collection containing the specified range of items.
 */
public PartialCollection<BoxItem.Info> getItemsRange(long offset, long limit, String... fields) {
    QueryStringBuilder builder = new QueryStringBuilder().appendParam("offset", offset).appendParam("limit", limit);
    if (fields.length > 0) {
        builder.appendParam("fields", fields);
    }
    URL url = GET_COLLECTION_ITEMS_URL.buildWithQuery(getAPI().getBaseURL(), builder.toString(), getID());
    BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    String totalCountString = responseJSON.get("total_count").toString();
    long fullSize = Double.valueOf(totalCountString).longValue();
    PartialCollection<BoxItem.Info> items = new PartialCollection<>(offset, limit, fullSize);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        BoxItem.Info entryInfo = (BoxItem.Info) BoxResource.parseInfo(this.getAPI(), entry.asObject());
        if (entryInfo != null) {
            items.add(entryInfo);
        }
    }
    return items;
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 85 with JsonValue

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

the class BoxClassification method parseJSONMember.

@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("color")) {
            this.color = value.asString();
        } else if (memberName.equals("definition")) {
            this.definition = value.asString();
        } else if (memberName.equals("name")) {
            this.name = value.asString();
        }
    } catch (Exception e) {
        throw new BoxDeserializationException(memberName, value.toString(), e);
    }
}
Also used : JsonValue(com.eclipsesource.json.JsonValue)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)147 JsonObject (com.eclipsesource.json.JsonObject)74 JsonArray (com.eclipsesource.json.JsonArray)43 Test (org.junit.Test)38 ArrayList (java.util.ArrayList)26 URL (java.net.URL)21 HashMap (java.util.HashMap)10 IOException (java.io.IOException)9 Member (com.eclipsesource.json.JsonObject.Member)6 ParseException (com.eclipsesource.json.ParseException)4 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)4 InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 Map (java.util.Map)3 WebTarget (javax.ws.rs.client.WebTarget)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 JsonUtil.getString (com.hazelcast.util.JsonUtil.getString)2 WalletCallException (com.vaklinov.zcashui.ZCashClientCaller.WalletCallException)2 FileInputStream (java.io.FileInputStream)2