Search in sources :

Example 21 with JsonArray

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;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Example 22 with JsonArray

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;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 23 with JsonArray

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();
    }
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonValue(com.eclipsesource.json.JsonValue)

Example 24 with JsonArray

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;
}
Also used : ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 25 with JsonArray

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