Search in sources :

Example 76 with JsonArray

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

the class BoxSignRequestCreateParams method appendParamsAsJson.

/**
 * Used to append BoxSignRequestCreateParams to request.
 *
 * @param requestJSON request in json to append data to.
 */
public void appendParamsAsJson(JsonObject requestJSON) {
    JsonUtils.addIfNotNull(requestJSON, "is_document_preparation_needed", this.isDocumentPreparationNeeded);
    JsonUtils.addIfNotNull(requestJSON, "are_text_signatures_enabled", this.areTextSignaturesEnabled);
    JsonUtils.addIfNotNull(requestJSON, "are_dates_enabled", this.areDatesEnabled);
    JsonUtils.addIfNotNull(requestJSON, "signature_color", this.signatureColor);
    JsonUtils.addIfNotNull(requestJSON, "email_subject", this.emailSubject);
    JsonUtils.addIfNotNull(requestJSON, "email_message", this.emailMessage);
    JsonUtils.addIfNotNull(requestJSON, "are_reminders_enabled", this.areRemindersEnabled);
    JsonUtils.addIfNotNull(requestJSON, "name", this.name);
    JsonUtils.addIfNotNull(requestJSON, "days_valid", this.daysValid);
    JsonUtils.addIfNotNull(requestJSON, "external_id", this.externalId);
    if (this.prefillTags != null) {
        JsonArray prefillTagsJSON = new JsonArray();
        for (BoxSignRequestPrefillTag prefillTag : this.prefillTags) {
            prefillTagsJSON.add(prefillTag.getJSONObject());
        }
        requestJSON.add("prefill_tags", prefillTagsJSON);
    }
    return;
}
Also used : JsonArray(com.eclipsesource.json.JsonArray)

Example 77 with JsonArray

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

the class BoxGroup method getCollaborations.

/**
 * Gets information about all of the collaborations for this group.
 *
 * @return a collection of information about the collaborations for this group.
 */
public Collection<BoxCollaboration.Info> getCollaborations() {
    BoxAPIConnection api = this.getAPI();
    URL url = COLLABORATIONS_URL_TEMPLATE.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 78 with JsonArray

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

the class BoxRetentionPolicyAssignment method createAssignmentToMetadata.

/**
 * Assigns a retention policy to all items with a given metadata template, optionally matching on fields.
 *
 * @param api        the API connection to be used by the created assignment.
 * @param policyID   id of the assigned retention policy.
 * @param templateID the ID of the metadata template to assign the policy to.
 * @param startDateField  The date the retention policy assignment begins. This field can be a date field's metadata attribute key id.
 * @param filter     optional fields to match against in the metadata template.
 * @return info about the created assignment.
 */
public static BoxRetentionPolicyAssignment.Info createAssignmentToMetadata(BoxAPIConnection api, String policyID, String templateID, String startDateField, MetadataFieldFilter... filter) {
    JsonObject assignTo = new JsonObject().add("type", TYPE_METADATA).add("id", templateID);
    JsonArray filters = null;
    if (filter.length > 0) {
        filters = new JsonArray();
        for (MetadataFieldFilter f : filter) {
            filters.add(f.getJsonObject());
        }
    }
    return createAssignment(api, policyID, assignTo, startDateField, filters);
}
Also used : JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject)

Example 79 with JsonArray

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

Example 80 with JsonArray

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

the class BoxFolder method setCollections.

@Override
public BoxFolder.Info setCollections(BoxCollection... collections) {
    JsonArray jsonArray = new JsonArray();
    for (BoxCollection collection : collections) {
        JsonObject collectionJSON = new JsonObject();
        collectionJSON.add("id", collection.getID());
        jsonArray.add(collectionJSON);
    }
    JsonObject infoJSON = new JsonObject();
    infoJSON.add("collections", jsonArray);
    String queryString = new QueryStringBuilder().appendParam("fields", ALL_FIELDS).toString();
    URL url = FOLDER_INFO_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), queryString, this.getID());
    BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT");
    request.setBody(infoJSON.toString());
    BoxJSONResponse response = (BoxJSONResponse) request.send();
    JsonObject jsonObject = Json.parse(response.getJSON()).asObject();
    return new Info(jsonObject);
}
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