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);
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations