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