close
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
10 changes: 6 additions & 4 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ Move User's Folder
------------------

To move all of a user's content to another user, call the
[`moveFolderToUser(String destinationUserID)`][move-folder-to-user] method.
[`transferContent(String destinationUserID)`][transfer-folder-to-new-user] method.

```java
BoxUser user = new BoxUser(api, "0");
BoxFolder.Info folderInfo = user.moveFolderToUser("1");
String sourceUserID = "11111";
String destinationUserID = "22222";
BoxUser sourceUser = new BoxUser(api, sourceUserID);
BoxFolder.Info transferredFolderInfo = sourceUser.transferContent(destinationUserID);
```

[move-folder-to-user]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxUser.html#moveFolderToUser-java.lang.String-
[transfer-folder-to-new-user]: http://opensource.box.com/box-java-sdk/javadoc/com/box/sdk/BoxUser.html#transferContent-java.lang.String-
30 changes: 30 additions & 0 deletions src/main/java/com/box/sdk/BoxUser.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ public void updateInfo(BoxUser.Info info) {
}

/**
* @deprecated As of release 2.22.0, replaced by {@link #transferContent(String)} ()}
*
*
* Moves all of the owned content from within one user’s folder into a new folder in another user's account.
* You can move folders across users as long as the you have administrative permissions and the 'source'
* user owns the folders. Per the documentation at the link below, this will move everything from the root
Expand All @@ -448,6 +451,7 @@ public void updateInfo(BoxUser.Info info) {
* @param sourceUserID the user id of the user whose files will be the source for this operation
* @return info for the newly created folder
*/
@Deprecated
public BoxFolder.Info moveFolderToUser(String sourceUserID) {
// Currently the API only supports moving of the root folder (0), hence the hard coded "0"
URL url = MOVE_FOLDER_TO_USER_TEMPLATE.build(this.getAPI().getBaseURL(), sourceUserID, "0");
Expand All @@ -464,6 +468,32 @@ public BoxFolder.Info moveFolderToUser(String sourceUserID) {
return movedFolder.new Info(responseJSON);
}

/**
* Moves all of the owned content from within one user’s folder into a new folder in another user's account.
* You can move folders across users as long as the you have administrative permissions and the 'source'
* user owns the folders. Per the documentation at the link below, this will move everything from the root
* folder, as this is currently the only mode of operation supported.
*
* See also https://box-content.readme.io/reference#move-folder-into-another-users-folder
*
* @param destinationUserID the user id of the user that you wish to transfer content to.
* @return info for the newly created folder.
*/
public BoxFolder.Info transferContent(String destinationUserID) {
URL url = MOVE_FOLDER_TO_USER_TEMPLATE.build(this.getAPI().getBaseURL(), this.getID(), "0");
BoxJSONRequest request = new BoxJSONRequest(this.getAPI(), url, "PUT");
JsonObject destinationUser = new JsonObject();
destinationUser.add("id", destinationUserID);
JsonObject ownedBy = new JsonObject();
ownedBy.add("owned_by", destinationUser);
request.setBody(ownedBy.toString());
BoxJSONResponse response = (BoxJSONResponse) request.send();
JsonObject responseJSON = JsonObject.readFrom(response.getJSON());
BoxFolder movedFolder = new BoxFolder(this.getAPI(), responseJSON.get("id").asString());

return movedFolder.new Info(responseJSON);
}


/**
* Enumerates the possible roles that a user can have within an enterprise.
Expand Down
71 changes: 71 additions & 0 deletions src/test/Fixtures/BoxFolder/PutTransferFolder200.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"type": "folder",
"id": "0",
"sequence_id": "0",
"etag": "0",
"name": "Example Test Folder",
"created_at": "2018-04-24T12:50:03-07:00",
"modified_at": "2018-04-24T12:50:03-07:00",
"description": "",
"size": 0,
"path_collection": {
"total_count": 1,
"entries": [
{
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
}
]
},
"created_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@user.com"
},
"modified_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@user.com"
},
"trashed_at": null,
"purged_at": null,
"content_created_at": "2018-04-24T12:50:03-07:00",
"content_modified_at": "2018-04-24T12:50:03-07:00",
"owned_by": {
"type": "user",
"id": "1111",
"name": "Test User",
"login": "test@user.com"
},
"shared_link": null,
"folder_upload_email": null,
"parent": {
"type": "folder",
"id": "0",
"sequence_id": null,
"etag": null,
"name": "All Files"
},
"item_status": "active",
"item_collection": {
"total_count": 0,
"entries": [],
"offset": 0,
"limit": 100,
"order": [
{
"by": "type",
"direction": "ASC"
},
{
"by": "name",
"direction": "ASC"
}
]
}
}
32 changes: 32 additions & 0 deletions src/test/java/com/box/sdk/BoxUserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,36 @@ public void testGetAllEnterpriseUsersSucceeds() throws IOException {
Assert.assertEquals(secondUserName, secondUser.getName());
Assert.assertEquals(secondUserLogin, secondUser.getLogin());
}

@Test
@Category(UnitTest.class)
public void testTransferContent() throws IOException, InterruptedException {
String result = "";
final String sourceUserID = "1111";
final String destinationUserID = "5678";
final String createdByLogin = "test@user.com";
final String transferredFolderName = "Example Test Folder";
final String transferContentURL = "/users/" + sourceUserID + "/folders/0";

JsonObject destinationUser = new JsonObject()
.add("id", destinationUserID);
JsonObject ownedBy = new JsonObject()
.add("owned_by", destinationUser);

result = TestConfig.getFixture("BoxFolder/PutTransferFolder200");

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

Thread.sleep(5000);

BoxUser sourceUser = new BoxUser(this.api, sourceUserID);
BoxFolder.Info movedFolder = sourceUser.transferContent(destinationUserID);

Assert.assertEquals(transferredFolderName, movedFolder.getName());
Assert.assertEquals(createdByLogin, movedFolder.getCreatedBy().getLogin());
}
}