-
Notifications
You must be signed in to change notification settings - Fork 188
Multizones #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Multizones #598
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
26133da
init for boxstoragepolicy and boxstoragepolicyassignment
2316c91
completes storage policy and updated assignments
e004609
finished first implementation for storage assignment
7026ba0
docs for storage policy
6d23cfb
updates to storage policy readme
4bdca60
added tests for storage policy and storage policy assignment
cf2782d
completed documentation for storage policy/assignment and updated get…
ffa50cb
tests for assignment switched to wiremock
6529e26
storage policy test
b84f73d
bug fixes to storage policies
0fcfd41
completed final testing for multizones
724c193
removed unnecessary new line
72f7c69
fixed lint errors
32ccf7d
fixed all lint errors
d3d04ea
updated update test
c9c73f7
updated from feedback
716c9c6
Merge branch 'master' into multizones
d26ea77
Merge branch 'master' of https://github.com/box/box-java-sdk into mul…
45f3280
fixed from feedback
5f7d36f
Merge branch 'multizones' of https://github.com/box/box-java-sdk into…
e020bf8
updated tests
f1bfac3
feedback fixes
684da34
fixed from feedback
e94af5b
Merge branch 'master' into multizones
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| Storage Policy | ||
| ============== | ||
|
|
||
| Allows the enterprise admin to manage the Storage Policies for users in their | ||
| enterprise. Used for an enterprise to decide storage location for users based on | ||
| where they work/reside. | ||
|
|
||
| * [Get Storage Policy](#get-storage-policy) | ||
| * [Get List of Storage Policies](#get-list-of-storage-policies) | ||
| * [Create New Assignment](#create-new-assignment) | ||
| * [Get Assignment](#get-assignment) | ||
| * [Get Assignment For Target](#get-assignment-for-target) | ||
| * [Update Existing Assignment](#update-existing-assignment) | ||
| * [Assign Storage Policy](#assign-storage-policy) | ||
| * [Delete Assignment](#delete-assignment) | ||
|
|
||
| Get Storage Policy | ||
| ------------------ | ||
|
|
||
| Calling [`getInfo(String fields ...)`][get-info] will return BoxStoragePolicy.Info object | ||
| containing information about the storage policy. If necessary to retrieve | ||
| limited set of fields. It is possible to specify them using param. | ||
|
|
||
| ```java | ||
| BoxStoragePolicy storagePolicy = new BoxStoragePolicy(api, id); | ||
| BoxStoragePolicy.Info storagePolicyInfo = storagePolicy.getInfo(); | ||
| ``` | ||
|
|
||
| [get-info]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicy.html#getInfo-- | ||
|
|
||
| Get List of Storage Policies | ||
| ---------------------------- | ||
|
|
||
| Calling the static [`getAll(BoxAPIConnection api)`][get-list-of-storage-policies] | ||
| will return an iterable that will page through all of the storage policies. | ||
| It is possible to specify maximum number of items per response and fields to retrieve by | ||
| calling the static [`getAll(BoxAPIConnection api, int limit, String fields ...)`][get-list-of-storage-policies-with-fields] method. | ||
|
|
||
| ```java | ||
| Iterable<BoxStoragePolicy.Info> storagePolicies = BoxStoragePolicy.getAll(api); | ||
| for (BoxStoragePolicy.Info storagePolicyInfo : storagePolicies) { | ||
| //Do something with the storage policy. | ||
| } | ||
| ``` | ||
|
|
||
| [get-list-of-storage-policies]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicy.html#getAll-- | ||
| [get-list-of-storage-policies-with-fields]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicy.html#getAll-java.lang.String...- | ||
|
|
||
| Create New Assignment | ||
| --------------------- | ||
|
|
||
| To create new storage policy assignment call [`create(BoxAPIConnection api, String policyID, String userID)`][create] method. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment.Info assignmentInfo = BoxStoragePolicyAssignment.create(api, policyID, userID); | ||
| ``` | ||
|
|
||
| [create]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssignment.html#create-com.box.sdk.BoxAPIConnection-java.lang.String-java.lang.String- | ||
|
|
||
| Update Existing Assignment | ||
| -------------------------- | ||
|
|
||
| Updating a storage policy assignment information is done by calling | ||
| [`updateInfo(BoxStoragePolicyAssignment.Info updatedInfo)`][update-info]. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment storagePolicyAssignment = new BoxStoragePolicyAssignment(api, "ASSIGNMENT_ID"); | ||
| BoxStoragePolicyAssignment.Info assignmentInfo = storagePolicyAssignment.new Info(); | ||
| assignmentInfo.setStoragePolicyID("NEW_STORAGE_POLICY_ID"); | ||
| storagePolicyAssignment.updateInfo(assignmentInfo); | ||
| ``` | ||
|
|
||
| [update-info]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssignment.html#updateInfo-com.box.sdk.BoxStoragePolicyAssignment.Info- | ||
|
|
||
| Get Assignment | ||
| -------------- | ||
|
|
||
| Calling [`getInfo(String fields ...)`][get-assignment] will return a BoxStoragePolicyAssignment.Info object containing information | ||
| about the storage policy assignment. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment storagePolicyAssignment = new BoxStoragePolicyAssignment(api, id); | ||
| BoxStoragePolicyAssignment.Info assignmentInfo = storagePolicyAssignment.getInfo(); | ||
| ``` | ||
|
|
||
| [get-assignment]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssignment.html#getInfo-- | ||
|
|
||
| Get Assignment for Target | ||
| ------------------------- | ||
|
|
||
| Calling [`getAssignmentForTarget(BoxAPIConnection api, String resolvedForType, String resolvedForID)`][get-assignment-for-target] will return a BoxStorageAssignment.Info | ||
| object containing information about the storage policy assignment. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment.Info assignmentInfo = BoxStoragePolicyAssignment.getAssignmentForTarget(api, "user", "1234") | ||
| ``` | ||
|
|
||
| [get-assignment-for-target]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssignment.html#getAssignmentForTarget-com.box.BoxAPIConnection-java.lang.String-java.lang.String- | ||
|
|
||
| Assign Storage Policy | ||
| --------------------- | ||
|
|
||
| Calling [`assign(BoxAPIConnection api, String storagePolicyID, String userID)`][assign] will check if this user already has storage policy assigned to them. If not then a new | ||
| this user will be assigned the specified storage policy. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment.Info assignmentInfo = BoxStoragePolicyAssignment.assign(api, "1234", "5678"); | ||
| ``` | ||
|
|
||
| [assign]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssigbment.html#assign-com.box.BoxAPIConnection-java.lang.String-java.lang.String- | ||
|
|
||
| Delete Assignment | ||
| ----------------- | ||
|
|
||
| Calling [`delete()`][delete] will remove the storage policy assignment from the user. | ||
|
|
||
| ```java | ||
| BoxStoragePolicyAssignment assignment = new BoxStoragePolicyAssignment(api, "dXNlcl8xMjM0"); | ||
| assignment.delete(); | ||
| ``` | ||
|
|
||
| [delete]:http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxStoragePolicyAssignment.html#delete-- | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| package com.box.sdk; | ||
|
|
||
| import java.net.URL; | ||
|
|
||
| import com.eclipsesource.json.JsonObject; | ||
| import com.eclipsesource.json.JsonValue; | ||
| import com.eclipsesource.json.ParseException; | ||
|
|
||
| /** | ||
| * Represents a BoxStoragePolicy. | ||
| */ | ||
| @BoxResourceType("storage_policy") | ||
| public class BoxStoragePolicy extends BoxResource { | ||
|
|
||
| /** | ||
| * Storage Policies URL Template. | ||
| */ | ||
| public static final URLTemplate STORAGE_POLICY_URL_TEMPLATE = new URLTemplate("storage_policies"); | ||
|
|
||
| /** | ||
| * Storage Policies URL Template. | ||
| */ | ||
| public static final URLTemplate STORAGE_POLICY_WITH_ID_URL_TEMPLATE = new URLTemplate("storage_policies/%s"); | ||
|
|
||
| /** | ||
| * The default limit of entries per response. | ||
| */ | ||
| private static final int DEFAULT_LIMIT = 100; | ||
|
|
||
| /** | ||
| * Constructs a BoxStoragePolicy with a given ID. | ||
| * | ||
| * @param api the API connection to be used by the BoxStoragePolicy. | ||
| * @param id the ID of the BoxStoragePolicy. | ||
| */ | ||
| public BoxStoragePolicy(BoxAPIConnection api, String id) { | ||
| super(api, id); | ||
| } | ||
|
|
||
| /** | ||
| * Gets information for a Box Storage Policy with optional fields. | ||
| * | ||
| * @param fields the fields to retrieve. | ||
| * @return info about this item containing only the specified fields, including storage policy. | ||
| */ | ||
| public BoxStoragePolicy.Info getInfo(String... fields) { | ||
| QueryStringBuilder builder = new QueryStringBuilder(); | ||
| if (fields.length > 0) { | ||
| builder.appendParam("fields", fields); | ||
| } | ||
| URL url = STORAGE_POLICY_WITH_ID_URL_TEMPLATE.buildWithQuery(this.getAPI().getBaseURL(), builder.toString(), | ||
| this.getID()); | ||
|
|
||
| BoxAPIRequest request = new BoxAPIRequest(this.getAPI(), url, "GET"); | ||
| BoxJSONResponse response = (BoxJSONResponse) request.send(); | ||
| return new Info(response.getJSON()); | ||
| } | ||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably also add an |
||
| /** | ||
| * Returns all BoxStoragePolicy with specified fields. | ||
| * | ||
| * @param api the API connection to be used by the resource. | ||
| * @param fields the fields to retrieve. | ||
| * @return an iterable with all the storage policies met search conditions. | ||
| */ | ||
| public static Iterable<BoxStoragePolicy.Info> getAll(final BoxAPIConnection api, String... fields) { | ||
|
|
||
| return getAll(api, DEFAULT_LIMIT, fields); | ||
| } | ||
|
|
||
| /** | ||
| * Returns all BoxStoragePolicy with specified fields. | ||
| * | ||
| * @param api the API connection to be used by the resource. | ||
| * @param limit the limit of items per single response. The default is 100. | ||
| * @param fields the fields to retrieve. | ||
| * @return an iterable with all the storage policies met search conditions. | ||
| */ | ||
| public static Iterable<BoxStoragePolicy.Info> getAll(final BoxAPIConnection api, int limit, String... fields) { | ||
|
|
||
| QueryStringBuilder builder = new QueryStringBuilder(); | ||
| if (fields.length > 0) { | ||
| builder.appendParam("fields", fields); | ||
| } | ||
|
|
||
| URL url = STORAGE_POLICY_URL_TEMPLATE.buildWithQuery(api.getBaseURL(), builder.toString()); | ||
| return new BoxResourceIterable<BoxStoragePolicy.Info>(api, url, limit) { | ||
|
|
||
| @Override | ||
| protected BoxStoragePolicy.Info factory(JsonObject jsonObject) { | ||
| BoxStoragePolicy storagePolicy = new BoxStoragePolicy(api, jsonObject.get("id").asString()); | ||
|
|
||
| return storagePolicy.new Info(jsonObject); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Checks if there is already a Storage Policy Assignment and creates one if one does not exist. | ||
| * @param userID the ID of the user you want to assign the Storage Policy to. | ||
| * @return information about this {@link BoxStoragePolicyAssignment}. | ||
| */ | ||
| public BoxStoragePolicyAssignment.Info assign(String userID) { | ||
| return BoxStoragePolicyAssignment.assign(this.getAPI(), this.getID(), userID); | ||
| } | ||
|
|
||
| /** | ||
| * Contains information about the BoxStoragePolicy. | ||
| */ | ||
| public class Info extends BoxResource.Info { | ||
|
|
||
| /** | ||
| * @see #getStoragePolicyName() | ||
| */ | ||
| private String storagePolicyName; | ||
|
|
||
| /** | ||
| * Constructs an empty Info object. | ||
| */ | ||
| public Info() { | ||
| super(); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs an Info object by parsing information from a JSON string. | ||
| * | ||
| * @param json the JSON string to parse. | ||
| */ | ||
| public Info(String json) { | ||
| super(json); | ||
| } | ||
|
|
||
| /** | ||
| * Constructs an Info object using an already parsed JSON object. | ||
| * | ||
| * @param jsonObject the parsed JSON object. | ||
| */ | ||
| Info(JsonObject jsonObject) { | ||
| super(jsonObject); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| @Override | ||
| public BoxStoragePolicy getResource() { | ||
| return BoxStoragePolicy.this; | ||
| } | ||
|
|
||
| /** | ||
| * @return the name of the storage policy. | ||
| */ | ||
| public String getStoragePolicyName() { | ||
| return this.storagePolicyName; | ||
| } | ||
|
|
||
| @Override | ||
| void parseJSONMember(JsonObject.Member member) { | ||
| super.parseJSONMember(member); | ||
| String memberName = member.getName(); | ||
| JsonValue value = member.getValue(); | ||
| try { | ||
| if (memberName.equals("name")) { | ||
| this.storagePolicyName = value.asString(); | ||
| } | ||
| } catch (ParseException e) { | ||
| assert false : "A ParseException indicates a bug in the SDK."; | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This link needs a URL