Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 1E706200C2F for ; Mon, 6 Mar 2017 12:10:51 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1D085160B76; Mon, 6 Mar 2017 11:10:51 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B952F160B73 for ; Mon, 6 Mar 2017 12:10:48 +0100 (CET) Received: (qmail 46446 invoked by uid 500); 6 Mar 2017 11:10:47 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 46082 invoked by uid 99); 6 Mar 2017 11:10:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Mar 2017 11:10:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2268BDFF5D; Mon, 6 Mar 2017 11:10:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Mon, 06 Mar 2017 11:10:54 -0000 Message-Id: <67f633cb164b4610868a3b2c1fc82d5f@git.apache.org> In-Reply-To: <10225e7cb940444e862b1a40c6cb9a42@git.apache.org> References: <10225e7cb940444e862b1a40c6cb9a42@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [09/15] camel git commit: CAMEL-9047: Rename box2 to box archived-at: Mon, 06 Mar 2017 11:10:51 -0000 http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/test/resources/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/test/resources/test-options.properties b/components/camel-box/camel-box-component/src/test/resources/test-options.properties new file mode 100644 index 0000000..bd87fa3 --- /dev/null +++ b/components/camel-box/camel-box-component/src/test/resources/test-options.properties @@ -0,0 +1,33 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################### +## Authentication properties for Box Component +############################################### + +############################################################################# +## Authentication properties for Box Component using STANDARD_AUTHENTICATION +############################################################################# +authenticationType=STANDARD_AUTHENTICATION +## User name and password +## Create a free developer account on http://developers.box.com/ and provide user name password +userName= +userPassword= +## Application client id and secret +## Create a test Box.com application and provide its clientId and clientSecret +clientId= +clientSecret= http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/tmp/test-options.properties ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/tmp/test-options.properties b/components/camel-box/camel-box-component/tmp/test-options.properties new file mode 100644 index 0000000..9cee863 --- /dev/null +++ b/components/camel-box/camel-box-component/tmp/test-options.properties @@ -0,0 +1,67 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################### +## Authentication properties for Box Component +############################################### + +############################################################################# +## Authentication properties for Box Component using STANDARD_AUTHENTICATION +############################################################################# +authenticationType=STANDARD_AUTHENTICATION +## User name and password +## Create a free developer account on http://developers.box.com/ and provide user name password +userName=punkhornsw@gmail.com +userPassword=RedHat12!@ +## Application client id and secret +## Create a test Box.com application and provide its clientId and clientSecret +clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr + +################################################################################### +## Authentication properties for Box Component using APP_ENTERPRISE_AUTHENTICATION +################################################################################### +#authenticationType=APP_ENTERPRISE_AUTHENTICATION +#enterpriseId=8962085 +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr +#publicKeyId=b22nf9qt +#privateKeyFile=/Volumes/Development/Dev/box-java-sdk/private_key.pem +#privateKeyPassword=RedHat12!@ +#encryptionAlgorithm=RSA_SHA_256 +#maxCacheEntries=100 +### Application client id and secret +### Create a test Box.com application and provide its clientId and clientSecret +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr + +################################################################################### +## Authentication properties for Box Component using APP_USER_AUTHENTICATION +################################################################################### +#authenticationType=APP_USER_AUTHENTICATION +#userId=punkhornsw@gmail.com +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr +#publicKeyId=b22nf9qt +#privateKeyFile=/Volumes/Development/Dev/box-java-sdk/private_key.pem +#privateKeyPassword=RedHat12!@ +#encryptionAlgorithm=RSA_SHA_256 +#maxCacheEntries=100 +### Application client id and secret +### Create a test Box.com application and provide its clientId and clientSecret +#clientId=4vvr1njh5d0u3o8lpowbgnameqic9mz3 +#clientSecret=rh0qN6EWyMek61fELV8N82XblkK2EJMr http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-box/pom.xml b/components/camel-box/pom.xml new file mode 100644 index 0000000..1852cbf --- /dev/null +++ b/components/camel-box/pom.xml @@ -0,0 +1,48 @@ + + + + + 4.0.0 + + + components + org.apache.camel + 2.19.0-SNAPSHOT + + + camel-box-parent + pom + + Camel :: Box :: Parent + Camel Box parent + + + camel-box-component + camel-box-api + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/pom.xml b/components/camel-box2/camel-box2-api/pom.xml deleted file mode 100644 index 8b23615..0000000 --- a/components/camel-box2/camel-box2-api/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - 4.0.0 - - - org.apache.camel - camel-box2-parent - 2.19.0-SNAPSHOT - - - camel-box2-api - Camel Box2 Component API - API for Camel Box2 Component - - - UTF-8 - UTF-8 - - - - install - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - add-javadoc - - jar - - - true - 1.7 - true - false - 1.7 - UTF-8 - - - - - - - - - - - - doclint-java8-disable - - [1.8, - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - -Xdoclint:none - - - - - - - - - - com.box - box-java-sdk - 2.1.1 - - - http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CollaborationsManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CollaborationsManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CollaborationsManager.java deleted file mode 100644 index 6905036..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CollaborationsManager.java +++ /dev/null @@ -1,238 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import java.util.Collection; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.BoxCollaboration; -import com.box.sdk.BoxCollaborator; -import com.box.sdk.BoxFolder; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Collaborations Manager - * - *

- * Provides operations to manage Box collaborations. - * - * - * - */ -public class Box2CollaborationsManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2CollaborationsManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - /** - * Create collaborations manager to manage the comments of Box connection's - * authenticated user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2CollaborationsManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Get information about all of the collaborations for folder. - * - * @param folderId - * - the id of folder to get collaborations information on. - * - * @return The collection of collaboration information for folder. - */ - public Collection getFolderCollaborations(String folderId) { - try { - LOG.debug("Getting collaborations for folder(id=" + folderId + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - BoxFolder folder = new BoxFolder(boxConnection, folderId); - return folder.getCollaborations(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Add a collaboration to this folder. - * - * @param folderId - * - the id of folder to add collaboration to. - * @param collaborator - * - the collaborator to add. - * @param role - * - the role of the collaborator. - * - * @return The new collaboration. - */ - @SuppressWarnings("unused") // compiler for some reason thinks 'if - // (collaborator == null)' clause is dead code. - public BoxCollaboration addFolderCollaboration(String folderId, BoxCollaborator collaborator, - BoxCollaboration.Role role) { - try { - LOG.debug("Creating collaborations for folder(id=" + folderId + ") with collaborator(" - + collaborator.getID() + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (collaborator == null) { - throw new IllegalArgumentException("Parameter 'collaborator' can not be null"); - } - if (role == null) { - throw new IllegalArgumentException("Parameter 'role' can not be null"); - } - - BoxFolder folder = new BoxFolder(boxConnection, folderId); - return folder.collaborate(collaborator, role).getResource(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Add a collaboration to this folder. An email will be sent to the - * collaborator if they don't already have a Box account. - * - * @param folderId - * - the id of folder to add collaboration to. - * @param email - * - the email address of the collaborator to add. - * @param role - * - the role of the collaborator. - * - * @return The new collaboration. - */ - public BoxCollaboration addFolderCollaborationByEmail(String folderId, String email, BoxCollaboration.Role role) { - try { - LOG.debug("Creating collaborations for folder(id=" + folderId + ") with collaborator(" + email + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (email == null) { - throw new IllegalArgumentException("Parameter 'email' can not be null"); - } - if (role == null) { - throw new IllegalArgumentException("Parameter 'role' can not be null"); - } - - BoxFolder folder = new BoxFolder(boxConnection, folderId); - return folder.collaborate(email, role).getResource(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get collaboration information. - * - * @param collaborationId - * - the id of collaboration. - * @return The collaboration information. - */ - public BoxCollaboration.Info getCollaborationInfo(String collaborationId) { - try { - LOG.debug("Getting info for collaboration(id=" + collaborationId + ")"); - if (collaborationId == null) { - throw new IllegalArgumentException("Parameter 'collaborationId' can not be null"); - } - - BoxCollaboration collaboration = new BoxCollaboration(boxConnection, collaborationId); - - return collaboration.getInfo(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Update collaboration information. - * - * @param collaborationId - * - the id of collaboration. - * @return The collaboration with updated information. - */ - public BoxCollaboration updateCollaborationInfo(String collaborationId, BoxCollaboration.Info info) { - try { - LOG.debug("Updating info for collaboration(id=" + collaborationId + ")"); - if (collaborationId == null) { - throw new IllegalArgumentException("Parameter 'collaborationId' can not be null"); - } - - BoxCollaboration collaboration = new BoxCollaboration(boxConnection, collaborationId); - - collaboration.updateInfo(info); - return collaboration; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete collaboration. - * - * @param collaborationId - * - the id of comment to change. - * @param message - * - the new message for the comment. - * @return The comment with changed message. - */ - public void deleteCollaboration(String collaborationId) { - try { - LOG.debug("Deleting collaboration(id=" + collaborationId + ")"); - if (collaborationId == null) { - throw new IllegalArgumentException("Parameter 'collaborationId' can not be null"); - } - BoxCollaboration collaboration = new BoxCollaboration(boxConnection, collaborationId); - collaboration.delete(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get all pending collaboration invites for the current user. - * - * @return A collection of pending collaboration information. - */ - public Collection getPendingCollaborations() { - try { - - return BoxCollaboration.getPendingCollaborations(boxConnection); - - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CommentsManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CommentsManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CommentsManager.java deleted file mode 100644 index b20c7bc..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2CommentsManager.java +++ /dev/null @@ -1,205 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import java.util.List; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.BoxComment; -import com.box.sdk.BoxFile; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Comments Manager - * - *

- * Provides operations to manage Box comments. - * - * - * - */ -public class Box2CommentsManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2CommentsManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - /** - * Create comments manager to manage the comments of Box connection's - * authenticated user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2CommentsManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Add comment to file. - * - * @param fileId - * - the id of file to rename. - * @param message - * - the comment's message. - * @return The commented file. - */ - public BoxFile addFileComment(String fileId, String message) { - try { - LOG.debug("Adding comment to file(id=" + fileId + ") to '" + message + "'"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (message == null) { - throw new IllegalArgumentException("Parameter 'message' can not be null"); - } - - BoxFile fileToCommentOn = new BoxFile(boxConnection, fileId); - fileToCommentOn.addComment(message); - return fileToCommentOn; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get a list of any comments on this file. - * - * @param fileId - * - the id of file. - * @return The list of comments on this file. - */ - public List getFileComments(String fileId) { - try { - LOG.debug("Getting comments of file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - return file.getComments(); - - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get comment information. - * - * @param commentId - * - the id of comment. - * @return The comment information. - */ - public BoxComment.Info getCommentInfo(String commentId) { - try { - LOG.debug("Getting info for comment(id=" + commentId + ")"); - if (commentId == null) { - throw new IllegalArgumentException("Parameter 'commentId' can not be null"); - } - - BoxComment comment = new BoxComment(boxConnection, commentId); - - return comment.getInfo(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Reply to a comment. - * - * @param commentId - * - the id of comment to reply to. - * @param message - * - the message for the reply. - * @return The newly created reply comment. - */ - public BoxComment replyToComment(String commentId, String message) { - try { - LOG.debug("Replying to comment(id=" + commentId + ") with message=" + message); - if (commentId == null) { - throw new IllegalArgumentException("Parameter 'commentId' can not be null"); - } - if (message == null) { - throw new IllegalArgumentException("Parameter 'message' can not be null"); - } - BoxComment comment = new BoxComment(boxConnection, commentId); - return comment.reply(message).getResource(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Change comment message. - * - * @param commentId - * - the id of comment to change. - * @param message - * - the new message for the comment. - * @return The comment with changed message. - */ - public BoxComment changeCommentMessage(String commentId, String message) { - try { - LOG.debug("Changing comment(id=" + commentId + ") message=" + message); - if (commentId == null) { - throw new IllegalArgumentException("Parameter 'commentId' can not be null"); - } - if (message == null) { - throw new IllegalArgumentException("Parameter 'message' can not be null"); - } - BoxComment comment = new BoxComment(boxConnection, commentId); - return comment.changeMessage(message).getResource(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete comment. - * - * @param commentId - * - the id of comment to delete. - */ - public void deleteComment(String commentId) { - try { - LOG.debug("Deleting comment(id=" + commentId + ")"); - if (commentId == null) { - throw new IllegalArgumentException("Parameter 'commentId' can not be null"); - } - BoxComment comment = new BoxComment(boxConnection, commentId); - comment.delete(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventLogsManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventLogsManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventLogsManager.java deleted file mode 100644 index b7be4f7..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventLogsManager.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.BoxEvent; -import com.box.sdk.EventLog; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Event Logs Manager - * - *

- * Provides operations to read Box enterprise (admin) event logs. - * - * - * - */ -public class Box2EventLogsManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2EventLogsManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - /** - * Create event logs manager to manage the event logs of Box connection's - * authenticated user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2EventLogsManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Create an event stream with optional starting initial position and add - * listener that will be notified when an event is received. - * - * @param position - * - the starting position of the event stream. May be - * null in which case all events within bounds - * returned. - * @param after - * - the lower bound on the timestamp of the events returned. - * @param after - * - the upper bound on the timestamp of the events returned. - * @param types - * - an optional list of event types to filter by. - * - * @return A list of all the events that met the given criteria. - */ - public List getEnterpriseEvents(String position, Date after, Date before, BoxEvent.Type... types) { - try { - LOG.debug("Getting all enterprise events occuring between " - + (after == null ? after : SimpleDateFormat.getDateTimeInstance().format(after)) + " and " - + (before == null ? before : SimpleDateFormat.getDateTimeInstance().format(before)) - + (position == null ? position : (" starting at " + position))); - - if (after == null) { - throw new IllegalArgumentException("Parameter 'after' can not be null"); - } - if (before == null) { - throw new IllegalArgumentException("Parameter 'before' can not be null"); - } - - if (types == null) { - types = new BoxEvent.Type[0]; - } - - EventLog eventLog = EventLog.getEnterpriseEvents(boxConnection, position, after, before, types); - - List results = new ArrayList(); - for (BoxEvent event : eventLog) { - results.add(event); - } - - return results; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - -} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventsManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventsManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventsManager.java deleted file mode 100644 index 62b7f11..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2EventsManager.java +++ /dev/null @@ -1,99 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.EventListener; -import com.box.sdk.EventStream; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Events Manager - * - *

- * Provides operations to manage Box events. - * - * - * - */ -public class Box2EventsManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2EventsManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - private EventStream eventStream; - - /** - * Create events manager to manage the events of Box connection's - * authenticated user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2EventsManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Create an event stream with optional starting initial position and add - * listener that will be notified when an event is received. - * - * @param startingPosition - * - the starting position of the event stream. - * @param listener - * - the listener to add to event stream. - * - * @return The event stream. - */ - public void listen(EventListener listener, Long startingPosition) { - try { - LOG.debug("Listening for events with listener=" + listener + " at startingPosition=" + startingPosition); - - if (listener == null) { - LOG.debug("Parameter 'listener' is null: will not listen for events"); - return; - } - - if (startingPosition != null) { - eventStream = new EventStream(boxConnection, startingPosition); - } else { - eventStream = new EventStream(boxConnection); - } - - eventStream.addListener(listener); - - eventStream.start(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - public void stopListening() { - if (eventStream != null && eventStream.isStarted()) { - eventStream.stop(); - } - eventStream = null; - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FilesManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FilesManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FilesManager.java deleted file mode 100644 index 2435e34..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FilesManager.java +++ /dev/null @@ -1,798 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.text.SimpleDateFormat; -import java.util.Collection; -import java.util.Date; -import java.util.List; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.BoxFile; -import com.box.sdk.BoxFileVersion; -import com.box.sdk.BoxFolder; -import com.box.sdk.BoxSharedLink; -import com.box.sdk.FileUploadParams; -import com.box.sdk.Metadata; -import com.box.sdk.ProgressListener; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Files Manager - * - *

- * Provides operations to manage Box files. - * - * - * - */ -public class Box2FilesManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2FilesManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - /** - * Create files manager to manage the files of Box connection's - * authenticated user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2FilesManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Get file information. - * - * @param fileId - * - the id of file. - * @param fields - * - the information fields to retrieve; if null all - * information fields are retrieved. - * @return The file information. - */ - public BoxFile.Info getFileInfo(String fileId, String... fields) { - try { - LOG.debug("Getting info for file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - if (fields == null || fields.length == 0) { - return file.getInfo(); - } else { - return file.getInfo(fields); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Update file information. - * - * @param fileId - * - the id of file to update. - * @param info - * - the updated information - * @return The updated file. - */ - public BoxFile updateFileInfo(String fileId, BoxFile.Info info) { - try { - LOG.debug("Updating info for file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (info == null) { - throw new IllegalArgumentException("Parameter 'info' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - file.updateInfo(info); - return file; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Upload a new file to parent folder. - * - * @param parentFolderId - * - the id of parent folder. - * @param content - * - a stream containing contents of the file to upload. - * @param fileName - * the name to give the uploaded file. - * @param created - * - the content created date that will be given to the uploaded - * file. - * @param modified - * - the content modified date that will be given to the uploaded - * file. - * @param size - * - the size of the file's content used for monitoring the - * upload's progress. - * @param listener - * - a listener for monitoring the upload's progress. - * @return The uploaded file. - */ - public BoxFile uploadFile(String parentFolderId, InputStream content, String fileName, Date created, Date modified, - Long size, ProgressListener listener) { - try { - LOG.debug("Uploading file with name '" + fileName + "' to parent_folder(id=" + parentFolderId + ")"); - if (parentFolderId == null) { - throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null"); - } - if (content == null) { - throw new IllegalArgumentException("Paramerer 'content' can not be null"); - } - if (fileName == null) { - throw new IllegalArgumentException("Paramerer 'fileName' can not be null"); - } - BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId); - - FileUploadParams uploadParams = new FileUploadParams(); - uploadParams.setName(fileName); - uploadParams.setContent(content); - if (created != null) { - uploadParams.setCreated(created); - } - if (modified != null) { - uploadParams.setModified(modified); - } - if (size != null) { - uploadParams.setSize(size); - } - if (listener != null) { - uploadParams.setProgressListener(listener); - } - - return parentFolder.uploadFile(uploadParams).getResource(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Upload a new version of file. - * - * @param fileId - * - the id of file. - * @param fileContent - * - a stream containing contents of the file to upload. - * @param modified - * - the content modified date that will be given to the uploaded - * file. - * @param fileSize - * - the size of the file's content used for monitoring the - * upload's progress. - * @param listener - * - a listener for monitoring the upload's progress. - * @return The uploaded file. - */ - public BoxFile uploadNewFileVersion(String fileId, InputStream fileContent, Date modified, Long fileSize, - ProgressListener listener) { - try { - LOG.debug("Uploading new version of file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (fileContent == null) { - throw new IllegalArgumentException("Paramerer 'fileContent' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - if (modified != null) { - if (fileSize != null && listener != null) { - file.uploadVersion(fileContent, modified, fileSize, listener); - } else { - file.uploadVersion(fileContent, modified); - } - } else { - file.uploadVersion(fileContent); - } - - return file; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get any previous versions of file. - * - * @param fileId - * - the id of file. - * @return The list of previous file versions. - */ - public Collection getFileVersions(String fileId) { - try { - LOG.debug("Getting versions of file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - return file.getVersions(); - - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Download a file. - * - * @param fileId - * - the id of file. - * @param output - * - the stream to which the file contents will be written. - * @param rangeStart - * - the byte offset in file at which to start the download; if - * null the entire contents of file will be - * downloaded. - * @param rangeEnd - * - the byte offset in file at which to stop the download; if - * null the entire contents of file will be - * downloaded. - * @param listener - * - a listener for monitoring the download's progress; if - * null the download's progress will not be - * monitored. - * @return The stream containing the contents of the downloaded file. - */ - public OutputStream downloadFile(String fileId, OutputStream output, Long rangeStart, Long rangeEnd, - ProgressListener listener) { - try { - LOG.debug("Downloading file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (output == null) { - throw new IllegalArgumentException("Parameter 'output' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - - if (listener != null) { - if (rangeStart != null && rangeEnd != null) { - file.downloadRange(output, rangeStart, rangeEnd, listener); - } else { - file.download(output, listener); - } - } else { - if (rangeStart != null && rangeEnd != null) { - file.downloadRange(output, rangeStart, rangeEnd); - } else { - file.download(output); - } - } - return output; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Download a previous version of file. - * - * @param fileId - * - the id of file. - * @param version - * - the version of file to download; initial version of file has - * value of 0, second version of file is - * 1 and so on. - * @param output - * - the stream to which the version contents will be written. - * @param listener - * - a listener for monitoring the download's progress; if - * null the download's progress will not be - * monitored. - * @return The stream containing the contents of the downloaded file - * version. - */ - public OutputStream downloadPreviousFileVersion(String fileId, Integer version, OutputStream output, - ProgressListener listener) { - try { - LOG.debug("Downloading file(id=" + fileId + ", version=" + version + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (version == null) { - throw new IllegalArgumentException("Parameter 'version' can not be null"); - } - if (output == null) { - throw new IllegalArgumentException("Parameter 'output' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - - List fileVersions = (List) file.getVersions(); - BoxFileVersion fileVersion = fileVersions.get(version); - - if (listener != null) { - fileVersion.download(output, listener); - } else { - fileVersion.download(output); - } - return output; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Promote a previous version of file. - * - * @param fileId - * - the id of file. - * @param version - * - the version of file to promote; initial version of file has - * value of 0, second version of file is - * 1 and so on. - * @return The promoted version of file. - */ - public BoxFileVersion promoteFileVersion(String fileId, Integer version) { - try { - LOG.debug("Promoting file(id=" + fileId + ", version=" + version + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (version == null) { - throw new IllegalArgumentException("Parameter 'version' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - - List fileVersions = (List) file.getVersions(); - BoxFileVersion fileVersion = fileVersions.get(version); - - fileVersion.promote(); - return fileVersion; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Copy file to destination folder while optionally giving it a new name. - * - * @param fileId - * - the id of file to copy. - * @param destinationFolderId - * - the id of the destination folder. - * @param newName - * - the new name for copied file; if newName is - * null, the copied file has same name as the - * original. - * @return The copied file. - */ - public BoxFile copyFile(String fileId, String destinationFolderId, String newName) { - try { - LOG.debug("Copying file(id=" + fileId + ") to destination_folder(id=" + destinationFolderId + ")" - + (newName == null ? "" : " with new name '" + newName + "'")); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (destinationFolderId == null) { - throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null"); - } - BoxFile fileToCopy = new BoxFile(boxConnection, fileId); - BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId); - if (newName == null) { - return fileToCopy.copy(destinationFolder).getResource(); - } else { - return fileToCopy.copy(destinationFolder, newName).getResource(); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Move file to destination folder while optionally giving it a new name. - * - * @param fileId - * - the id of file to move. - * @param destinationFolderId - * - the id of the destination folder. - * @param newName - * - the new name of moved file; if newName is - * null, the moved file has same name as the - * original. - * @return The moved file. - */ - public BoxFile moveFile(String fileId, String destinationFolderId, String newName) { - try { - LOG.debug("Moving file(id=" + fileId + ") to destination_folder(id=" + destinationFolderId + ")" - + (newName == null ? "" : " with new name '" + newName + "'")); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (destinationFolderId == null) { - throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null"); - } - BoxFile fileToMove = new BoxFile(boxConnection, fileId); - BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId); - if (newName == null) { - return (BoxFile) fileToMove.move(destinationFolder).getResource(); - } else { - return (BoxFile) fileToMove.move(destinationFolder, newName).getResource(); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Rename file giving it the name newName - * - * @param fileId - * - the id of file to rename. - * @param newFileName - * - the new name of file. - * @return The renamed file. - */ - public BoxFile renameFile(String fileId, String newFileName) { - try { - LOG.debug("Renaming file(id=" + fileId + ") to '" + newFileName + "'"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (newFileName == null) { - throw new IllegalArgumentException("Parameter 'newName' can not be null"); - } - BoxFile fileToRename = new BoxFile(boxConnection, fileId); - fileToRename.rename(newFileName); - return fileToRename; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete the file. - * - * @param fileId - * - the id of file to delete. - */ - public void deleteFile(String fileId) { - try { - LOG.debug("Deleting file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - file.delete(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete a file version. - * - * @param fileId - * - the id of file with version to delete. - * @param version - * - the version of file to delete; initial version of file has - * value of 0, second version of file is - * 1 and so on. - */ - public void deleteFileVersion(String fileId, Integer version) { - try { - LOG.debug("Deleting file(id=" + fileId + ", version=" + version + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (version == null) { - throw new IllegalArgumentException("Parameter 'version' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - List versions = (List) file.getVersions(); - BoxFileVersion fileVersion = versions.get(version); - - fileVersion.delete(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Create a shared link to file. - * - * @param fileId - * - the id of the file to create shared link on. - * @param access - * - the access level of the shared link. - * @param unshareDate - * - the date and time at which time the created shared link will - * expire; if unsharedDate is null then - * a non-expiring link is created. - * @param permissions - * - the permissions of the created link; if - * permissions is null then the created - * shared link is create with default permissions. - * @return The created shared link. - */ - public BoxSharedLink createFileSharedLink(String fileId, BoxSharedLink.Access access, Date unshareDate, - BoxSharedLink.Permissions permissions) { - try { - LOG.debug("Creating shared link for file(id=" + fileId + ") with access=" + access - + (unshareDate == null ? "" - : " unsharedDate=" + SimpleDateFormat.getDateTimeInstance().format(unshareDate) - + " permissions=" + permissions)); - - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (access == null) { - throw new IllegalArgumentException("Parameter 'access' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - return file.createSharedLink(access, unshareDate, permissions); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get an expiring URL for downloading a file directly from Box. This can be - * user, for example, for sending as a redirect to a browser to cause the - * browser to download the file directly from Box. - * - * @param fileId - * - the id of file. - * @return The temporary download URL - */ - public URL getDownloadURL(String fileId) { - try { - LOG.debug("Getting download URL for file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - return file.getDownloadURL(); - - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get an expiring URL for creating an embedded preview session. The URL - * will expire after 60 seconds and the preview session will expire after 60 - * minutes. - * - * @param fileId - * - the id of the file to get preview link on. - * @return The preview link. - */ - public URL getFilePreviewLink(String fileId) { - try { - LOG.debug("Getting preview link for file(id=" + fileId + ")"); - - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - return file.getPreviewLink(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get an expiring URL for creating an embedded preview session. The URL - * will expire after 60 seconds and the preview session will expire after 60 - * minutes. - * - * @param fileId - * - the id of the file to get preview link on. - * @param fileType - * - either PNG of JPG. - * @param minWidth - * - minimum width. - * @param minHeight - * - minimum height. - * @param maxWidth - * - maximum width. - * @param maxHeight - * - maximum height. - * @return The byte array of the thumbnail image. - */ - public byte[] getFileThumbnail(String fileId, BoxFile.ThumbnailFileType fileType, Integer minWidth, - Integer minHeight, Integer maxWidth, Integer maxHeight) { - try { - LOG.debug("Getting thumbnail for file(id=" + fileId + ") fileType=" + fileType + " minWidth=" + minWidth - + " minHeight=" + minHeight + " maxWidth=" + maxWidth + " maxHeight=" + maxHeight); - - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (fileType == null) { - throw new IllegalArgumentException("Parameter 'fileType' can not be null"); - } - if (minWidth == null) { - throw new IllegalArgumentException("Parameter 'minWidth' can not be null"); - } - if (minHeight == null) { - throw new IllegalArgumentException("Parameter 'minHeight' can not be null"); - } - if (maxWidth == null) { - throw new IllegalArgumentException("Parameter 'maxWidth' can not be null"); - } - if (maxHeight == null) { - throw new IllegalArgumentException("Parameter 'maxHeight' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - return file.getThumbnail(fileType, minWidth, minHeight, maxWidth, maxHeight); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Create metadata for file in either the global properties template or the - * specified template type. - * - * @param fileId - * - the id of the file to create metadata for. - * @param metadata - * - the new metadata values. - * @param typeName - * - the metadata template type name; if null the - * global properties template type is used. - * @return The metadata returned from the server. - */ - public Metadata createFileMetadata(String fileId, Metadata metadata, String typeName) { - try { - LOG.debug("Creating metadata for file(id=" + fileId + ")"); - - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (metadata == null) { - throw new IllegalArgumentException("Parameter 'metadata' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - if (typeName != null) { - return file.createMetadata(typeName, metadata); - } else { - return file.createMetadata(metadata); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Gets the file properties metadata. - * - * @param fileId - * - the id of the file to retrieve metadata for. - * @param typeName - * - the metadata template type name; if null the - * global properties template type is used. - * @return The metadata returned from the server. - */ - public Metadata getFileMetadata(String fileId, String typeName) { - try { - LOG.debug("Get metadata for file(id=" + fileId + ")"); - - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - - BoxFile file = new BoxFile(boxConnection, fileId); - - if (typeName != null) { - return file.getMetadata(typeName); - } else { - return file.getMetadata(); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - - } - - /** - * Update the file properties metadata. - * - * @param fileId - * - the id of file to delete. - * @param metadata - * - the new metadata values. - * @return The metadata returned from the server. - */ - public Metadata updateFileMetadata(String fileId, Metadata metadata) { - try { - LOG.debug("Updating metadata for file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - if (metadata == null) { - throw new IllegalArgumentException("Parameter 'metadata' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - return file.updateMetadata(metadata); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete the file properties metadata. - * - * @param fileId - * - the id of file to delete. - */ - public void deleteFileMetadata(String fileId) { - try { - LOG.debug("Deleting metadata for file(id=" + fileId + ")"); - if (fileId == null) { - throw new IllegalArgumentException("Parameter 'fileId' can not be null"); - } - BoxFile file = new BoxFile(boxConnection, fileId); - file.deleteMetadata(); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } -} http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FoldersManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FoldersManager.java b/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FoldersManager.java deleted file mode 100644 index 5eba928..0000000 --- a/components/camel-box2/camel-box2-api/src/main/java/org/apache/camel/component/box2/api/Box2FoldersManager.java +++ /dev/null @@ -1,407 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.component.box2.api; - -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Date; - -import com.box.sdk.BoxAPIConnection; -import com.box.sdk.BoxAPIException; -import com.box.sdk.BoxFolder; -import com.box.sdk.BoxItem; -import com.box.sdk.BoxSharedLink; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Box2 Folders Manager - * - *

- * Provides operations to manage Box folders. - * - * - * - */ -public class Box2FoldersManager { - - private static final Logger LOG = LoggerFactory.getLogger(Box2FoldersManager.class); - - /** - * Box connection to authenticated user account. - */ - private BoxAPIConnection boxConnection; - - /** - * Create folder manager to manage folders of Box connection's authenticated - * user. - * - * @param boxConnection - * - Box connection to authenticated user account. - */ - public Box2FoldersManager(BoxAPIConnection boxConnection) { - this.boxConnection = boxConnection; - } - - /** - * Return the root folder of authenticated user. - * - * @return The root folder of authenticated user. - */ - public BoxFolder getRootFolder() { - try { - LOG.debug("Getting root folder"); - return BoxFolder.getRootFolder(boxConnection); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Return the Box folder referenced by path. - * - * @param path - * - Sequence of Box folder names from root folder to returned - * folder. - * - * @return The Box folder referenced by path or - * null if folder is not found. - */ - public BoxFolder getFolder(String... path) { - try { - LOG.debug("Getting folder at path=" + Arrays.toString(path)); - - BoxFolder folder = BoxFolder.getRootFolder(boxConnection); - if (path == null || path.length == 0) { - // Return root folder if path is null or empty. - return folder; - } - - 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; - } - } - // Failed to find named folder in path: return null - return null; - } - 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); - } - } - - /** - * Returns a specific range of child items in folder and specifies which - * fields of each item to retrieve. - * - * @param folderId - * - the id of folder. - * @param offset - * - the index of first child item to retrieve; if - * null all child items are retrieved. - * @param limit - * - the maximum number of children to retrieve after the offset; - * if null all child items are retrieved. - * @param fields - * - the item fields to retrieve for each child item; if - * null all item fields are retrieved. - * @return The Items in folder - */ - public Collection getFolderItems(String folderId, Long offset, Long limit, String... fields) { - try { - LOG.debug("Getting folder items in folder(id=" + folderId + ") at offset=" + offset + " and limit=" + limit - + " with fields=" + Arrays.toString(fields)); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - BoxFolder folder = new BoxFolder(boxConnection, folderId); - if (fields == null) { - fields = new String[0]; - } - if (offset != null && limit != null) { - return folder.getChildrenRange(offset, limit, fields); - } else { - Collection folderItems = new ArrayList(); - Iterable iterable; - if (fields.length > 0) { - iterable = folder.getChildren(fields); - } else { - iterable = folder.getChildren(); - } - for (BoxItem.Info itemInfo : iterable) { - folderItems.add(itemInfo); - } - - return folderItems; - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Create a folder in parent folder with given folderName. - * - * @param parentFolderId - * - the id of parent folder. - * @param folderName - * the name of created folder. - * @return The created folder. - */ - public BoxFolder createFolder(String parentFolderId, String folderName) { - try { - LOG.debug("Creating folder with name '" + folderName + "' in parent_folder(id=" + parentFolderId + ")"); - if (parentFolderId == null) { - throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null"); - } - if (folderName == null) { - throw new IllegalArgumentException("Paramerer 'folderName' can not be null"); - } - BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId); - return parentFolder.createFolder(folderName).getResource(); - } 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 - * - the id of folder to copy. - * @param destinationFolderId - * - the id of the destination folder. - * @param newName - * - the new name for copied folder; if newName is - * null, the copied folder has same name as the - * original. - * @return The copied folder. - */ - public BoxFolder copyFolder(String folderId, String destinationFolderId, String newName) { - try { - LOG.debug("Copying folder(id=" + folderId + ") to destination_folder(id=" + destinationFolderId + ")" - + (newName == null ? "" : " with new name '" + newName + "'")); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (destinationFolderId == null) { - throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null"); - } - BoxFolder folderToCopy = new BoxFolder(boxConnection, folderId); - BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId); - if (newName == null) { - return folderToCopy.copy(destinationFolder).getResource(); - } else { - return folderToCopy.copy(destinationFolder, newName).getResource(); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Move folder to destination folder while optionally giving it a new name. - * - * @param folderId - * - the id of folder to move. - * @param destinationFolderId - * - the id of the destination folder. - * @param newName - * - the new name of moved folder; if newName is - * null, the moved folder has same name as the - * original. - * @return The moved folder. - */ - public BoxFolder moveFolder(String folderId, String destinationFolderId, String newName) { - try { - LOG.debug("Moving folder(id=" + folderId + ") to destination_folder(id=" + destinationFolderId + ")" - + (newName == null ? "" : " with new name '" + newName + "'")); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (destinationFolderId == null) { - throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null"); - } - BoxFolder folderToMove = new BoxFolder(boxConnection, folderId); - BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId); - if (newName == null) { - return (BoxFolder) folderToMove.move(destinationFolder).getResource(); - } else { - return (BoxFolder) folderToMove.move(destinationFolder, newName).getResource(); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Rename folder giving it the name newName - * - * @param folderId - * - the id of folder to rename. - * @param newFolderName - * - the new name of folder. - * @return The renamed folder. - */ - public BoxFolder renameFolder(String folderId, String newFolderName) { - try { - LOG.debug("Renaming folder(id=" + folderId + ") to '" + newFolderName + "'"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (newFolderName == null) { - throw new IllegalArgumentException("Parameter 'newFolderName' can not be null"); - } - BoxFolder folderToRename = new BoxFolder(boxConnection, folderId); - folderToRename.rename(newFolderName); - return folderToRename; - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Delete folder. - * - * @param folderId - * - the id of folder to delete. - */ - public void deleteFolder(String folderId) { - try { - LOG.debug("Deleting folder(id=" + folderId + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - BoxFolder folder = new BoxFolder(boxConnection, folderId); - folder.delete(true); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Get folder information. - * - * @param folderId - * - the id of folder. - * @param fields - * - the information fields to retrieve; if null all - * information fields are retrieved. - * @return The folder information. - */ - public BoxFolder.Info getFolderInfo(String folderId, String... fields) { - try { - LOG.debug("Getting info for folder(id=" + folderId + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - - BoxFolder folder = new BoxFolder(boxConnection, folderId); - - if (fields == null || fields.length == 0) { - return folder.getInfo(); - } else { - return folder.getInfo(fields); - } - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - - /** - * Update folder information. - * - * @param folderId - * - the id of folder to update. - * @param info - * - the updated information - * @return The updated folder. - */ - public BoxFolder updateFolderInfo(String folderId, BoxFolder.Info info) { - try { - LOG.debug("Updating info for folder(id=" + folderId + ")"); - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (info == null) { - throw new IllegalArgumentException("Parameter 'info' can not be null"); - } - BoxFolder folder = new BoxFolder(boxConnection, folderId); - folder.updateInfo(info); - 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); - } - } - - /** - * Create a shared link to folder. - * - * @param folderId - * - the id of folder to create shared link on. - * @param access - * - the access level of the shared link. - * @param unshareDate - * - the date and time at which time the created shared link will - * expire; if unsharedDate is null then - * a non-expiring link is created. - * @param permissions - * - the permissions of the created link; if - * permissions is null then the created - * shared link is create with default permissions. - * @return The created shared link. - */ - public BoxSharedLink createFolderSharedLink(String folderId, BoxSharedLink.Access access, Date unshareDate, - BoxSharedLink.Permissions permissions) { - try { - LOG.debug("Creating shared link for folder(id=" + folderId + ") with access=" + access - + (unshareDate == null ? "" - : " unsharedDate=" + SimpleDateFormat.getDateTimeInstance().format(unshareDate) - + " permissions=" + permissions)); - - if (folderId == null) { - throw new IllegalArgumentException("Parameter 'folderId' can not be null"); - } - if (access == null) { - throw new IllegalArgumentException("Parameter 'access' can not be null"); - } - - BoxFolder folder = new BoxFolder(boxConnection, folderId); - return folder.createSharedLink(access, unshareDate, permissions); - } catch (BoxAPIException e) { - throw new RuntimeException( - String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); - } - } - -}