Search in sources :

Example 46 with BoxAPIException

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

the class BoxFilesManager method copyFile.

/**
     * Copy file to destination folder while optionally giving it a new name.
     * 
     * @param fileId
     *            - the id of file to copy.
     * @param destinationFolderId
     *            - the id of the destination folder.
     * @param newName
     *            - the new name for copied file; if <code>newName</code> is
     *            <code>null</code>, the copied file has same name as the
     *            original.
     * @return The copied file.
     */
public BoxFile copyFile(String fileId, String destinationFolderId, String newName) {
    try {
        LOG.debug("Copying file(id=" + fileId + ") to destination_folder(id=" + destinationFolderId + ")" + (newName == null ? "" : " with new name '" + newName + "'"));
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (destinationFolderId == null) {
            throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null");
        }
        BoxFile fileToCopy = new BoxFile(boxConnection, fileId);
        BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId);
        if (newName == null) {
            return fileToCopy.copy(destinationFolder).getResource();
        } else {
            return fileToCopy.copy(destinationFolder, newName).getResource();
        }
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 47 with BoxAPIException

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

the class BoxFoldersManager method copyFolder.

/**
     * Copy folder to destination folder while optionally giving it a new name.
     * 
     * @param folderId
     *            - the id of folder to copy.
     * @param destinationFolderId
     *            - the id of the destination folder.
     * @param newName
     *            - the new name for copied folder; if <code>newName</code> is
     *            <code>null</code>, the copied folder has same name as the
     *            original.
     * @return The copied folder.
     */
public BoxFolder copyFolder(String folderId, String destinationFolderId, String newName) {
    try {
        LOG.debug("Copying folder(id=" + folderId + ") to destination_folder(id=" + destinationFolderId + ")" + (newName == null ? "" : " with new name '" + newName + "'"));
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (destinationFolderId == null) {
            throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null");
        }
        BoxFolder folderToCopy = new BoxFolder(boxConnection, folderId);
        BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId);
        if (newName == null) {
            return folderToCopy.copy(destinationFolder).getResource();
        } else {
            return folderToCopy.copy(destinationFolder, newName).getResource();
        }
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 48 with BoxAPIException

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

the class BoxFoldersManager method updateFolderInfo.

/**
     * Update folder information.
     * 
     * @param folderId
     *            - the id of folder to update.
     * @param info
     *            - the updated information
     * @return The updated folder.
     */
public BoxFolder updateFolderInfo(String folderId, BoxFolder.Info info) {
    try {
        LOG.debug("Updating info for folder(id=" + folderId + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (info == null) {
            throw new IllegalArgumentException("Parameter 'info' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        folder.updateInfo(info);
        return folder;
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 49 with BoxAPIException

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

the class BoxCommentsManager method getCommentInfo.

/**
     * Get comment information.
     * 
     * @param commentId
     *            - the id of comment.
     * @return The comment information.
     */
public BoxComment.Info getCommentInfo(String commentId) {
    try {
        LOG.debug("Getting info for comment(id=" + commentId + ")");
        if (commentId == null) {
            throw new IllegalArgumentException("Parameter 'commentId' can not be null");
        }
        BoxComment comment = new BoxComment(boxConnection, commentId);
        return comment.getInfo();
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxComment(com.box.sdk.BoxComment) BoxAPIException(com.box.sdk.BoxAPIException)

Example 50 with BoxAPIException

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

the class BoxCommentsManager method changeCommentMessage.

/**
     * Change comment message.
     * 
     * @param commentId
     *            - the id of comment to change.
     * @param message
     *            - the new message for the comment.
     * @return The comment with changed message.
     */
public BoxComment changeCommentMessage(String commentId, String message) {
    try {
        LOG.debug("Changing comment(id=" + commentId + ") message=" + message);
        if (commentId == null) {
            throw new IllegalArgumentException("Parameter 'commentId' can not be null");
        }
        if (message == null) {
            throw new IllegalArgumentException("Parameter 'message' can not be null");
        }
        BoxComment comment = new BoxComment(boxConnection, commentId);
        return comment.changeMessage(message).getResource();
    } catch (BoxAPIException e) {
        throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
    }
}
Also used : BoxComment(com.box.sdk.BoxComment) 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