use of com.eclipsesource.json.JsonArray 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;
}
use of com.eclipsesource.json.JsonArray 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;
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxRetentionPolicy method createRetentionPolicy.
/**
* Used to create a new retention policy with optional parameters.
*
* @param api the API connection to be used by the created user.
* @param name the name of the retention policy.
* @param type the type of the retention policy. Can be "finite" or "indefinite".
* @param length the duration in days that the retention policy will be active for after being assigned to content.
* @param action the disposition action can be "permanently_delete" or "remove_retention".
* @param optionalParams the optional parameters.
* @return the created retention policy's info.
*/
private static BoxRetentionPolicy.Info createRetentionPolicy(BoxAPIConnection api, String name, BoxRetentionPolicyType type, int length, BoxRetentionPolicyAction action, RetentionPolicyParams optionalParams) {
URL url = RETENTION_POLICIES_URL_TEMPLATE.build(api.getBaseURL());
BoxJSONRequest request = new BoxJSONRequest(api, url, "POST");
JsonObject requestJSON = new JsonObject().add("policy_name", name).add("policy_type", type.value).add("disposition_action", action.value);
if (type != BoxRetentionPolicyType.Indefinite) {
requestJSON.add("retention_length", length);
}
if (optionalParams != null) {
requestJSON.add("can_owner_extend_retention", optionalParams.getCanOwnerExtendRetention());
requestJSON.add("are_owners_notified", optionalParams.getAreOwnersNotified());
requestJSON.add("description", optionalParams.getDescription());
List<BoxUser.Info> customNotificationRecipients = optionalParams.getCustomNotificationRecipients();
if (customNotificationRecipients.size() > 0) {
JsonArray users = new JsonArray();
for (BoxUser.Info user : customNotificationRecipients) {
JsonObject userJSON = new JsonObject().add("type", "user").add("id", user.getID());
users.add(userJSON);
}
requestJSON.add("custom_notification_recipients", users);
}
}
request.setBody(requestJSON.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = Json.parse(response.getJSON()).asObject();
BoxRetentionPolicy createdPolicy = new BoxRetentionPolicy(api, responseJSON.get("id").asString());
return createdPolicy.new Info(responseJSON);
}
use of com.eclipsesource.json.JsonArray 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;
}
use of com.eclipsesource.json.JsonArray in project box-java-sdk by box.
the class BoxUser method getEmailAliases.
/**
* Gets a collection of all the email aliases for this user.
*
* <p>Note that the user's primary login email is not included in the collection of email aliases.</p>
*
* @return a collection of all the email aliases for this user.
*/
public Collection<EmailAlias> getEmailAliases() {
URL url = EMAIL_ALIASES_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();
Collection<EmailAlias> emailAliases = new ArrayList<>(totalCount);
JsonArray entries = responseJSON.get("entries").asArray();
for (JsonValue value : entries) {
JsonObject emailAliasJSON = value.asObject();
emailAliases.add(new EmailAlias(emailAliasJSON));
}
return emailAliases;
}
Aggregations