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