-
Notifications
You must be signed in to change notification settings - Fork 186
Metadata cascade policy #603
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
Conversation
|
Hi @carycheng, thanks for the pull request. Before we can merge it, we need you to sign our Contributor License Agreement. You can do so electronically here: http://opensource.box.com/cla Once you have signed, just add a comment to this pull request saying, "CLA signed". Thanks! |
doc/folders.md
Outdated
| BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, 'folder-id', 'metadata-scope', 'example-template-key'); | ||
| ``` | ||
|
|
||
| [create-policy]: |
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.
Remember to add the actual link URLs here!
doc/folders.md
Outdated
| with the api connection, scope, template key of the metadata template to be cascaded, and the ID of the folder to apply the policy to. | ||
|
|
||
| ```java | ||
| BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, 'folder-id', 'metadata-scope', 'example-template-key'); |
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.
Can we use more realistic values for the parameter values in these examples? One way might be to do something like:
String folderID = "22222";
String scope = "enterprise";
String templateKey = "myTemplate";
BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, folderID, scope, templateKey);Also, remember that strings in Java are double-quoted — the example you have here wouldn't compile.
doc/folders.md
Outdated
| You can also set the `owner_enterprise_id` option to retrieve only cascade policies owned by a specific enterprise(defaults to the current enterprise). | ||
|
|
||
| ```java | ||
| BoxMetadataCascadePolicy.getAll(api, 'folder-id', 'owner-enterprise-id', 100); |
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.
What's the last parameter here? The full signature of this method should be documented here somewhere.
doc/folders.md
Outdated
| will overwrite values on items in the folder with the metadata value from the folder. | ||
|
|
||
| ```java | ||
| BoxMetadataCascadePolicy.forceApply(api, 'none', 'cascade-policy-id'); |
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.
Remember that "none" needs to be double-quoted here
|
|
||
| /** | ||
| * Deletes this collaboration. | ||
| * Deletes this collanboration. |
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.
Typo: "collanboration"
| /** | ||
| * Represents a Metadata Cascade Policy. | ||
| */ | ||
| @BoxResourceType("") |
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.
Does this need to have a value filled in?
| * @param conflictResolution the desired behavior for conflict-resolution. Set to either none or overwrite. | ||
| * @param cascadePolicyID the ID of the metadata cascade policy. | ||
| */ | ||
| public static void forceApply(final BoxAPIConnection api, String conflictResolution, |
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 should probably be an instance method, not static, since it uses the ID of a specific cascade policy. That way it wouldn't need to take in the ID as a parameter
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.
Remember to make this non-static!
| public static void forceApply(final BoxAPIConnection api, String conflictResolution, | ||
| String cascadePolicyID) { | ||
| QueryStringBuilder builder = new QueryStringBuilder(); | ||
| builder.appendParam("id", cascadePolicyID); |
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.
The ID is a path param, not a query parameter
doc/folders.md
Outdated
| ```java | ||
| String folderID = "2222"; | ||
| String enterpriseID = "1234"; | ||
| BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100); |
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.
You should make this more like a real-world use case by assigning this to some variable to show what type comes out of this method
| * @param conflictResolution the desired behavior for conflict-resolution. Set to either none or overwrite. | ||
| * @param cascadePolicyID the ID of the metadata cascade policy. | ||
| */ | ||
| public static void forceApply(final BoxAPIConnection api, String conflictResolution, |
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.
Remember to make this non-static!
| /** | ||
| * Represents a Metadata Cascade Policy. | ||
| */ | ||
| public class BoxMetadataCascadePolicy extends BoxResource { |
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.
Since we're waiting to ship until the API has a type field, you can probably just put the resource decorator back here and use the expected value of "metadata_cascade_policy"
Pull Request Test Coverage Report for Build 1725
💛 - Coveralls |
doc/folders.md
Outdated
| BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, folderID, scope, templateKey); | ||
| ``` | ||
|
|
||
| [create-policy]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxMetadataCascadePolicy.html#create-com.box.sdk.BoxAPIConnection-java.lang.String-java.lang.String-java.lang.String |
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.
These URLs should always have a trailing -
doc/folders.md
Outdated
| String folderID = "22222"; | ||
| String scope = "enterprise"; | ||
| String templateKey = "myTemplate"; | ||
| BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, folderID, scope, templateKey); |
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.
Can we update this example to use the new BoxFolder method?
doc/folders.md
Outdated
|
|
||
| [create-policy]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxMetadataCascadePolicy.html#create-com.box.sdk.BoxAPIConnection-java.lang.String-java.lang.String-java.lang.String | ||
|
|
||
| Get a Cascade Policies Information |
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.
Should use Policy's here
doc/folders.md
Outdated
| ``` | ||
|
|
||
| You can also call [`getAll(BoxAPIConnection api, String folderID, String enterpriseID, int limit)`][get-all-with-limit] | ||
| and set the `enterpriseID` option to retrieve only cascade policies owned by a specific enterprise(defaults to the current enterprise). |
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.
We might want to clarify that the method call above only gets cascade policies from the current enterprise; this overload allows getting those from another enterprise
doc/folders.md
Outdated
| ```java | ||
| String folderID = "2222"; | ||
| String enterpriseID = "1234"; | ||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100); |
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.
Can you double-check the return type here? I think it might be Iterable instead of Iterator
| * @param templateKey the key of the template. | ||
| * @return information about the Metadata Cascade Policy. | ||
| */ | ||
| public BoxMetadataCascadePolicy.Info createCascadePolicyOnFolder(String scope, String templateKey) { |
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.
The OnFolder part of this method name is redundant — this is a method on BoxFolder, after all
| * @param fields optional fields to retrieve for cascade policies. | ||
| * @return the Iterable of Box Metadata Cascade Policies in your enterprise. | ||
| */ | ||
| public static Iterable<BoxMetadataCascadePolicy.Info> getAll(final BoxAPIConnection api, |
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 static method should also be aliased as an instance method on BoxFolder
|
|
||
| @Test | ||
| @Category(UnitTest.class) | ||
| public void testCreateMetadataCascadePolicySucceedsSendsCorrectJson() throws IOException { |
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.
We should also add a test for the BoxFolder instance method version of this call
|
|
||
| @Test | ||
| @Category(UnitTest.class) | ||
| public void testGetAllMetadataCascadePoliciesSucceeds() throws IOException { |
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.
After you add an instance method version of this call on BoxFolder, add a test for that method as well (should mostly be able to copy/paste this test)
| .withHeader("Content-Type", "application/json") | ||
| .withBody(result))); | ||
|
|
||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = |
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 doesn't exercise the optional params — those should also have a test to make sure they get passed correctly
doc/folders.md
Outdated
| To set a metadata policy, which applies metadata values on a folder to new items in the folder, call | ||
| [`create(BoxAPIConnection api, String folderID, String scope, String templateKey)`][create-policy] | ||
| with the api connection, scope, template key of the metadata template to be cascaded, and the ID of the folder to apply the policy to. | ||
| [`createCascadePolicy(String scope, String template)`][create-cascade-policy]. |
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.
We might want to document what object this method is called on
doc/folders.md
Outdated
| String templateKey = "template"; | ||
| String folderId = "12345"; | ||
| BoxFolder folder = new BoxFolder(api, folderId); | ||
| BoxMetadataCascadePolicy.Info cascadePolicyInfo = folder.createCascadePolicyOnFolder(scope, template); |
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.
The method name here should match the one documented above
doc/folders.md
Outdated
| String folderID = "2222"; | ||
| BoxMetadataCascadePolicy.getAll(api, folderID); | ||
| BoxFolder folder = new BoxFolder(api, folderID); | ||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = folder.getCascadePolicies().iterator(); |
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.
Most users aren't going to manually call .iterator() here — it might be more illustrative to show how to use this with a for-in loop
doc/folders.md
Outdated
|
|
||
| You can also call [`getAll(BoxAPIConnection api, String folderID, String enterpriseID, int limit)`][get-all-with-limit] | ||
| and set the `enterpriseID` option to retrieve only cascade policies owned by a specific enterprise(defaults to the current enterprise). | ||
| and set the `enterpriseID` option set to retrieve metadata cascade policies from another enterprise. |
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.
"set the enterpriseID option set" should be reworded
doc/folders.md
Outdated
| String folderID = "2222"; | ||
| String enterpriseID = "1234"; | ||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100); | ||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100).iterator(); |
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 example should probably also use a for-in loop to capture the common use case
doc/folders.md
Outdated
|
|
||
| If you already have a Box folder object, you can add a Metadata Cascade Policy by using, | ||
| [`createCascadePolicyOnFolder()`][create-cascade-policy-on-folder]. | ||
| You can also set a metadata policy on a folder by calling |
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.
I don't think we really need to document both of these
|
|
||
| @Test | ||
| @Category(UnitTest.class) | ||
| public void testAddMetadataCascadePolicySucceedsSendsCorrectJson() throws IOException { |
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 test should probably live in the BoxFolderTest.java file
|
|
||
| @Test | ||
| @Category(UnitTest.class) | ||
| public void testGetAllMetadataCascadePoliciesOnFolderSucceeds() throws IOException { |
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 test should also probably live in BoxFolderTest.java
| * @param fields optional fields to retrieve for cascade policies. | ||
| * @return the Iterable of Box Metadata Cascade Policies in your enterprise. | ||
| */ | ||
| public Iterable<BoxMetadataCascadePolicy.Info> getCascadePolicies(String... fields) { |
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.
We should have an overload of this that allows passing in the owner enterprise ID
| public void testForceApplyMetadataCascadePolicySucceedsAndSendsCorrectJson() { | ||
| final String conflictResolution = "none"; | ||
| final String cascadePolicyID = "12345"; | ||
| final String forceApplyURL = "/metadata_cascade_policies/" + cascadePolicyID; |
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 URL needs a /apply at the end
| BoxMetadataCascadePolicy.Info policyInfo = BoxMetadataCascadePolicy | ||
| .create(this.getAPI(), this.getID(), scope, templateKey); | ||
|
|
||
| return policyInfo; |
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.
You can condense this onto one line with the above if you want
| * @param templateKey the key of the template. | ||
| * @return information about the Metadata Cascade Policy. | ||
| */ | ||
| public BoxMetadataCascadePolicy.Info createCascadePolicy(String scope, String templateKey) { |
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.
We should probably add "Metadata" to the name here, e.g. addMetadataCascadePolicy()
No description provided.