Skip to content
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

Added convenience function for shared link and fixed setting null bug #720

Merged
merged 2 commits into from
Jul 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions doc/files.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ file's contents, upload new versions, and perform other common file operations
- [Download a File](#download-a-file)
- [Upload a File](#upload-a-file)
- [Upload Preflight Check](#upload-preflight-check)
- [Upload a Large File in Chunks](#upload-a-large-file-in-chunks)
- [Upload a Large File Version in Chunks](#upload-a-large-file-version-in-chunks)
- [Upload a Large File Or File Version Manually](#upload-a-large-file-or-file-version-manually)
- [Move a File](#move-a-file)
Expand All @@ -23,11 +22,11 @@ file's contents, upload new versions, and perform other common file operations
- [Get Previous Versions of a File](#get-previous-versions-of-a-file)
- [Upload a New Version of a File](#upload-a-new-version-of-a-file)
- [Download a Previous Version of a File](#download-a-previous-version-of-a-file)
- [Promote a Previous Version of a File](#promote-a-previous-version-of-a-file)
- [Delete a Previous Version of a File](#delete-a-previous-version-of-a-file)
- [Lock a File](#lock-a-file)
- [Unlock a File](#unlock-a-file)
- [Create a Shared Link](#create-a-shared-link)
- [Remove a Shared Link](#remove-a-shared-link)
- [Add a Collaborator](#add-a-collaborator)
- [Get an Embed Link](#get-an-embed-link)
- [Get Thumbnail](#get-thumbnail)
Expand Down Expand Up @@ -576,6 +575,20 @@ BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null

[create-shared-link]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxFile.html#createSharedLink-com.box.sdk.BoxSharedLink.Access-java.util.Date-com.box.sdk.BoxSharedLink.Permissions-

Remove a Shared Link
carycheng marked this conversation as resolved.
Show resolved Hide resolved
--------------------

A shared link for a file can be removed by calling [`removeSharedLink()`][remove-shared-link].

```java
BoxFile file = new BoxFile(api, "12345")
BoxFile.Info info = file.getInfo()
info.removeSharedLink()
file.updateInfo(info)
```

[remove-shared-link]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxFile.html#removeSharedLink--

Add a Collaborator
------------------

Expand Down
17 changes: 15 additions & 2 deletions doc/folders.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ group, and perform other common folder operations (move, copy, delete, etc.).
- [Rename a Folder](#rename-a-folder)
- [Delete a Folder](#delete-a-folder)
- [Created a Shared Link for a Folder](#created-a-shared-link-for-a-folder)
- [Remove a Shared Link for a Folder](#remove-a-shared-link-for-a-folder)
- [Share a Folder](#share-a-folder)
- [Get All Collaborations for a Folder](#get-all-collaborations-for-a-folder)
- [Create Metadata](#create-metadata)
- [Set Metadata](#set-metadata)
- [Get Metadata](#get-metadata)
- [Update Metadata](#update-metadata)
- [Delete Metadata](#delete-metadata)
- [Get All Metadata on Folder](#get-all-metadata-on-folder)
- [Get Metadata for Multiple Files](#get-metadata-for-multiple-files)
Expand Down Expand Up @@ -266,6 +265,20 @@ folder.updateInfo(info);

[create-shared-link]: https://box.github.io/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#createSharedLink-com.box.sdk.BoxSharedLink.Access-java.util.Date-com.box.sdk.BoxSharedLink.Permissions-

Remove a Shared Link for a Folder
---------------------------------

You can remove a shared link for a folder by calling the [`removeSharedLink`](remove-shared-link) method.

```java
BoxFolder folder = new BoxFolder(api, "12345");
BoxFolder.Info info = folder.getInfo();
info.removeSharedLink()
folder.updateInfo(info)
```

[remove-shared-link]: https://box.github.io/box-java-sdk/javadoc/com/box/sdk/BoxFolder.html#removeSharedLink--

Share a Folder
--------------

Expand Down
32 changes: 31 additions & 1 deletion doc/weblinks.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ webLink.updateInfo(webLinkInfo);

[update-web-link]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxWebLink.html#updateInfo-com.box.sdk.BoxWebLink.Info-

Create a Shared Link
--------------------

You can create a shared link for a web link by calling the
[`createSharedLink(BoxSharedLink.Access accessLevel, Date expirationDate, BoxSharedLink.Permissions permissions)`][create-shared-link]
method.

```java
BoxWebLink webLink = new BoxWebLink(api, "id");
SharedLink link = webLink.createSharedLink(BoxSharedLink.Access.OPEN, null,
permissions);
```

[create-shared-link]: https://box.github.io/box-java-sdk/javadoc/com/box/sdk/BoxWebLink.html#createSharedLink-com.box.sdk.BoxSharedLink.Access-java.util.Date-com.box.sdk.BoxSharedLink.Permissions-

Remove a Shared Link
--------------------

You can remove a shared link for a web link by calling the [`removeSharedLink`](remove-shared-link) method.

```java
BoxWebLink webLink = new BoxWebLink(api, "12345");
BoxWebLink.Info webLinkInfo = webLink.getInfo();
info.removeSharedLink()
webLink.updateInfo(info)
```

[remove-shared-link]: https://box.github.io/box-java-sdk/javadoc/com/box/sdk/BoxWebLink.html#removeSharedLink--


Delete Web Link
---------------

Expand All @@ -82,4 +112,4 @@ BoxWebLink webLink = new BoxWebLink(api, id);
webLink.delete();
```

[delete]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxWebLink.html#delete--
[delete]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxWebLink.html#delete--
11 changes: 7 additions & 4 deletions src/main/java/com/box/sdk/BoxItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,18 @@ public BoxSharedLink getSharedLink() {
* @param sharedLink the shared link for the item.
*/
public void setSharedLink(BoxSharedLink sharedLink) {
if (this.sharedLink == sharedLink) {
return;
}

this.removeChildObject("shared_link");
this.sharedLink = sharedLink;
this.addChildObject("shared_link", sharedLink);
}

/**
* Removes the shared link for the item.
*/
public void removeSharedLink() {
this.addChildObject("shared_link", null);
}

/**
* Gets a unique ID for use with the {@link EventStream}.
* @return a unique ID for use with the EventStream.
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/com/box/sdk/BoxFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,32 @@ public void testGetFileInfoSucceeds() throws IOException {
Assert.assertTrue(info.getHasCollaborations());
}

@Test
@Category(UnitTest.class)
public void testRemoveSharedLink() throws IOException {
String getResult = "";
String putResult = "";
final String fileID = "12345";
final String fileURL = "/files/" + fileID;
JsonObject jsonObject = new JsonObject()
.add("shared_link", (String) null);

putResult = TestConfig.getFixture("BoxFile/GetFileInfo200");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo(fileURL))
.withRequestBody(WireMock.containing(jsonObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withBody(putResult)));

BoxFile file = new BoxFile(this.api, fileID);
BoxFile.Info info = file.new Info();
info.removeSharedLink();
file.updateInfo(info);

Assert.assertNull("Shared Link was not removed", info.getSharedLink());
}

@Test
@Category(UnitTest.class)
public void testGetTasksWithFields() throws IOException {
Expand Down