use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxFile method getComments.
/**
* Gets a list of any comments on this file.
*
* @return a list of comments on this file.
*/
public List<BoxComment.Info> getComments() {
URL url = GET_COMMENTS_URL_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int totalCount = responseJSON.get("total_count").asInt();
List<BoxComment.Info> comments = new ArrayList<>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject commentJSON = value.asObject();
BoxComment comment = new BoxComment(this.getAPI(), commentJSON.get("id").asString());
BoxComment.Info info = comment.new Info(commentJSON);
comments.add(info);
}
return comments;
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxFile method getTasks.
/**
* Gets a list of any tasks on this file with requested fields.
*
* @param fields optional fields to retrieve for this task.
* @return a list of tasks on this file.
*/
public List<BoxTask.Info> getTasks(String... fields) {
QueryStringBuilder builder = new QueryStringBuilder();
if (fields.length > 0) {
builder.appendParam("fields", fields);
}
URL url = GET_TASKS_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int totalCount = responseJSON.get("total_count").asInt();
List<BoxTask.Info> tasks = new ArrayList<>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject taskJSON = value.asObject();
BoxTask task = new BoxTask(this.getAPI(), taskJSON.get("id").asString());
BoxTask.Info info = task.new Info(taskJSON);
tasks.add(info);
}
return tasks;
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxFileUploadSessionPartList method parseJSONMember.
@Override
protected void parseJSONMember(JsonObject.Member member) {
String memberName = member.getName();
JsonValue value = member.getValue();
if (memberName.equals("entries")) {
JsonArray array = (JsonArray) value;
if (array.size() > 0) {
this.entries = this.getParts(array);
}
} else if (memberName.equals("offset")) {
this.offset = Double.valueOf(value.toString()).intValue();
} else if (memberName.equals("limit")) {
this.limit = Double.valueOf(value.toString()).intValue();
} else if (memberName.equals("total_count")) {
this.totalCount = Double.valueOf(value.toString()).intValue();
}
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxFolder method getCollaborations.
/**
* Gets information about all of the collaborations for this folder.
*
* @return a collection of information about the collaborations for this folder.
*/
public Collection<BoxCollaboration.Info> getCollaborations() {
BoxAPIConnection api = this.getAPI();
URL url = GET_COLLABORATIONS_URL.build(api.getBaseURL(), this.getID());
BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
int entriesCount = responseJSON.get("total_count").asInt();
Collection<BoxCollaboration.Info> collaborations = new ArrayList<>(entriesCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue entry : entries) {
JsonObject entryObject = entry.asObject();
BoxCollaboration collaboration = new BoxCollaboration(api, entryObject.get("id").asString());
BoxCollaboration.Info info = collaboration.new Info(entryObject);
collaborations.add(info);
}
return collaborations;
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxFolder method uploadFile.
/**
* Uploads a new file to this folder with custom upload parameters.
*
* @param uploadParams the custom upload parameters.
* @return the uploaded file's info.
*/
public BoxFile.Info uploadFile(FileUploadParams uploadParams) {
URL uploadURL = UPLOAD_FILE_URL.build(this.getAPI().getBaseUploadURL());
BoxMultipartRequest request = new BoxMultipartRequest(getAPI(), uploadURL);
JsonObject fieldJSON = new JsonObject();
JsonObject parentIdJSON = new JsonObject();
parentIdJSON.add("id", getID());
fieldJSON.add("name", uploadParams.getName());
fieldJSON.add("parent", parentIdJSON);
if (uploadParams.getCreated() != null) {
fieldJSON.add("content_created_at", BoxDateFormat.format(uploadParams.getCreated()));
}
if (uploadParams.getModified() != null) {
fieldJSON.add("content_modified_at", BoxDateFormat.format(uploadParams.getModified()));
}
if (uploadParams.getSHA1() != null && !uploadParams.getSHA1().isEmpty()) {
request.setContentSHA1(uploadParams.getSHA1());
}
if (uploadParams.getDescription() != null) {
fieldJSON.add("description", uploadParams.getDescription());
}
request.putField("attributes", fieldJSON.toString());
if (uploadParams.getSize() > 0) {
request.setFile(uploadParams.getContent(), uploadParams.getName(), uploadParams.getSize());
} else if (uploadParams.getContent() != null) {
request.setFile(uploadParams.getContent(), uploadParams.getName());
} else {
request.setUploadFileCallback(uploadParams.getUploadFileCallback(), uploadParams.getName());
}
BoxJSONResponse response;
if (uploadParams.getProgressListener() == null) {
response = (BoxJSONResponse) request.send();
} else {
response = (BoxJSONResponse) request.send(uploadParams.getProgressListener());
}
JsonObject collection = Json.parse(response.getJSON()).asObject();
JsonArray entries = collection.get("entries").asArray();
JsonObject fileInfoJSON = entries.get(0).asObject();
String uploadedFileID = fileInfoJSON.get("id").asString();
BoxFile uploadedFile = new BoxFile(getAPI(), uploadedFileID);
return uploadedFile.new Info(fileInfoJSON);
}
Aggregations