Metadata cascade policy - #603
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! |
| BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, 'folder-id', 'metadata-scope', 'example-template-key'); | ||
| ``` | ||
|
|
||
| [create-policy]: |
There was a problem hiding this comment.
Remember to add the actual link URLs here!
| 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.
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.
| 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.
What's the last parameter here? The full signature of this method should be documented here somewhere.
| 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.
Remember that "none" needs to be double-quoted here
|
|
||
| /** | ||
| * Deletes this collaboration. | ||
| * Deletes this collanboration. |
| /** | ||
| * Represents a Metadata Cascade Policy. | ||
| */ | ||
| @BoxResourceType("") |
There was a problem hiding this comment.
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.
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
| 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.
The ID is a path param, not a query parameter
| ```java | ||
| String folderID = "2222"; | ||
| String enterpriseID = "1234"; | ||
| BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100); |
There was a problem hiding this comment.
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, |
| /** | ||
| * Represents a Metadata Cascade Policy. | ||
| */ | ||
| public class BoxMetadataCascadePolicy extends BoxResource { |
There was a problem hiding this comment.
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 |
| 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.
These URLs should always have a trailing -
| 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.
Can we update this example to use the new BoxFolder method?
|
|
||
| [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 |
| ``` | ||
|
|
||
| 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.
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
| ```java | ||
| String folderID = "2222"; | ||
| String enterpriseID = "1234"; | ||
| Iterator<BoxMetadataCascadePolicy.Info> metadataCascadePolicies = BoxMetadataCascadePolicy.getAll(api, folderID, enterpriseID, 100); |
There was a problem hiding this comment.
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.
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.
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.
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.
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.
This doesn't exercise the optional params — those should also have a test to make sure they get passed correctly
| 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.
We might want to document what object this method is called on
| 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.
The method name here should match the one documented above
| 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.
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
|
|
||
| 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.
"set the enterpriseID option set" should be reworded
| 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.
This example should probably also use a for-in loop to capture the common use case
|
|
||
| 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.
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.
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.
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.
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; |
| BoxMetadataCascadePolicy.Info policyInfo = BoxMetadataCascadePolicy | ||
| .create(this.getAPI(), this.getID(), scope, templateKey); | ||
|
|
||
| return policyInfo; |
There was a problem hiding this comment.
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.
We should probably add "Metadata" to the name here, e.g. addMetadataCascadePolicy()
No description provided.