Skip to content

Conversation

@carycheng
Copy link

No description provided.

@carycheng carycheng requested a review from mattwiller May 8, 2018 17:42
@boxcla
Copy link

boxcla commented May 8, 2018

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!

@carycheng carycheng removed the request for review from mattwiller May 8, 2018 17:43
doc/folders.md Outdated
BoxMetadataCascadePolicy.Info metadataCascadePolicyInfo = BoxMetadataCascadePolicy.create(api, 'folder-id', 'metadata-scope', 'example-template-key');
```

[create-policy]:

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');

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

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');

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.

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("")

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,

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

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

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

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,

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 {

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"

@coveralls
Copy link

coveralls commented Aug 14, 2018

Pull Request Test Coverage Report for Build 1725

  • 82 of 93 (88.17%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.4%) to 58.554%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/main/java/com/box/sdk/BoxMetadataCascadePolicy.java 75 86 87.21%
Totals Coverage Status
Change from base Build 1713: 0.4%
Covered Lines: 4576
Relevant Lines: 7815

💛 - 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

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

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

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).

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

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) {

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,

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 {

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 {

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 =

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].

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

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();

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.

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();

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

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 {

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 {

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) {

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;

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;

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) {

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()

@mattwiller mattwiller dismissed their stale review August 23, 2018 21:19

Major changes have been addressed

@carycheng carycheng merged commit 8c72d75 into master Aug 23, 2018
@carycheng carycheng deleted the metadata_cascade_policy branch August 23, 2018 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants