This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 051a5a4 CAMEL-11885: Add support for creating folder by path in camel-box 051a5a4 is described below commit 051a5a496c74664550f714dd0228580b4dae39e4 Author: Fredrik Jönsson <f...@kth.se> AuthorDate: Fri Oct 6 15:27:53 2017 +0200 CAMEL-11885: Add support for creating folder by path in camel-box --- .../camel/component/box/api/BoxFoldersManager.java | 39 +++++++++++++++++++++- .../src/main/docs/box-component.adoc | 2 ++ .../box/BoxFoldersManagerIntegrationTest.java | 19 +++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFoldersManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFoldersManager.java index b44fca9..dbe4e55 100644 --- a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFoldersManager.java +++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxFoldersManager.java @@ -163,7 +163,7 @@ public class BoxFoldersManager { } /** - * Create a folder in parent folder with given <code>folderName</code>. + * Create a folder in parent folder with given <code>parentFolderId</code>. * * @param parentFolderId * - the id of parent folder. @@ -189,6 +189,43 @@ public class BoxFoldersManager { } /** + * Create a folder specified by path from parent folder with given <code>parentFolderId</code>, + * creating intermediate directories as required. + * + * @param parentFolderId + * - the id of parent folder. + * @param path + * - Sequence of Box folder names from parent folder to returned + * folder. + * @return The last folder in path, no fault will be thrown if it already exists. + */ + public BoxFolder createFolder(String parentFolderId, String... path) { + try { + LOG.debug("Creating folder with path '" + path + "' in parent_folder(id=" + parentFolderId + ")"); + if (parentFolderId == null) { + throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null"); + } + if (path == null) { + throw new IllegalArgumentException("Paramerer 'path' can not be null"); + } + BoxFolder folder = new BoxFolder(boxConnection, parentFolderId); + searchPath: for (int folderIndex = 0; folderIndex < path.length; folderIndex++) { + for (BoxItem.Info itemInfo : folder) { + if (itemInfo instanceof BoxFolder.Info && itemInfo.getName().equals(path[folderIndex])) { + folder = (BoxFolder) itemInfo.getResource(); + continue searchPath; + } + } + folder = folder.createFolder(path[folderIndex]).getResource(); + } + return folder; + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** * Copy folder to destination folder while optionally giving it a new name. * * @param folderId diff --git a/components/camel-box/camel-box-component/src/main/docs/box-component.adoc b/components/camel-box/camel-box-component/src/main/docs/box-component.adoc index a423e7d..f8a68ae 100644 --- a/components/camel-box/camel-box-component/src/main/docs/box-component.adoc +++ b/components/camel-box/camel-box-component/src/main/docs/box-component.adoc @@ -422,6 +422,8 @@ box:folders/endpoint?[options] |createFolder |create |parentFolderId, folderName |com.box.sdk.BoxFolder +|createFolder |create |parentFolderId, path |com.box.sdk.BoxFolder + |copyFolder |copy |folderId, destinationfolderId, [newName] |com.box.sdk.BoxFolder |moveFolder |move |folderId, destinationFolderId, newName |com.box.sdk.BoxFolder diff --git a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java index 8da867a..7d2638e 100644 --- a/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java +++ b/components/camel-box/camel-box-component/src/test/java/org/apache/camel/component/box/BoxFoldersManagerIntegrationTest.java @@ -73,6 +73,25 @@ public class BoxFoldersManagerIntegrationTest extends AbstractBoxTestSupport { } @Test + public void testCreateFolderByPath() throws Exception { + + // delete folder created in test setup. + deleteTestFolder(); + + final Map<String, Object> headers = new HashMap<String, Object>(); + // parameter type is String + headers.put("CamelBox.parentFolderId", "0"); + // parameter type is String[] + headers.put("CamelBox.path", new String[] {CAMEL_TEST_FOLDER}); + + testFolder = requestBodyAndHeaders("direct://CREATEFOLDER", null, headers); + + assertNotNull("createFolder result", testFolder); + assertEquals("createFolder folder name", CAMEL_TEST_FOLDER, testFolder.getInfo().getName()); + LOG.debug("createFolder: " + testFolder); + } + + @Test public void testDeleteFolder() throws Exception { // using String message body for single parameter "folderId" requestBody("direct://DELETEFOLDER", testFolder.getID()); -- To stop receiving notification emails like this one, please contact ['"commits@camel.apache.org" <commits@camel.apache.org>'].