Search in sources :

Example 86 with JsonValue

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

the class BoxCollaboration method getPendingCollaborations.

/**
 * Gets all pending collaboration invites for the current user.
 *
 * @param api the API connection to use.
 * @return a collection of pending collaboration infos.
 */
public static Collection<Info> getPendingCollaborations(BoxAPIConnection api) {
    URL url = PENDING_COLLABORATIONS_URL.build(api.getBaseURL());
    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 : JsonArray(com.eclipsesource.json.JsonArray) ArrayList(java.util.ArrayList) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Example 87 with JsonValue

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

the class BoxTermsOfService method getAllTermsOfServices.

/**
 * Retrieves a list of Terms of Service that belong to your Enterprise as an Iterable.
 *
 * @param api                api the API connection to be used by the resource.
 * @param termsOfServiceType the type of terms of service to be retrieved. Can be set to "managed" or "external"
 * @return the Iterable of Terms of Service in an Enterprise that match the filter parameters.
 */
public static List<BoxTermsOfService.Info> getAllTermsOfServices(final BoxAPIConnection api, BoxTermsOfService.TermsOfServiceType termsOfServiceType) {
    QueryStringBuilder builder = new QueryStringBuilder();
    if (termsOfServiceType != null) {
        builder.appendParam("tos_type", termsOfServiceType.toString());
    }
    URL url = ALL_TERMS_OF_SERVICES_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString());
    BoxAPIRequest request = new BoxAPIRequest(api, url, "GET");
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    int totalCount = responseJSON.get("total_count").asInt();
    List<BoxTermsOfService.Info> termsOfServices = new ArrayList<>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject termsOfServiceJSON = value.asObject();
        BoxTermsOfService termsOfService = new BoxTermsOfService(api, termsOfServiceJSON.get("id").asString());
        BoxTermsOfService.Info info = termsOfService.new Info(termsOfServiceJSON);
        termsOfServices.add(info);
    }
    return termsOfServices;
}
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 88 with JsonValue

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

the class BoxTask method getAssignments.

/**
 * Gets any assignments for this task.
 *
 * @return a list of assignments for this task.
 */
public List<BoxTaskAssignment.Info> getAssignments() {
    URL url = GET_ASSIGNMENTS_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<BoxTaskAssignment.Info> assignments = new ArrayList<>(totalCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue value : entries) {
        JsonObject assignmentJSON = value.asObject();
        BoxTaskAssignment assignment = new BoxTaskAssignment(this.getAPI(), assignmentJSON.get("id").asString());
        BoxTaskAssignment.Info info = assignment.new Info(assignmentJSON);
        assignments.add(info);
    }
    return assignments;
}
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 89 with JsonValue

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

the class BoxRecentItem method parseJSONMember.

@Override
protected void parseJSONMember(JsonObject.Member member) {
    super.parseJSONMember(member);
    String memberName = member.getName();
    JsonValue value = member.getValue();
    try {
        if (memberName.equals("type")) {
            this.type = value.asString();
        } else if (memberName.equals("interaction_type")) {
            this.interactionType = value.asString();
        } else if (memberName.equals("item")) {
            String id = value.asObject().get("id").asString();
            this.item = new BoxFile(this.api, id).new Info(value.asObject());
        } else if (memberName.equals("interacted_at")) {
            this.interactedAt = BoxDateFormat.parse(value.asString());
        } else if (memberName.equals("interaction_shared_link")) {
            this.interactionSharedLink = new URL(value.asString());
        }
    } catch (ParseException e) {
        assert false : "A ParseException indicates a bug in the SDK.";
    } catch (MalformedURLException e) {
        assert false : "A ParseException indicates a bug in the SDK.";
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) JsonValue(com.eclipsesource.json.JsonValue) ParseException(java.text.ParseException) URL(java.net.URL)

Example 90 with JsonValue

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

the class BoxSearch method searchRangeIncludeSharedLinks.

/**
 * Searches all descendant folders using a given query and query parameters.
 *
 * @param offset is the starting position.
 * @param limit  the maximum number of items to return. The default is 30 and the maximum is 200.
 * @param bsp    containing query and advanced search capabilities.
 * @return a PartialCollection containing the search results.
 */
public PartialCollection<BoxSearchSharedLink> searchRangeIncludeSharedLinks(long offset, long limit, final BoxSearchParameters bsp) {
    QueryStringBuilder builder = bsp.getQueryParameters().appendParam("include_recent_shared_links", "true").appendParam("limit", limit).appendParam("offset", offset);
    URL url = SEARCH_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString());
    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<BoxSearchSharedLink> results = new PartialCollection<>(offset, limit, fullSize);
    JsonArray jsonArray = responseJSON.get("entries").asArray();
    for (JsonValue value : jsonArray) {
        JsonObject jsonObject = value.asObject();
        BoxSearchSharedLink parsedItem = new BoxSearchSharedLink(jsonObject, this.getAPI());
        results.add(parsedItem);
    }
    return results;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL)

Aggregations

JsonValue (com.eclipsesource.json.JsonValue)149 JsonObject (com.eclipsesource.json.JsonObject)76 JsonArray (com.eclipsesource.json.JsonArray)44 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 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)4 Field (java.lang.reflect.Field)3 InetSocketAddress (java.net.InetSocketAddress)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