Search in sources :

Example 26 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxFoldersManager method getFolder.

/**
     * Return the Box folder referenced by <code>path</code>.
     * 
     * @param path
     *            - Sequence of Box folder names from root folder to returned
     *            folder.
     * 
     * @return The Box folder referenced by <code>path</code> or
     *         <code>null</code> 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);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 27 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxGroupsManager method addGroupMembership.

/**
     * 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);
    }
}
Also used : BoxGroup(com.box.sdk.BoxGroup) BoxAPIException(com.box.sdk.BoxAPIException) BoxUser(com.box.sdk.BoxUser)

Example 28 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxGroupsManager method deleteGroupMembership.

/**
     * 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);
    }
}
Also used : BoxGroupMembership(com.box.sdk.BoxGroupMembership) BoxAPIException(com.box.sdk.BoxAPIException)

Example 29 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxTasksManager method getFileTasks.

/**
     * 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);
    }
}
Also used : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException)

Example 30 with BoxAPIException

use of com.box.sdk.BoxAPIException in project camel by apache.

the class BoxTasksManager method getTaskInfo.

/**
     * 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);
    }
}
Also used : BoxTask(com.box.sdk.BoxTask) BoxAPIException(com.box.sdk.BoxAPIException)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)74 BoxFile (com.box.sdk.BoxFile)24 BoxFolder (com.box.sdk.BoxFolder)17 BoxUser (com.box.sdk.BoxUser)8 BoxTask (com.box.sdk.BoxTask)6 BoxCollaboration (com.box.sdk.BoxCollaboration)4 BoxComment (com.box.sdk.BoxComment)4 BoxGroup (com.box.sdk.BoxGroup)4 BoxFileVersion (com.box.sdk.BoxFileVersion)3 BoxGroupMembership (com.box.sdk.BoxGroupMembership)3 FailingHttpStatusCodeException (com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException)3 IOException (java.io.IOException)3 GeneralSecurityException (java.security.GeneralSecurityException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Test (org.junit.Test)3 BoxItem (com.box.sdk.BoxItem)2 BoxTaskAssignment (com.box.sdk.BoxTaskAssignment)2 IAccessTokenCache (com.box.sdk.IAccessTokenCache)2