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());
}
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations