Search in sources :

Example 56 with BoxAPIException

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

the class BoxFilesManager method moveFile.

/**
     * 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 <code>newName</code> is
     *            <code>null</code>, 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);
    }
}
Also used : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 57 with BoxAPIException

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

the class BoxTasksManager method updateTaskInfo.

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

Example 58 with BoxAPIException

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

the class BoxUsersManager method deleteUser.

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

Example 59 with BoxAPIException

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

the class BoxUsersManager method addUserEmailAlias.

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

Example 60 with BoxAPIException

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

the class BoxUsersManager method getUserEmailAlias.

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

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