[
https://issues.apache.org/jira/browse/CAMEL-11885?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16326888#comment-16326888
]
ASF GitHub Bot commented on CAMEL-11885:
----------------------------------------
davsclaus closed pull request #2011: CAMEL-11885: Add support for creating
folder by path in camel-box
URL: https://github.com/apache/camel/pull/2011
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
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 b44fca977c7..dbe4e55b96a 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 BoxFolder getFolder(String... path) {
}
/**
- * 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.
@@ -188,6 +188,43 @@ public BoxFolder createFolder(String parentFolderId,
String folderName) {
}
}
+ /**
+ * 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.
*
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 a4e3136d93b..facb5c70bf8 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 8da867a3ed2..7d2638e6f2f 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
@@ -72,6 +72,25 @@ public void testCreateFolder() throws Exception {
LOG.debug("createFolder: " + testFolder);
}
+ @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"
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Add support for creating folder by path in camel-box
> ----------------------------------------------------
>
> Key: CAMEL-11885
> URL: https://issues.apache.org/jira/browse/CAMEL-11885
> Project: Camel
> Issue Type: Improvement
> Components: camel-box
> Affects Versions: 2.19.3
> Reporter: Fredrik Jönsson
> Priority: Major
> Fix For: 2.21.0
>
>
> Add possibility to specify folder by path as String[] when creating folders
> in Box, similarly to getFolder. It makes creation of nested folders in routes
> much easier.
> Note that createFolder(String, String[]) doesn't throw exception when folders
> exists unlike createFolder(String, String). This can be argued, but mimics
> the behaviour of, e.g., mkdir on Linux.
> {{
> $ mkdir foo
> $ mkdir foo
> mkdir: foo: File exists
> $ mkdir -p foo/bar
> $ mkdir -p foo/bar
> $
> }}
> Patch will follow.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)