Skip to content
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
20 changes: 20 additions & 0 deletions src/main/java/com/box/sdk/BoxFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD
return info.getSharedLink();
}

/**
* Creates new SharedLink for a BoxFile with a password.
*
* @param access The access level of the shared link.
* @param unshareDate A specified date to unshare the Box file.
* @param permissions The permissions to set on the shared link for the Box file.
* @param password Password set on the shared link to give access to the Box file.
* @return information about the newly created shared link.
*/
public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate,
BoxSharedLink.Permissions permissions, String password) {

BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password);
Info info = new Info();
info.setSharedLink(sharedLink);

this.updateInfo(info);
return info.getSharedLink();
}

/**
* Adds new {@link BoxWebHook} to this {@link BoxFile}.
*
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/box/sdk/BoxFolder.java
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,26 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD
return info.getSharedLink();
}

/**
* Creates new SharedLink for a BoxFolder with a password.
*
* @param access The access level of the shared link.
* @param unshareDate A specified date to unshare the Box folder.
* @param permissions The permissions to set on the shared link for the Box folder.
* @param password Password set on the shared link to give access to the Box folder.
* @return information about the newly created shared link.
*/
public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate,
BoxSharedLink.Permissions permissions, String password) {

BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password);
Info info = new Info();
info.setSharedLink(sharedLink);

this.updateInfo(info);
return info.getSharedLink();
}

/**
* Gets information about all of the collaborations for this folder.
*
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/box/sdk/BoxSharedLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class BoxSharedLink extends BoxJSONObject {
private String downloadUrl;
private String vanityUrl;
private boolean isPasswordEnabled;
private String password;
private Date unsharedAt;
private long downloadCount;
private long previewCount;
Expand Down Expand Up @@ -46,6 +47,16 @@ public BoxSharedLink(String json) {
this.setUnsharedDate(unshareDate);
}
}
BoxSharedLink(BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions,
String password) {
this.setAccess(access);
this.setPermissions(permissions);
this.setPassword(password);

if (unshareDate != null) {
this.setUnsharedDate(unshareDate);
}
}

/**
* Get the URL of this shared link.
Expand Down Expand Up @@ -129,6 +140,15 @@ public void setAccess(Access access) {
this.addPendingChange("access", access.toJSONValue());
}

/**
* Sets the password of this shared link.
* @param password the password of this shared link.
*/
public void setPassword(String password) {
this.password = password;
this.addPendingChange("password", password.toString());
}

/**
* Gets the effective access level of this shared link.
* @return the effective access level of this shared link.
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/box/sdk/BoxWebLink.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@ public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareD
return info.getSharedLink();
}

/**
* Creates new SharedLink for a BoxWebLink with a password.
*
* @param access The access level of the shared link.
* @param unshareDate A specified date to unshare the Box web link.
* @param permissions The permissions to set on the shared link for the Box web link.
* @param password Password set on the shared link to give access to the Box web link.
* @return information about the newly created shared link.
*/
public BoxSharedLink createSharedLink(BoxSharedLink.Access access, Date unshareDate,
BoxSharedLink.Permissions permissions, String password) {

BoxSharedLink sharedLink = new BoxSharedLink(access, unshareDate, permissions, password);
Info info = new Info();
info.setSharedLink(sharedLink);

this.updateInfo(info);
return info.getSharedLink();
}

@Override
public BoxWebLink.Info copy(BoxFolder destination) {
return this.copy(destination, null);
Expand Down
82 changes: 82 additions & 0 deletions src/test/Fixtures/BoxFile/CreateSharedLinkWithPassword201.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"type": "file",
"id": "1111",
"file_version": {
"type": "file_version",
"id": "2222",
"sha1": "a9225c82fdce3e5701111976de462c22a76df7ee"
},
"sequence_id": "1",
"etag": "1",
"sha1": "a9225c82fdce3e5701111976de462c22a76df7ee",
"name": "test.png",
"description": "",
"size": 2882774,
"path_collection": {
"total_count": 2,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
{
"type": "folder",
"id": "3333",
"sequence_id": "0",
"etag": "0",
"name": "Test Folder"
}
]
},
"created_at": "2018-07-02T10:29:20-07:00",
"modified_at": "2018-07-02T10:29:22-07:00",
"trashed_at": null,
"purged_at": null,
"content_created_at": "2018-04-30T15:36:09-07:00",
"content_modified_at": "2018-04-30T15:36:09-07:00",
"created_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@example.com"
},
"modified_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@example.com"
},
"owned_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@example.com"
},
"shared_link": {
"url": "https://testt3t2t2t2.box.com/s/12345",
"download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png",
"vanity_url": null,
"effective_access": "open",
"effective_permission": "can_download",
"is_password_enabled": true,
"unshared_at": null,
"download_count": 0,
"preview_count": 0,
"access": "open",
"permissions": {
"can_preview": true,
"can_download": true
}
},
"parent": {
"type": "folder",
"id": "5555",
"sequence_id": "0",
"etag": "0",
"name": "Test Folder"
},
"item_status": "active"
}
18 changes: 18 additions & 0 deletions src/test/Fixtures/BoxSharedLink/CreateSharedLink201.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"shared_link": {
"url": "https://testt3t2t2t2.box.com/s/12345",
"download_url": "https://testt3t2t2t2.box.com/shared/static/12345.png",
"vanity_url": null,
"effective_access": "open",
"effective_permission": "can_download",
"is_password_enabled": true,
"unshared_at": null,
"download_count": 0,
"preview_count": 0,
"access": "open",
"permissions": {
"can_preview": true,
"can_download": true
}
}
}
37 changes: 37 additions & 0 deletions src/test/java/com/box/sdk/BoxFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1394,6 +1394,43 @@ public void testUploadNewVersionReturnsCorrectInfo() throws IOException {
Assert.assertEquals(fileName, info.getName());
}

@Test
@Category(UnitTest.class)
public void createSharedLinkSucceeds() throws IOException {
final String fileID = "1111";
final String password = "test1";
String result = "";

JsonObject permissionsObject = new JsonObject()
.add("can_download", true)
.add("can_preview", true);

JsonObject innerObject = new JsonObject()
.add("password", password)
.add("access", "open")
.add("permissions", permissionsObject);

JsonObject sharedLinkObject = new JsonObject()
.add("shared_link", innerObject);

result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/files/" + fileID))
.withRequestBody(WireMock.equalToJson(sharedLinkObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withBody(result)));

BoxFile file = new BoxFile(this.api, fileID);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();

permissions.setCanDownload(true);
permissions.setCanPreview(true);
BoxSharedLink sharedLink = file.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions,
password);
Assert.assertEquals(true, sharedLink.getIsPasswordEnabled());
}

private BoxFile.Info parallelMuliputUpload(File file, BoxFolder folder, String fileName)
throws IOException, InterruptedException {
FileInputStream newStream = new FileInputStream(file);
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/box/sdk/BoxFolderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,44 @@ public void testGetAllMetadataSucceeds() throws IOException {
Assert.assertEquals(scope, metadata.getScope());
}

@Test
@Category(UnitTest.class)
public void createSharedLinkSucceeds() throws IOException {
final String folderID = "1111";
final String password = "test1";
String result = "";

JsonObject permissionsObject = new JsonObject()
.add("can_download", true)
.add("can_preview", true);

JsonObject innerObject = new JsonObject()
.add("password", password)
.add("access", "open")
.add("permissions", permissionsObject);

JsonObject sharedLinkObject = new JsonObject()
.add("shared_link", innerObject);

result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/folders/" + folderID))
.withRequestBody(WireMock.equalToJson(sharedLinkObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withBody(result)));

BoxFolder folder = new BoxFolder(this.api, folderID);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();

permissions.setCanDownload(true);
permissions.setCanPreview(true);
BoxSharedLink sharedLink = folder.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions,
password);

Assert.assertEquals(true, sharedLink.getIsPasswordEnabled());
}

private void getUploadSessionStatus(BoxFileUploadSession session) {
BoxFileUploadSession.Info sessionInfo = session.getStatus();
Assert.assertNotNull(sessionInfo.getSessionExpiresAt());
Expand Down
38 changes: 38 additions & 0 deletions src/test/java/com/box/sdk/BoxWebLinkTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,42 @@ public void testDeleteWebLinkSucceeds() throws IOException {
BoxWebLink webLink = new BoxWebLink(this.api, webLinkID);
webLink.delete();
}

@Test
@Category(UnitTest.class)
public void createSharedLinkSucceeds() throws IOException {
final String webLinkID = "1111";
final String password = "test1";
String result = "";

JsonObject permissionsObject = new JsonObject()
.add("can_download", true)
.add("can_preview", true);

JsonObject innerObject = new JsonObject()
.add("password", password)
.add("access", "open")
.add("permissions", permissionsObject);

JsonObject sharedLinkObject = new JsonObject()
.add("shared_link", innerObject);

result = TestConfig.getFixture("BoxSharedLink/CreateSharedLink201");

WIRE_MOCK_CLASS_RULE.stubFor(WireMock.put(WireMock.urlPathEqualTo("/web_links/" + webLinkID))
.withRequestBody(WireMock.equalToJson(sharedLinkObject.toString()))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withBody(result)));

BoxWebLink webLink = new BoxWebLink(this.api, webLinkID);
BoxSharedLink.Permissions permissions = new BoxSharedLink.Permissions();

permissions.setCanDownload(true);
permissions.setCanPreview(true);
BoxSharedLink sharedLink = webLink.createSharedLink(BoxSharedLink.Access.OPEN, null, permissions,
password);

Assert.assertEquals(true, sharedLink.getIsPasswordEnabled());
}
}