Search in sources :

Example 26 with BoxFolder

use of com.box.sdk.BoxFolder 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)

Aggregations

BoxFolder (com.box.sdk.BoxFolder)26 BoxAPIException (com.box.sdk.BoxAPIException)17 InputStream (java.io.InputStream)5 BoxFile (com.box.sdk.BoxFile)2 BoxItem (com.box.sdk.BoxItem)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 FileUploadParams (com.box.sdk.FileUploadParams)1