http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxGroupsManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxGroupsManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxGroupsManager.java new file mode 100644 index 0000000..b8c914f --- /dev/null +++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxGroupsManager.java @@ -0,0 +1,274 @@ +/** + * 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.box.api; + +import java.util.ArrayList; +import java.util.Collection; + +import com.box.sdk.BoxAPIConnection; +import com.box.sdk.BoxAPIException; +import com.box.sdk.BoxGroup; +import com.box.sdk.BoxGroupMembership; +import com.box.sdk.BoxUser; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Box Groups Manager + * + * <p> + * Provides operations to manage Box groups. + * + * + * + */ +public class BoxGroupsManager { + + private static final Logger LOG = LoggerFactory.getLogger(BoxGroupsManager.class); + + /** + * Box connection to authenticated user account. + */ + private BoxAPIConnection boxConnection; + + /** + * Create groups manager to manage the users of Box connection's + * authenticated user. + * + * @param boxConnection + * - Box connection to authenticated user account. + */ + public BoxGroupsManager(BoxAPIConnection boxConnection) { + this.boxConnection = boxConnection; + } + + /** + * Get all the groups in the enterprise. + * + * @return Collection containing all the enterprise's groups. + */ + public Collection<BoxGroup> getAllGroups() { + try { + LOG.debug("Getting all groups"); + + Collection<BoxGroup> groups = new ArrayList<BoxGroup>(); + for (BoxGroup.Info groupInfo : BoxGroup.getAllGroups(boxConnection)) { + groups.add(groupInfo.getResource()); + } + return groups; + } 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 new group with a specified name. + * + * @param name + * - the name of the new group. + * @return The newly created group. + */ + public BoxGroup createGroup(String name) { + try { + LOG.debug("Creating group name=" + name); + if (name == null) { + throw new IllegalArgumentException("Parameter 'name' can not be null"); + } + + return BoxGroup.createGroup(boxConnection, name).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 group. + * + * @param groupId + * - the id of group to delete. + */ + public void deleteGroup(String groupId) { + try { + LOG.debug("Deleting group(" + groupId + ")"); + if (groupId == null) { + throw new IllegalArgumentException("Parameter 'groupId' can not be null"); + } + + BoxGroup group = new BoxGroup(boxConnection, groupId); + group.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 group information. + * + * @param groupId + * - the id of group. + * @return The group information. + */ + public BoxGroup.Info getGroupInfo(String groupId) { + try { + LOG.debug("Getting info for group(id=" + groupId + ")"); + if (groupId == null) { + throw new IllegalArgumentException("Parameter 'groupId' can not be null"); + } + + BoxGroup group = new BoxGroup(boxConnection, groupId); + + return group.getInfo(); + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Get information about all of the group memberships for this group. + * + * @param groupId + * - the id of group. + * @return The group information. + */ + public Collection<BoxGroupMembership.Info> getGroupMemberships(String groupId) { + try { + LOG.debug("Getting information about all memberships for group(id=" + groupId + ")"); + if (groupId == null) { + throw new IllegalArgumentException("Parameter 'groupId' can not be null"); + } + + BoxGroup group = new BoxGroup(boxConnection, groupId); + + return group.getMemberships(); + } 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 member to group with the specified role. + * + * @param groupId + * - the id of group. + * @param userId + * - the id of user to be added to group. + * @param role + * - the role of the user in this group. Can be <code>null</code> + * to assign the default role. + * @return The group information. + */ + public BoxGroupMembership addGroupMembership(String groupId, String userId, BoxGroupMembership.Role role) { + try { + LOG.debug("Adding user(id=" + userId + ") as member to group(id=" + groupId + + (role == null ? ")" : ") with role=" + role.name())); + if (groupId == null) { + throw new IllegalArgumentException("Parameter 'groupId' can not be null"); + } + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + + BoxGroup group = new BoxGroup(boxConnection, groupId); + BoxUser user = new BoxUser(boxConnection, userId); + + return group.addMembership(user, 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); + } + } + + /** + * Delete group membership. + * + * @param groupMembershipId + * - the id of group membership to delete. + */ + public void deleteGroupMembership(String groupMembershipId) { + try { + LOG.debug("Deleting groupMembership(id=" + groupMembershipId + ")"); + if (groupMembershipId == null) { + throw new IllegalArgumentException("Parameter 'groupMemebershipId' can not be null"); + } + + BoxGroupMembership groupMembership = new BoxGroupMembership(boxConnection, groupMembershipId); + + groupMembership.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 group membership information. + * + * @param groupMemebershipId + * - the id of group membership. + * @return The group information. + */ + public BoxGroupMembership.Info getGroupMembershipInfo(String groupMemebershipId) { + try { + LOG.debug("Getting info for groupMemebership(id=" + groupMemebershipId + ")"); + if (groupMemebershipId == null) { + throw new IllegalArgumentException("Parameter 'groupMemebershipId' can not be null"); + } + + BoxGroupMembership group = new BoxGroupMembership(boxConnection, groupMemebershipId); + + return group.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 group membership information. + * + * @param groupMembershipId + * - the id of group membership to update. + * @param info + * - the updated information. + * @return The group information. + */ + public BoxGroupMembership updateGroupMembershipInfo(String groupMemebershipId, BoxGroupMembership.Info info) { + try { + LOG.debug("Updating info for groupMembership(id=" + groupMemebershipId + ")"); + if (groupMemebershipId == null) { + throw new IllegalArgumentException("Parameter 'groupMemebershipId' can not be null"); + } + if (info == null) { + throw new IllegalArgumentException("Parameter 'info' can not be null"); + } + + BoxGroupMembership groupMembership = new BoxGroupMembership(boxConnection, groupMemebershipId); + + groupMembership.updateInfo(info); + return groupMembership; + } 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-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxSearchManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxSearchManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxSearchManager.java new file mode 100644 index 0000000..c44e44f --- /dev/null +++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxSearchManager.java @@ -0,0 +1,93 @@ +/** + * 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.box.api; + +import java.util.ArrayList; +import java.util.Collection; + +import com.box.sdk.BoxAPIConnection; +import com.box.sdk.BoxAPIException; +import com.box.sdk.BoxFolder; +import com.box.sdk.BoxItem; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Box Search Manager + * + * <p> + * Provides operations to manage Box searches. + * + * + * + */ +public class BoxSearchManager { + + private static final Logger LOG = LoggerFactory.getLogger(BoxSearchManager.class); + + /** + * Box connection to authenticated user account. + */ + private BoxAPIConnection boxConnection; + + /** + * Create search manager to manage the searches of Box connection's + * authenticated user. + * + * @param boxConnection + * - Box connection to authenticated user account. + */ + public BoxSearchManager(BoxAPIConnection boxConnection) { + this.boxConnection = boxConnection; + } + + /** + * Search folder and all descendant folders using the given query. + * + * @param folderId + * - the id of folder searched. + * @param query + * - the search query. + * + * @return A collection of matching items. + */ + public Collection<BoxItem> searchFolder(String folderId, String query) { + try { + LOG.debug("Searching folder(id=" + folderId + ") with query=" + query); + + if (folderId == null) { + throw new IllegalArgumentException("Parameter 'folderId' can not be null"); + } + if (query == null) { + throw new IllegalArgumentException("Parameter 'query' can not be null"); + } + + BoxFolder folder = new BoxFolder(boxConnection, folderId); + + Collection<BoxItem> results = new ArrayList<BoxItem>(); + for (BoxItem.Info info : folder.search(query)) { + results.add((BoxItem) info.getResource()); + } + + 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-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxTasksManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxTasksManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxTasksManager.java new file mode 100644 index 0000000..a345e8d --- /dev/null +++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxTasksManager.java @@ -0,0 +1,324 @@ +/** + * 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.box.api; + +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.BoxTask; +import com.box.sdk.BoxTaskAssignment; +import com.box.sdk.BoxUser; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Box Tasks Manager + * + * <p> + * Provides operations to manage Box tasks. + * + * + * + */ +public class BoxTasksManager { + + private static final Logger LOG = LoggerFactory.getLogger(BoxTasksManager.class); + + /** + * Box connection to authenticated user account. + */ + private BoxAPIConnection boxConnection; + + /** + * Create tasks manager to manage the tasks of Box connection's + * authenticated user. + * + * @param boxConnection + * - Box connection to authenticated user account. + */ + public BoxTasksManager(BoxAPIConnection boxConnection) { + this.boxConnection = boxConnection; + } + + /** + * Get a list of any tasks on file. + * + * @param fileId + * - the id of file. + * @return The list of tasks on file. + */ + public List<BoxTask.Info> getFileTasks(String fileId) { + try { + LOG.debug("Getting tasks of file(id=" + fileId + ")"); + if (fileId == null) { + throw new IllegalArgumentException("Parameter 'fileId' can not be null"); + } + + BoxFile file = new BoxFile(boxConnection, fileId); + + return file.getTasks(); + + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Add task to file. + * + * @param fileId + * - the id of file to add task to. + * @param action + * - the action the task assignee will be prompted to do. + * @param dueAt + * - - the day at which this task is due. + * @param message + * - an optional message to include with the task. + * @return The new task. + */ + public BoxTask addFileTask(String fileId, BoxTask.Action action, Date dueAt, String message) { + try { + LOG.debug("Adding task to file(id=" + fileId + ") to '" + message + "'"); + if (fileId == null) { + throw new IllegalArgumentException("Parameter 'fileId' can not be null"); + } + if (action == null) { + throw new IllegalArgumentException("Parameter 'action' can not be null"); + } + if (dueAt == null) { + throw new IllegalArgumentException("Parameter 'dueAt' can not be null"); + } + + BoxFile fileToAddTaskOn = new BoxFile(boxConnection, fileId); + return (BoxTask) fileToAddTaskOn.addTask(action, message, dueAt).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 task. + * + * @param taskId + * - the id of task to delete. + */ + public void deleteTask(String taskId) { + try { + LOG.debug("Deleting task(id=" + taskId + ")"); + if (taskId == null) { + throw new IllegalArgumentException("Parameter 'taskId' can not be null"); + } + BoxTask task = new BoxTask(boxConnection, taskId); + task.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 task information. + * + * @param taskId + * - the id of task. + * @return The task information. + */ + public BoxTask.Info getTaskInfo(String taskId) { + try { + LOG.debug("Getting info for task(id=" + taskId + ")"); + if (taskId == null) { + throw new IllegalArgumentException("Parameter 'taskId' can not be null"); + } + + BoxTask task = new BoxTask(boxConnection, taskId); + + return task.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 task information. + * + * @param taskId + * - the id of task. + * @param info + * - the updated information + * @return The updated task. + */ + public BoxTask updateTaskInfo(String taskId, BoxTask.Info info) { + try { + LOG.debug("Updating info for task(id=" + taskId + ")"); + if (taskId == null) { + throw new IllegalArgumentException("Parameter 'taskId' can not be null"); + } + if (info == null) { + throw new IllegalArgumentException("Parameter 'info' can not be null"); + } + + BoxTask task = new BoxTask(boxConnection, taskId); + task.updateInfo(info); + + return task; + } 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 assignments for task. + * + * @param taskId + * - the id of task. + * @return The list of assignments for task. + */ + public List<BoxTaskAssignment.Info> getTaskAssignments(String taskId) { + try { + LOG.debug("Getting assignments for task(id=" + taskId + ")"); + if (taskId == null) { + throw new IllegalArgumentException("Parameter 'taskId' can not be null"); + } + + BoxTask file = new BoxTask(boxConnection, taskId); + + return file.getAssignments(); + + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Add assignment for task. + * + * @param taskId + * - the id of task to add assignment for. + * @param assignTo + * - the user to assign to task. + * @return The assigned task. + */ + @SuppressWarnings("unused") // compiler for some reason thinks 'if (assignTo + // == null)' clause is dead code. + public BoxTask addAssignmentToTask(String taskId, BoxUser assignTo) { + try { + LOG.debug("Assigning task(id=" + taskId + ") to user(id=" + assignTo.getID() + ")"); + if (taskId == null) { + throw new IllegalArgumentException("Parameter 'commentId' can not be null"); + } + if (assignTo == null) { + throw new IllegalArgumentException("Parameter 'assignTo' can not be null"); + } + + BoxTask task = new BoxTask(boxConnection, taskId); + task.addAssignment(assignTo); + + return task; + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Get task assignment information. + * + * @param taskAssignmentId + * - the id of task assignment. + * @return The task assignment information. + */ + public BoxTaskAssignment.Info getTaskAssignmentInfo(String taskAssignmentId) { + try { + LOG.debug("Getting info for task(id=" + taskAssignmentId + ")"); + if (taskAssignmentId == null) { + throw new IllegalArgumentException("Parameter 'taskAssignmentId' can not be null"); + } + + BoxTaskAssignment taskAssignment = new BoxTaskAssignment(boxConnection, taskAssignmentId); + + return taskAssignment.getInfo(); + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + // TODO Add this method when BoxTaskAssignment API fixed: + // BoxTaskAssignment.update method currently + // takes BoxTask.Info instead of BoxTaskAssignment.Info + // /** + // * Update task assignment information. + // * + // * @param taskAssignmentId + // * - the id of task assignment. + // * @param info + // * - the updated information + // * @return The updated task assignment. + // */ + // public BoxTaskAssignment updateTaskAssignmentInfo(String + // taskAssignmentId, BoxTaskAssignment.Info info) { + // try { + // LOG.debug("Updating info for task(id=" + taskAssignmentId + ")"); + // if (taskAssignmentId == null) { + // throw new IllegalArgumentException("Parameter 'taskAssignmentId' can not + // be null"); + // } + // if (info == null) { + // throw new IllegalArgumentException("Parameter 'info' can not be null"); + // } + // + // BoxTaskAssignment taskAssignment = new BoxTaskAssignment(boxConnection, + // taskAssignmentId); + // taskAssignment.updateInfo(info); + // + // return taskAssignment; + // } catch (BoxAPIException e) { + // throw new RuntimeException( + // String.format("Box API returned the error code %d\n\n%s", + // e.getResponseCode(), e.getResponse()), e); + // } + // } + + /** + * Delete task assignment. + * + * @param taskAssignmentId + * - the id of task assignment to delete. + */ + public void deleteTaskAssignment(String taskAssignmentId) { + try { + LOG.debug("Deleting task(id=" + taskAssignmentId + ")"); + if (taskAssignmentId == null) { + throw new IllegalArgumentException("Parameter 'taskAssignmentId' can not be null"); + } + BoxTaskAssignment taskAssignment = new BoxTaskAssignment(boxConnection, taskAssignmentId); + taskAssignment.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-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxUsersManager.java ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxUsersManager.java b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxUsersManager.java new file mode 100644 index 0000000..dda4821 --- /dev/null +++ b/components/camel-box/camel-box-api/src/main/java/org/apache/camel/component/box/api/BoxUsersManager.java @@ -0,0 +1,333 @@ +/** + * 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.box.api; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import com.box.sdk.BoxAPIConnection; +import com.box.sdk.BoxAPIException; +import com.box.sdk.BoxUser; +import com.box.sdk.CreateUserParams; +import com.box.sdk.EmailAlias; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Box Users Manager + * + * <p> + * Provides operations to manage Box users. + * + * + * + */ +public class BoxUsersManager { + + private static final Logger LOG = LoggerFactory.getLogger(BoxUsersManager.class); + + /** + * Box connection to authenticated user account. + */ + private BoxAPIConnection boxConnection; + + /** + * Create users manager to manage the users of Box connection's + * authenticated user. + * + * @param boxConnection + * - Box connection to authenticated user account. + */ + public BoxUsersManager(BoxAPIConnection boxConnection) { + this.boxConnection = boxConnection; + } + + /** + * Get current user. + * + * @return The current user. + */ + public BoxUser getCurrentUser() { + try { + LOG.debug("Getting current user"); + + return BoxUser.getCurrentUser(boxConnection); + } 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 managed users that match the filter term as well as any external + * users that match the filter term. For managed users it matches any users + * names or emails that start with the term. For external, it only does full + * match on email. This method is ideal to use in the case where you have a + * full email for a user and you don't know if they're managed or external. + * + * @param filterTerm + * - The filter term to lookup users by (login for external, + * login or name for managed); if <code>null</code> all managed + * users are returned. + * @param fields + * - the fields to retrieve. Leave this out for the standard + * fields. + * @return All the enterprise users or enterprise users that matches the + * filter. + */ + public List<BoxUser.Info> getAllEnterpriseOrExternalUsers(String filterTerm, String... fields) { + try { + LOG.debug("Getting all enterprise users matching filterTerm=" + filterTerm); + + List<BoxUser.Info> users = new ArrayList<BoxUser.Info>(); + Iterable<BoxUser.Info> iterable; + if (filterTerm == null) { + iterable = BoxUser.getAllEnterpriseUsers(boxConnection); + } else { + iterable = BoxUser.getAllEnterpriseUsers(boxConnection, filterTerm, fields); + } + for (BoxUser.Info info : iterable) { + users.add(info); + } + return users; + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Provision a new user in an enterprise with additional user information. + * + * @param login + * - the email address the user will use to login. + * @param name + * - the name of the user. + * @param params + * - additional user information. + * @return All the enterprise users or enterprise users that matches the + * filter. + */ + public BoxUser createEnterpriseUser(String login, String name, CreateUserParams params) { + try { + LOG.debug("Creating enterprise user with login=" + login + " name=" + name); + if (login == null) { + throw new IllegalArgumentException("Parameter 'login' can not be null"); + } + if (name == null) { + throw new IllegalArgumentException("Parameter 'name' can not be null"); + } + + if (params != null) { + return BoxUser.createEnterpriseUser(boxConnection, login, name, params).getResource(); + } else { + return BoxUser.createEnterpriseUser(boxConnection, login, name).getResource(); + } + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Provision a new app user in an enterprise with additional user + * information using Box Developer Edition. + * + * @param name + * - the name of the user. + * @param params + * - additional user information. + * @return All the enterprise users or enterprise users that matches the + * filter. + */ + public BoxUser createAppUser(String name, CreateUserParams params) { + try { + LOG.debug("Creating app user with name=" + name); + if (name == null) { + throw new IllegalArgumentException("Parameter 'name' can not be null"); + } + + if (params != null) { + return BoxUser.createAppUser(boxConnection, name, params).getResource(); + } else { + return BoxUser.createAppUser(boxConnection, name).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 user information. + * + * @param userId + * - the id of user. + * @return The user information. + */ + public BoxUser.Info getUserInfo(String userId) { + try { + LOG.debug("Getting info for user(id=" + userId + ")"); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + + BoxUser user = new BoxUser(boxConnection, userId); + + return user.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 user information. + * + * @param userId + * - the id of user to update. + * @param info + * - the updated information + * @return The updated user. + */ + public BoxUser updateUserInfo(String userId, BoxUser.Info info) { + try { + LOG.debug("Updating info for user(id=" + userId + ")"); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + if (info == null) { + throw new IllegalArgumentException("Parameter 'info' can not be null"); + } + + BoxUser user = new BoxUser(boxConnection, userId); + user.updateInfo(info); + return user; + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Delete user from an enterprise account. + * + * @param userId + * - the id of user to delete. + * @param notifyUser + * - whether or not to send an email notification to the user + * that their account has been deleted. + * @param force + * - whether or not this user should be deleted even if they + * still own files. + */ + public void deleteUser(String userId, boolean notifyUser, boolean force) { + try { + LOG.debug("Deleting user(id=" + userId + ") notifyUser=" + notifyUser + " force=" + force); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'fileId' can not be null"); + } + + BoxUser file = new BoxUser(boxConnection, userId); + file.delete(notifyUser, force); + } 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 new email alias to user's account. + * + * @param userId + * - the id of user. + * @param email + * - the email address to add as an alias. + * @return The newly created email alias. + */ + public EmailAlias addUserEmailAlias(String userId, String email) { + try { + LOG.debug("Adding email alias '" + email + "' to user(id=" + userId + ")"); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + if (email == null) { + throw new IllegalArgumentException("Paramerer 'email' can not be null"); + } + + BoxUser user = new BoxUser(boxConnection, userId); + + return user.addEmailAlias(email); + } 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 collection of all the email aliases for user. + * + * @param userId + * - the id of user. + * @return A collection of all the email aliases for user. + */ + public Collection<EmailAlias> getUserEmailAlias(String userId) { + try { + LOG.debug("Get email aliases for user(id=" + userId + ")"); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + + BoxUser user = new BoxUser(boxConnection, userId); + + return user.getEmailAliases(); + } catch (BoxAPIException e) { + throw new RuntimeException( + String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e); + } + } + + /** + * Delete an email alias from user's account. + * + * @param userId + * - the id of user. + * @param emailAliasId + * - the id of the email alias to delete. + */ + public void deleteUserEmailAlias(String userId, String emailAliasId) { + try { + LOG.debug("Deleting email_alias(" + emailAliasId + ") for user(id=" + userId + ")"); + if (userId == null) { + throw new IllegalArgumentException("Parameter 'userId' can not be null"); + } + if (emailAliasId == null) { + throw new IllegalArgumentException("Parameter 'emailAliasId' can not be null"); + } + + BoxUser user = new BoxUser(boxConnection, userId); + + user.deleteEmailAlias(emailAliasId); + } 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-box/camel-box-component/pom.xml ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/pom.xml b/components/camel-box/camel-box-component/pom.xml new file mode 100644 index 0000000..3f9f39d --- /dev/null +++ b/components/camel-box/camel-box-component/pom.xml @@ -0,0 +1,627 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + 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. + --> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>camel-box-parent</artifactId> + <version>2.19.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-box</artifactId> + <packaging>jar</packaging> + <name>Camel :: Box :: Component</name> + <description>Camel Box component</description> + + <properties> + <schemeName>box</schemeName> + <componentName>Box</componentName> + <componentPackage>org.apache.camel.component.box</componentPackage> + <outPackage>org.apache.camel.component.box.internal</outPackage> + <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-core</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-box-api</artifactId> + </dependency> + + <dependency> + <groupId>com.box</groupId> + <artifactId>box-java-sdk</artifactId> + <version>2.1.1</version> + </dependency> + + <dependency> + <groupId>net.sourceforge.htmlunit</groupId> + <artifactId>htmlunit</artifactId> + <version>2.24</version> + </dependency> + + <!-- Camel annotations in provided scope to avoid compile errors in IDEs --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>spi-annotations</artifactId> + <scope>provided</scope> + </dependency> + + <!-- Component API javadoc in provided scope to read API signatures --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-box-api</artifactId> + <version>${project.version}</version> + <classifier>javadoc</classifier> + <scope>provided</scope> + </dependency> + + <!-- Component API javadoc in provided scope to read API signatures --> + <dependency> + <groupId>com.box</groupId> + <artifactId>box-java-sdk</artifactId> + <version>2.1.1</version> + <classifier>javadoc</classifier> + <scope>provided</scope> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-api</artifactId> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + <scope>test</scope> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-test</artifactId> + <scope>test</scope> + </dependency> + </dependencies> + + <build> + <defaultGoal>install</defaultGoal> + + <plugins> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + </plugin> + + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <executions> + <execution> + <id>generate-test-component-classes</id> + <goals> + <goal>fromApis</goal> + </goals> + <configuration> + <apis> + <api> + <apiName>collaborations</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxCollaborationsManager</proxyClass> + <fromJavadoc /> + <aliases> + <alias> + <methodPattern>addFolderCollaboration</methodPattern> + <methodAlias>add</methodAlias> + </alias> + <alias> + <methodPattern>addFolderCollaborationByEmail</methodPattern> + <methodAlias>addByEmail</methodAlias> + </alias> + <alias> + <methodPattern>deleteCollaboration</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>getFolderCollaborations</methodPattern> + <methodAlias>collaborations</methodAlias> + </alias> + <alias> + <methodPattern>getPendingCollaborations</methodPattern> + <methodAlias>pendingCollaborations</methodAlias> + </alias> + <alias> + <methodPattern>getCollaborationInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>updateCollaborationInfo</methodPattern> + <methodAlias>updateInfo</methodAlias> + </alias> + </aliases> + </api> + <api> + <apiName>comments</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxCommentsManager</proxyClass> + <fromJavadoc /> + <aliases> + <alias> + <methodPattern>addFileComment</methodPattern> + <methodAlias>add</methodAlias> + </alias> + <alias> + <methodPattern>changeCommentMessage</methodPattern> + <methodAlias>updateMessage</methodAlias> + </alias> + <alias> + <methodPattern>deleteComment</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>getCommentInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>getFileComments</methodPattern> + <methodAlias>comments</methodAlias> + </alias> + <alias> + <methodPattern>replyToComment</methodPattern> + <methodAlias>reply</methodAlias> + </alias> + </aliases> + </api> + <api> + <apiName>event-logs</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxEventLogsManager</proxyClass> + <fromJavadoc /> + <aliases> + <alias> + <methodPattern>getEnterpriseEvents</methodPattern> + <methodAlias>events</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>position</nullableOption> + <nullableOption>types</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>files</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxFilesManager</proxyClass> + <fromJavadoc /> + <aliases> + <alias> + <methodPattern>uploadFile</methodPattern> + <methodAlias>upload</methodAlias> + </alias> + <alias> + <methodPattern>downloadFile</methodPattern> + <methodAlias>download</methodAlias> + </alias> + <alias> + <methodPattern>copyFile</methodPattern> + <methodAlias>copy</methodAlias> + </alias> + <alias> + <methodPattern>moveFile</methodPattern> + <methodAlias>move</methodAlias> + </alias> + <alias> + <methodPattern>renameFile</methodPattern> + <methodAlias>rename</methodAlias> + </alias> + <alias> + <methodPattern>createFileSharedLink</methodPattern> + <methodAlias>link</methodAlias> + </alias> + <alias> + <methodPattern>deleteFile</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>uploadNewFileVersion</methodPattern> + <methodAlias>uploadVersion</methodAlias> + </alias> + <alias> + <methodPattern>promoteFileVersion</methodPattern> + <methodAlias>promoteVersion</methodAlias> + </alias> + <alias> + <methodPattern>getFileVersions</methodPattern> + <methodAlias>versions</methodAlias> + </alias> + <alias> + <methodPattern>downloadPreviousFileVersions</methodPattern> + <methodAlias>downloadVersion</methodAlias> + </alias> + <alias> + <methodPattern>deleteFileVersion</methodPattern> + <methodAlias>deleteVersion</methodAlias> + </alias> + <alias> + <methodPattern>getFileInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>updateFileInfo</methodPattern> + <methodAlias>updateInfo</methodAlias> + </alias> + <alias> + <methodPattern>createFileMetadata</methodPattern> + <methodAlias>createMetadata</methodAlias> + </alias> + <alias> + <methodPattern>getFileMetadata</methodPattern> + <methodAlias>metadata</methodAlias> + </alias> + <alias> + <methodPattern>updateFileMetadata</methodPattern> + <methodAlias>updateMetadata</methodAlias> + </alias> + <alias> + <methodPattern>deleteFileMetadata</methodPattern> + <methodAlias>deleteMetadata</methodAlias> + </alias> + <alias> + <methodPattern>getDownloadUrl</methodPattern> + <methodAlias>url</methodAlias> + </alias> + <alias> + <methodPattern>getPreviewLink</methodPattern> + <methodAlias>preview</methodAlias> + </alias> + <alias> + <methodPattern>getFileThumbnail</methodPattern> + <methodAlias>thumbnail</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>fields</nullableOption> + <nullableOption>created</nullableOption> + <nullableOption>modified</nullableOption> + <nullableOption>size</nullableOption> + <nullableOption>fileSize</nullableOption> + <nullableOption>rangeStart</nullableOption> + <nullableOption>rangeEnd</nullableOption> + <nullableOption>listener</nullableOption> + <nullableOption>fileSize</nullableOption> + <nullableOption>newName</nullableOption> + <nullableOption>unshareDate</nullableOption> + <nullableOption>permissions</nullableOption> + <nullableOption>typeName</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>folders</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxFoldersManager</proxyClass> + <fromJavadoc> + </fromJavadoc> + <aliases> + <alias> + <methodPattern>getRootFolder</methodPattern> + <methodAlias>root</methodAlias> + </alias> + <alias> + <methodPattern>createFolder</methodPattern> + <methodAlias>create</methodAlias> + </alias> + <alias> + <methodPattern>copyFolder</methodPattern> + <methodAlias>copy</methodAlias> + </alias> + <alias> + <methodPattern>moveFolder</methodPattern> + <methodAlias>move</methodAlias> + </alias> + <alias> + <methodPattern>renameFolder</methodPattern> + <methodAlias>rename</methodAlias> + </alias> + <alias> + <methodPattern>createFolderSharedLink</methodPattern> + <methodAlias>link</methodAlias> + </alias> + <alias> + <methodPattern>deleteFolder</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>getFolder</methodPattern> + <methodAlias>folder</methodAlias> + </alias> + <alias> + <methodPattern>getFolderInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>getFolderItems</methodPattern> + <methodAlias>items</methodAlias> + </alias> + <alias> + <methodPattern>updateFolderInfo</methodPattern> + <methodAlias>updateInfo</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>offset</nullableOption> + <nullableOption>limit</nullableOption> + <nullableOption>fields</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>groups</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxGroupsManager</proxyClass> + <fromJavadoc> + </fromJavadoc> + <aliases> + <alias> + <methodPattern>createGroup</methodPattern> + <methodAlias>create</methodAlias> + </alias> + <alias> + <methodPattern>deleteGroup</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>getAllGroups</methodPattern> + <methodAlias>groups</methodAlias> + </alias> + <alias> + <methodPattern>getGroupInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>addGroupMembership</methodPattern> + <methodAlias>addMembership</methodAlias> + </alias> + <alias> + <methodPattern>deleteGroupMembership</methodPattern> + <methodAlias>deleteMembership</methodAlias> + </alias> + <alias> + <methodPattern>getGroupMemberships</methodPattern> + <methodAlias>memberships</methodAlias> + </alias> + <alias> + <methodPattern>getGroupMembershipInfo</methodPattern> + <methodAlias>membershipInfo</methodAlias> + </alias> + <alias> + <methodPattern>updateGroupMembershipInfo</methodPattern> + <methodAlias>updateMembershipInfo</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>role</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>events</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxEventsManager</proxyClass> + <fromJavadoc> + <excludeMethods>stopListening</excludeMethods> + </fromJavadoc> + <excludeConfigNames>listener</excludeConfigNames> + <nullableOptions> + <nullableOption>startingPosition</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>search</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxSearchManager</proxyClass> + <fromJavadoc/> + <aliases> + <alias> + <methodPattern>searchFolder</methodPattern> + <methodAlias>search</methodAlias> + </alias> + </aliases> + </api> + <api> + <apiName>tasks</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxTasksManager</proxyClass> + <fromJavadoc> + </fromJavadoc> + <aliases> + <alias> + <methodPattern>addFileTask</methodPattern> + <methodAlias>add</methodAlias> + </alias> + <alias> + <methodPattern>deleteTask</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>getFileTasks</methodPattern> + <methodAlias>tasks</methodAlias> + </alias> + <alias> + <methodPattern>getTaskInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>updateTaskInfo</methodPattern> + <methodAlias>updateInfo</methodAlias> + </alias> + <alias> + <methodPattern>addAssignmentToTask</methodPattern> + <methodAlias>addAssignment</methodAlias> + </alias> + <alias> + <methodPattern>deleteTaskAssignment</methodPattern> + <methodAlias>deleteAssignment</methodAlias> + </alias> + <alias> + <methodPattern>getTaskAssignments</methodPattern> + <methodAlias>assignments</methodAlias> + </alias> + <alias> + <methodPattern>getTaskAssignmentInfo</methodPattern> + <methodAlias>assignmentInfo</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>message</nullableOption> + </nullableOptions> + </api> + <api> + <apiName>users</apiName> + <proxyClass>org.apache.camel.component.box.api.BoxUsersManager</proxyClass> + <fromJavadoc/> + <aliases> + <alias> + <methodPattern>getCurrentUser</methodPattern> + <methodAlias>currentUser</methodAlias> + </alias> + <alias> + <methodPattern>getAllEnterpriseOrExternalUsers</methodPattern> + <methodAlias>users</methodAlias> + </alias> + <alias> + <methodPattern>createAppUser</methodPattern> + <methodAlias>create</methodAlias> + </alias> + <alias> + <methodPattern>createEnterpriseUser</methodPattern> + <methodAlias>create</methodAlias> + </alias> + <alias> + <methodPattern>deleteUser</methodPattern> + <methodAlias>delete</methodAlias> + </alias> + <alias> + <methodPattern>addUserEmailAlias</methodPattern> + <methodAlias>addEmailAlias</methodAlias> + </alias> + <alias> + <methodPattern>getUserEmailAlias</methodPattern> + <methodAlias>emailAlias</methodAlias> + </alias> + <alias> + <methodPattern>deleteUserEmailAlias</methodPattern> + <methodAlias>deleteEmailAlias</methodAlias> + </alias> + <alias> + <methodPattern>getUserInfo</methodPattern> + <methodAlias>info</methodAlias> + </alias> + <alias> + <methodPattern>updateUserInfo</methodPattern> + <methodAlias>updateInfo</methodAlias> + </alias> + </aliases> + <nullableOptions> + <nullableOption>filterTerm</nullableOption> + <nullableOption>fields</nullableOption> + <nullableOption>params</nullableOption> + </nullableOptions> + </api> + </apis> + <!-- Specify global values for all APIs here, these are overridden + at API level <substitutions/> <excludeConfigNames/> <excludeConfigTypes/> + <extraOptions> <fromJavadoc/> <aliases/> --> + </configuration> + </execution> + </executions> + </plugin> + + <!-- add generated source and test source to build --> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <id>add-generated-sources</id> + <goals> + <goal>add-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-sources/camel-component</source> + </sources> + </configuration> + </execution> + <execution> + <id>add-generated-test-sources</id> + <goals> + <goal>add-test-source</goal> + </goals> + <configuration> + <sources> + <source>${project.build.directory}/generated-test-sources/camel-component</source> + </sources> + </configuration> + </execution> + </executions> + </plugin> + + </plugins> + + <pluginManagement> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </pluginManagement> + + </build> + + <reporting> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-api-component-maven-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <scheme>${schemeName}</scheme> + <componentName>${componentName}</componentName> + <componentPackage>${componentPackage}</componentPackage> + <outPackage>${outPackage}</outPackage> + </configuration> + </plugin> + </plugins> + </reporting> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/db0ca734/components/camel-box/camel-box-component/src/main/docs/box2-component.adoc ---------------------------------------------------------------------- diff --git a/components/camel-box/camel-box-component/src/main/docs/box2-component.adoc b/components/camel-box/camel-box-component/src/main/docs/box2-component.adoc new file mode 100644 index 0000000..1e3a810 --- /dev/null +++ b/components/camel-box/camel-box-component/src/main/docs/box2-component.adoc @@ -0,0 +1,744 @@ +## Box Component + +*Available as of Camel version * + +The Box component provides access to all of the Box.com APIs accessible +using https://github.com/box/box-java-sdk/[box-java-sdk]. It +allows producing messages to upload and download files, create, edit, +and manage folders, etc. It also supports APIs that allow polling for +updates to user accounts and even changes to enterprise accounts, etc. + +Box.com requires the use of OAuth2.0 for all client application +authentication. In order to use camel-box with your account, you'll need +to create a new application within Box.com at +https://app.box.com/developers/services/edit/[https://app.box.com/developers/services/edit/]. +The Box application's client id and secret will allow access to Box APIs +which require a current user. A user access token is generated and +managed by the API for an end user. + +Maven users will need to add the following dependency to their pom.xml +for this component: + +[source,java] +------------------------------------------- + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-box</artifactId> + <version>${camel-version}</version> + </dependency> +------------------------------------------- + +### Connection Authentication Types + +The Box component supports three different types of authenticated connections. + +#### Standard Authentication + +*Standard Authentication* uses the *OAuth 2.0 three-legged authentication process* to authenticate its connections with Box.com. This type of authentication enables Box *managed users* and *external users* to access, edit, and save their Box content through the Box component. + +#### App Enterprise Authentication + +*App Enterprise Authentication* uses the *OAuth 2.0 with JSON Web Tokens (JWT)* to authenticate its connections as a *Service Account* for a *Box Application*. This type of authentication enables a service account to access, edit, and save the Box content of its *Box Application* through the Box component. + +#### App User Authentication + +*App User Authentication* uses the *OAuth 2.0 with JSON Web Tokens (JWT)* to authenticate its connections as an *App User* for a *Box Application*. This type of authentication enables app users to access, edit, and save their Box content in its *Box Application* through the Box component. + +### URI format + +[source,java] +-------------------------------------------- + box://endpoint-prefix/endpoint?[options] +-------------------------------------------- + +Endpoint prefix can be one of: + +* collaborations +* comments +* event-logs +* files +* folders +* groups +* events +* search +* tasks +* users + +### BoxComponent + +The Box Component can be configured with the options below. These +options can be provided using the component's bean +property *`configuration`* of +type *`org.apache.camel.component.box.BoxConfiguration`*. These options +can also be specified in the endpoint URI. + +[width="100%",cols="10%,10%,80%",options="header",] +|======================================================================= custom access token cachecom.box.sdk +|Option |Type |Description + +|accessTokenCache |com.box.sdk.IAccessTokenCache |A custom access token cache. For production applications it is recommended to use a distributed cache like Memcached or Redis, and to implement this interface to store and retrieve access tokens appropriately for your environment; when not set an internal access token cache is used; ONLY used when using App Enterprise or User authentication. + +|clientId |String |Box application client ID + +|clientSecret |String |Box application client secret + +|encryptionAlgorithm |com.box.sdk.EncryptionAlgorithm |Algorithm used by OAuth 2.0 with JWT; MUST be provided when using App Enterprise and User authentication + +|enterpriseId |String |The enterprise ID to use for requesting access token; MUST be provided when using App Enterprise authentication + +|httpParams |java.util.Map |Custom HTTP params for settings like proxy host + +|maxCacheEntries |Integer |The maximum number of access tokens in cache; ONLY used when internal access token cache is used + +|privateKeyFile |String |Path to file containing private key used to generate signature in OAuth 2.0 with JWT; MUST be provided when using App Enterprise and User authentication + +|privateKeyPassword |String |Password for private key; only used for App Enterprise and User authentication; MUST be provided when using App Enterprise and User authentication + +|publicKeyId |String |The ID of public key used to generate signature in OAuth 2.0 with JWT; MUST be provided when using App Enterprise and User authentication + +|userId |String |The user ID to use for an App user Authentication; MUST be provided when using App User authentication + +|userName |String |Box user name for a Managed user; MUST be provided when using Standard Authentication + +|userPassword |String |Box user password, MUST be provided when using Standard Authentication and if authSecureStorage is not set, or +returns null on first call +|======================================================================= + +### Producer Endpoints: + +Producer endpoints can use endpoint prefixes followed by endpoint names +and associated options described next. A shorthand alias can be used for +some endpoints. The endpoint URI MUST contain a prefix. + +Endpoint options that are not mandatory are denoted by *[]*. When there +are no mandatory options for an endpoint, one of the set of *[]* options +MUST be provided. Producer endpoints can also use a special +option *`inBody`* that in turn should contain the name of the endpoint +option whose value will be contained in the Camel Exchange In message. + +Any of the endpoint options can be provided in either the endpoint URI, +or dynamically in a message header. The message header name must be of +the format *`CamelBox.<option>`*. Note that the *`inBody`* option +overrides message header, i.e. the endpoint +option *`inBody=option`* would override a *`CamelBox.option`* header. + +If a value is not provided for the option *defaultRequest* either in the +endpoint URI or in a message header, it will be assumed to be `null`. +Note that the `null` value will only be used if other options do not +satisfy matching endpoints. + +In case of Box API errors the endpoint will throw a +RuntimeCamelException with a +*com.box.sdk.BoxAPIException* derived exception +cause. + +#### Endpoint Prefix _collaborations_ + +For more information on Box collaborations see +https://docs.box.com/reference#collaboration-object[https://docs.box.com/reference#collaboration-object]. The +following endpoints can be invoked with the prefix *`collaborations`* as +follows: + +[source,java] +------------------------------------------- + box://collaborations/endpoint?[options] +------------------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|addFolderCollaboration |add |folderId, collaborator, role |com.box.sdk.BoxCollaboration + +|addFolderCollaborationByEmail |addByEmail |folderId, email, role |com.box.sdk.BoxCollaboration + +|deleteCollaboration |delete |collaborationId | + +|getFolderCollaborations |collaborations |folderId |java.util.Collection + +|getPendingCollaborations |pendingCollaborations | |java.util.Collection + +|getCollaborationInfo |info |collaborationId |com.box.sdk.BoxCollaboration.Info + +|updateCollaborationInfo |updateInfo |collaborationId, info |com.box.sdk.BoxCollaboration +|======================================================================= + +[[Box-URIOptionsforcollaborations]] +URI Options for _collaborations_ + + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|collaborationId |String + +|collaborator |com.box.sdk.BoxCollaborator + +|role |com.box.sdk.BoxCollaboration.Role + +|folderId |String + +|email |String + +|info |com.box.sdk.BoxCollaboration.Info +|======================================================================= + +#### Endpoint Prefix _comments_ + +For more information on Box comments see +https://docs.box.com/reference#comment-object[https://docs.box.com/reference#comment-object]. The +following endpoints can be invoked with the prefix *`comments`* as +follows: + +[source,java] +------------------------------------------- + box://comments/endpoint?[options] +------------------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|addFileComment |add |fileId, message |com.box.sdk.BoxFile + +|changeCommentMessage |updateMessage |commentId, message |com.box.sdk.BoxComment + +|deleteComment |delete |commentId | + +|getCommentInfo |info |commentId |com.box.sdk.BoxComment.Info + +|getFileComments |comments |fileId |java.util.List + +|replyToComment |reply |commentId, message |com.box.sdk.BoxComment +|======================================================================= + +[[Box-URIOptionsforcollaborations]] +URI Options for _collaborations_ + + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|commentId |String + +|fileId |String + +|message |String + +|======================================================================= + +#### Endpoint Prefix _events-logs_ + +For more information on Box event logs see +https://docs.box.com/reference#events[https://docs.box.com/reference#events]. +The following endpoints can be invoked with the prefix *`events`* as follows: + +[source,java] +--------------------------------- + box://event-logs/endpoint?[options] +--------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|getEnterpriseEvents |events |position, after, before, [types] |java.util.List +|======================================================================= + +[[Box-URIOptionsforevent-logs]] +URI Options for _event-logs_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|position |String + +|after |Date + +|before |Date + +|types |com.box.sdk.BoxEvent.Types[] +|======================================================================= + +#### Endpoint Prefix _files_ + +For more information on Box files see +https://docs.box.com/reference#file-object[https://docs.box.com/reference#file-object]. +The following endpoints can be invoked with the +prefix *`files`* as follows. + +[source,java] +---------------------------------------- + box://files/endpoint?[options] +---------------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|uploadFile |upload |parentFolderId, content, fileName, [created], [modified], [size], [listener] |com.box.sdk.BoxFile + +|downloadFile |download |fileId, output, [rangeStart], [rangeEnd], [listener] |java.io.OutputStream + +|copyFile |copy |fileId, destinationFolderId, [newName] |com.box.sdk.BoxFile + +|moveFile |move |fileId, destinationFolderId, [newName] |com.box.sdk.BoxFile + +|renameFile |rename |fileId, newFileName |com.box.sdk.BoxFile + +|createFileSharedLink |link |fileId, access, [unshareDate], [permissions] |com.box.sdk.BoxSharedLink + +|deleteFile |delete |fileId | + +|uploadNewFileVersion |uploadVersion |fileId, fileContent, [modified], [fileSize], [listener] |com.box.boxsdk.BoxFile + +|promoteFileVersion |promoteVersion |fileId, version |com.box.sdk.BoxFileVersion + +|getFileVersions |versions |fileId |java.util.Collection + +|downloadPreviousFileVersions |downloadVersion |fileId, version, output, [listener] |java.io.OutputStream + +|deleteFileVersion |deleteVersion |fileId, version | + +|getFileInfo |info |fileId, fields |com.box.sdk.BoxFile.Info + +|updateFileInfo |updateInfo |fileId, info |com.box.sdk.BoxFile + +|createFileMetadata |createMetadata |fileId, metadata, [typeName] |com.box.sdk.Metadata + +|getFileMetadata |metadata |fileId, [typeName] |com.box.sdk.Metadata + +|updateFileMetadata |updateMetadata |fileId, metadata |com.box.sdk.Metadata + +|deleteFileMetadata |deleteMetadata |fileId | + +|getDownloadUrl |url |fileId |java.net.URL + +|getPreviewLink |preview |fileId |java.net.URL + +|getFileThumbnail |thumbnail |fileId, fileType, minWidth, minHeight, maxWidth, maxHeight |byte[] +|======================================================================= + +[[Box-URIOptionsforfiles]] +URI Options for _files_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|parentFolderId |String + +|content |java.io.InputStream + +|fileName |String + +|created |Date + +|modified |Date + +|size |Long + +|listener |com.box.sdk.ProgressListener + +|output |java.io.OutputStream + +|rangeStart |Long + +|rangeEnd |Long + +|outputStreams |java.io.OutputStream[] + +|destinationFolderId |String + +|newName |String + +|fields |String[] + +|info |com.box.sdk.BoxFile.Info + +|fileSize |Long + +|version |Integer + +|access |com.box.sdk.BoxSharedLink.Access + +|unshareDate |Date + +|permissions |com.box.sdk.BoxSharedLink.Permissions + +|fileType |com.box.sdk.BoxFile.ThumbnailFileType + +|minWidth |Integer + +|minHeight |Integer + +|maxWidth |Integer + +|maxHeight |Integer + +|metadata |com.box.sdk.Metadata + +|typeName |String +|======================================================================= + +#### Endpoint Prefix _folders_ + +For more information on Box folders see +https://docs.box.com/reference#folder-object[https://docs.box.com/reference#folder-object]. +The following endpoints can be invoked with the prefix +*`folders`* as follows. + +[source,java] +------------------------------------------- + box://folders/endpoint?[options] +------------------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|getRootFolder |root | |com.box.sdk.BoxFolder + +|createFolder |create |parentFolderId, folderName |com.box.sdk.BoxFolder + +|copyFolder |copy |folderId, destinationfolderId, [newName] |com.box.sdk.BoxFolder + +|moveFolder |move |folderId, destinationFolderId, newName |com.box.sdk.BoxFolder + +|renameFolder |rename |folderId, newFolderName |com.box.sdk.BoxFolder + +|createFolderSharedLink |link |folderId, access, [unsharedDate], [permissions] |java.util.List + +|deleteFolder |delete |folderId | + +|getFolder |folder |path |com.box.sdk.BoxFolder + +|getFolderInfo |info |folderId, fields |com.box.sdk.BoxFolder.Info + +|getFolderItems |items |folderId, offset, limit, fields |com.box.sdk.BoxFolder + +|updateFolderInfo |updateInfo |folderId, info |com.box.sdk.BoxFolder +|======================================================================= + +[[Box-URIOptionsforfolders]] +URI Options for _folders_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|path |String[] + +|folderId |String + +|offset |Long + +|limit |Long + +|fields |String[] + +|parentFolderId |String + +|folderName |String + +|destinationFolderId |String + +|newName |String + +|newFolderName |String + +|info |String + +|access |com.box.sdk.BoxSharedLink.Access + +|unshareDate |Date + +|permissions |com.box.sdk.BoxSharedLink.Permissions +|======================================================================= + +#### Endpoint Prefix _groups_ + +For more information on Box groups see +https://docs.box.com/reference#group-object[https://docs.box.com/reference#group-object]. +The following endpoints can be invoked with the prefix *`groups`* as +follows: + +[source,java] +----------------------------------- + box://groups/endpoint?[options] +----------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|createGroup |create |name |com.box.sdk.BoxGroup + +|addGroupMembership |createMembership |groupId, userId, role |com.box.sdk.BoxGroupMembership + +|deleteGroup |delete |groupId | + +|getAllGroups |groups | |java.util.Collection + +|getGroupInfo |info |groupId |com.box.sdk.BoxGroup.Info + +|addGroupMembership |addMembership |groupId, userId, role |com.box.sdk.BoxGroupMembership + +|deleteGroupMembership |deleteMembership |groupMembershipId | + +|getGroupMemberships |memberships |groupId |java.uti.Collection + +|getGroupMembershipInfo |membershipInfo |groupMemebershipId |com.box.sdk.BoxGroup.Info + +|updateGroupMembershipInfo |updateMembershipInfo |groupMemebershipId, info |com.box.sdk.BoxGroupMembership +|======================================================================= + +[[Box-URIOptionsforgroups]] +URI Options for _groups_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|name |String + +|groupId |String + +|userId |String + +|role |com.box.sdk.BoxGroupMembership.Role + +|groupMembershipId |String + +|info |com.box.sdk.BoxGroupMembership.Info + +|======================================================================= + +#### Endpoint Prefix _search_ + +For more information on Box search API see +https://docs.box.com/reference#searching-for-content[https://docs.box.com/reference#searching-for-content]. The +following endpoints can be invoked with the prefix *`search`* as +follows: + +[source,java] +----------------------------------- + box://search/endpoint?[options] +----------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|searchFolder |search |folderId, query |java.util.Collection +|======================================================================= + +[[Box-URIOptionsforsearch]] +URI Options for _search_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|folderId |String + +|query |String +|======================================================================= + +#### Endpoint Prefix _tasks_ + +For information on Box tasks see +https://docs.box.com/reference#task-object-1[https://docs.box.com/reference#task-object-1]. +The following endpoints can be invoked with the prefix *`tasks`* as +follows: + +[source,java] +---------------------------------- + box://tasks/endpoint?[options] +---------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|addFileTask |add |fileId, action, dueAt, [message] |com.box.sdk.BoxUser + +|deleteTask |delete |taskId | + +|getFileTasks |tasks |fileId |java.util.List + +|getTaskInfo |info |taskId |com.box.sdk.BoxTask.Info + +|updateTaskInfo |updateInfo |taskId, info |com.box.sdk.BoxTask + +|addAssignmentToTask |addAssignment |taskId, assignTo |com.box.sdk.BoxTask + +|deleteTaskAssignment |deleteAssignment |taskAssignmentId | + +|getTaskAssignments |assignments | taskId |java.util.List + +|getTaskAssignmentInfo |assignmentInfo |taskAssignmentId |com.box.sdk.BoxTaskAssignment.Info +|======================================================================= + +[[Box-URIOptionsfortasks]] +URI Options for _tasks_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|fileId |String + +|action |com.box.sdk.BoxTask.Action + +|dueAt |Date + +|message |String + +|taskId |String + +|info |com.box.sdk.BoxTask.Info + +|assignTo |com.box.sdk.BoxUser + +|taskAssignmentId |String +|======================================================================= + +#### Endpoint Prefix _users_ + +For information on Box users see +https://docs.box.com/reference#user-object[https://docs.box.com/reference#user-object]. +The following endpoints can be invoked with the prefix *`users`* as +follows: + +[source,java] +---------------------------------- + box://users/endpoint?[options] +---------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|getCurrentUser |currentUser | |com.box.sdk.BoxUser + +|getAllEnterpriseOrExternalUsers |users |filterTerm, [fields] |com.box.sdk.BoxUser + +|createAppUser |create |name, [params] |com.box.sdk.BoxUser + +|createEnterpriseUser |create |login, name, [params] |com.box.sdk.BoxUser + +|deleteUser |delete |userId, notifyUser, force | + +|getUserEmailAlias |emailAlias |userId |com.box.sdk.BoxUser + +|deleteUserEmailAlias |deleteEmailAlias |userId, emailAliasId |java.util.List + +|getUserInfo |info | userId |com.box.sdk.BoxUser.Info + +|updateUserInfo |updateInfo |userId, info |com.box.sdk.BoxUser +|======================================================================= + +[[Box-URIOptionsforusers]] +URI Options for _users_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|defaultRequest |com.box.restclientv2.requestsbase.BoxDefaultRequestObject + +|emailAliasRequest |com.box.boxjavalibv2.requests.requestobjects.BoxEmailAliasRequestObject + +|emailId |String + +|filterTerm |String + +|folderId |String + +|simpleUserRequest |com.box.boxjavalibv2.requests.requestobjects.BoxSimpleUserRequestObject + +|userDeleteRequest |com.box.boxjavalibv2.requests.requestobjects.BoxUserDeleteRequestObject + +|userId |String + +|userRequest |com.box.boxjavalibv2.requests.requestobjects.BoxUserRequestObject + +|userUpdateLoginRequest |com.box.boxjavalibv2.requests.requestobjects.BoxUserUpdateLoginRequestObject +|======================================================================= + +### Consumer Endpoints: + +For more information on Box events see +https://docs.box.com/reference#events[https://docs.box.com/reference#events]. +Consumer endpoints can only use the endpoint prefix *events* as +shown in the example next. + +[source,java] +---------------------------------------- + box://events/endpoint?[options] +---------------------------------------- + +[width="100%",cols="10%,10%,10%,70%",options="header",] +|======================================================================= +|Endpoint |Shorthand Alias |Options |Result Body Type + +|events | |[startingPosition] |com.box.sdk.BoxEvent +|======================================================================= + +[[Box-URIOptionsforevents]] +URI Options for _events_ + +[width="100%",cols="10%,90%",options="header",] +|======================================================================= +|Name |Type + +|startingPosition |Long +|======================================================================= + +### Message header + +Any of the options can be provided in a message header for producer +endpoints with *CamelBox.* prefix. + +### Message body + +All result message bodies utilize objects provided by the Box Java SDK. +Producer endpoints can specify the option name for incoming message body +in the *inBody* endpoint parameter. + +### Use cases + +The following route uploads new files to the user's root folder: + +[source,java] +----------------------------------------------------------- + from("file:...") + .to("box://files/upload/inBody=fileUploadRequest"); +----------------------------------------------------------- + +The following route polls user's account for updates: + +[source,java] +----------------------------------------------------------------------------- + from("box://events/listen?startingPosition=-1") + .to("bean:blah"); +----------------------------------------------------------------------------- + +The following route uses a producer with dynamic header options. The +*fileId* property has the Box file id and the *output* property has +the output stream of the file contents, so they are assigned to the +*CamelBox.fileId* header and *CamelBox.output* header respectively +as follows: + +[source,java] +------------------------------------------------------- + from("direct:foo") + .setHeader("CamelBox.fileId", header("fileId")) + .setHeader("CamelBox.output", header("output")) + .to("box://files/download") + .to("file://..."); +-------------------------------------------------------