Search in sources :

Example 36 with JsonArray

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

the class BoxSearchParameters method formatBoxMetadataFilterRequest.

/**
 * Add BoxMetaDataFilter to the JsonArray boxMetadataFilterRequestArray.
 *
 * @return JsonArray that is formated Json request
 */
private JsonArray formatBoxMetadataFilterRequest() {
    JsonArray boxMetadataFilterRequestArray = new JsonArray();
    JsonObject boxMetadataFilter = new JsonObject().add("templateKey", this.metadataFilter.getTemplateKey()).add("scope", this.metadataFilter.getScope()).add("filters", this.metadataFilter.getFiltersList());
    boxMetadataFilterRequestArray.add(boxMetadataFilter);
    return boxMetadataFilterRequestArray;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 37 with JsonArray

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

the class BoxUser method getMemberships.

/**
 * Gets information about all of the group memberships for this user.
 * Does not support paging.
 *
 * <p>Note: This method is only available to enterprise admins.</p>
 *
 * @return a collection of information about the group memberships for this user.
 */
public Collection<BoxGroupMembership.Info> getMemberships() {
    BoxAPIConnection api = this.getAPI();
    URL url = USER_MEMBERSHIPS_URL_TEMPLATE.build(this.getAPI().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<BoxGroupMembership.Info> memberships = new ArrayList<>(entriesCount);
    JsonArray entries = responseJSON.get("entries").asArray();
    for (JsonValue entry : entries) {
        JsonObject entryObject = entry.asObject();
        BoxGroupMembership membership = new BoxGroupMembership(api, entryObject.get("id").asString());
        BoxGroupMembership.Info info = membership.new Info(entryObject);
        memberships.add(info);
    }
    return memberships;
}
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 38 with JsonArray

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

the class BoxUser method toTrackingCodesJson.

private static JsonArray toTrackingCodesJson(Map<String, String> trackingCodes) {
    JsonArray trackingCodesJsonArray = new JsonArray();
    for (String attrKey : trackingCodes.keySet()) {
        JsonObject trackingCode = new JsonObject();
        trackingCode.set("type", "tracking_code");
        trackingCode.set("name", attrKey);
        trackingCode.set("value", trackingCodes.get(attrKey));
        trackingCodesJsonArray.add(trackingCode);
    }
    return trackingCodesJsonArray;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 39 with JsonArray

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

the class BoxSearch method searchRange.

/**
 * 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<BoxItem.Info> searchRange(long offset, long limit, final BoxSearchParameters bsp) {
    QueryStringBuilder builder = bsp.getQueryParameters().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<BoxItem.Info> results = 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) {
            results.add(parsedItemInfo);
        }
    }
    return results;
}
Also used : JsonValue(com.eclipsesource.json.JsonValue) JsonObject(com.eclipsesource.json.JsonObject) URL(java.net.URL) JsonArray(com.eclipsesource.json.JsonArray)

Example 40 with JsonArray

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

the class BoxSignRequest method createSignRequest.

/**
 * Used to create a new sign request with optional parameters.
 *
 * @param api            the API connection to be used by the created user.
 * @param signers        the list of signers for this sign request.
 * @param sourceFiles    the list of files to a signing document from.
 * @param parentFolderId the id of the destination folder to place sign request specific data in.
 * @param optionalParams the optional parameters.
 * @return the created sign request's info.
 */
public static BoxSignRequest.Info createSignRequest(BoxAPIConnection api, List<BoxSignRequestFile> sourceFiles, List<BoxSignRequestSigner> signers, String parentFolderId, BoxSignRequestCreateParams optionalParams) {
    JsonObject requestJSON = new JsonObject();
    JsonArray sourceFilesJSON = new JsonArray();
    for (BoxSignRequestFile sourceFile : sourceFiles) {
        sourceFilesJSON.add(sourceFile.getJSONObject());
    }
    requestJSON.add("source_files", sourceFilesJSON);
    JsonArray signersJSON = new JsonArray();
    for (BoxSignRequestSigner signer : signers) {
        signersJSON.add(signer.getJSONObject());
    }
    requestJSON.add("signers", signersJSON);
    JsonObject parentFolderJSON = new JsonObject();
    parentFolderJSON.add("id", parentFolderId);
    parentFolderJSON.add("type", "folder");
    requestJSON.add("parent_folder", parentFolderJSON);
    if (optionalParams != null) {
        optionalParams.appendParamsAsJson(requestJSON);
    }
    URL url = SIGN_REQUESTS_URL_TEMPLATE.build(api.getBaseURL());
    BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
    request.setBody(requestJSON.toString());
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
    BoxSignRequest signRequest = new BoxSignRequest(api, responseJSON.get("id").asString());
    return signRequest.new Info(responseJSON);
}
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