use of com.box.sdk.BoxFolder in project camel by apache.
the class BoxFilesManager method uploadFile.
/**
* Upload a new file to parent folder.
*
* @param parentFolderId
* - the id of parent folder.
* @param content
* - a stream containing contents of the file to upload.
* @param fileName
* the name to give the uploaded file.
* @param created
* - the content created date that will be given to the uploaded
* file.
* @param modified
* - the content modified date that will be given to the uploaded
* file.
* @param size
* - the size of the file's content used for monitoring the
* upload's progress.
* @param listener
* - a listener for monitoring the upload's progress.
* @return The uploaded file.
*/
public BoxFile uploadFile(String parentFolderId, InputStream content, String fileName, Date created, Date modified, Long size, ProgressListener listener) {
try {
LOG.debug("Uploading file with name '" + fileName + "' to parent_folder(id=" + parentFolderId + ")");
if (parentFolderId == null) {
throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null");
}
if (content == null) {
throw new IllegalArgumentException("Paramerer 'content' can not be null");
}
if (fileName == null) {
throw new IllegalArgumentException("Paramerer 'fileName' can not be null");
}
BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId);
FileUploadParams uploadParams = new FileUploadParams();
uploadParams.setName(fileName);
uploadParams.setContent(content);
if (created != null) {
uploadParams.setCreated(created);
}
if (modified != null) {
uploadParams.setModified(modified);
}
if (size != null) {
uploadParams.setSize(size);
}
if (listener != null) {
uploadParams.setProgressListener(listener);
}
return parentFolder.uploadFile(uploadParams).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.BoxFolder in project camel by apache.
the class BoxFoldersManager method createFolderSharedLink.
/**
* Create a shared link to folder.
*
* @param folderId
* - the id of folder to create shared link on.
* @param access
* - the access level of the shared link.
* @param unshareDate
* - the date and time at which time the created shared link will
* expire; if <code>unsharedDate</code> is <code>null</code> then
* a non-expiring link is created.
* @param permissions
* - the permissions of the created link; if
* <code>permissions</code> is <code>null</code> then the created
* shared link is create with default permissions.
* @return The created shared link.
*/
public BoxSharedLink createFolderSharedLink(String folderId, BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions) {
try {
LOG.debug("Creating shared link for folder(id=" + folderId + ") with access=" + access + (unshareDate == null ? "" : " unsharedDate=" + SimpleDateFormat.getDateTimeInstance().format(unshareDate) + " permissions=" + permissions));
if (folderId == null) {
throw new IllegalArgumentException("Parameter 'folderId' can not be null");
}
if (access == null) {
throw new IllegalArgumentException("Parameter 'access' can not be null");
}
BoxFolder folder = new BoxFolder(boxConnection, folderId);
return folder.createSharedLink(access, unshareDate, permissions);
} 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.BoxFolder in project camel by apache.
the class BoxFoldersManager method createFolder.
/**
* Create a folder in parent folder with given <code>folderName</code>.
*
* @param parentFolderId
* - the id of parent folder.
* @param folderName
* the name of created folder.
* @return The created folder.
*/
public BoxFolder createFolder(String parentFolderId, String folderName) {
try {
LOG.debug("Creating folder with name '" + folderName + "' in parent_folder(id=" + parentFolderId + ")");
if (parentFolderId == null) {
throw new IllegalArgumentException("Parameter 'parentFolderId' can not be null");
}
if (folderName == null) {
throw new IllegalArgumentException("Paramerer 'folderName' can not be null");
}
BoxFolder parentFolder = new BoxFolder(boxConnection, parentFolderId);
return parentFolder.createFolder(folderName).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.BoxFolder in project camel by apache.
the class BoxFoldersManager method moveFolder.
/**
* Move folder to destination folder while optionally giving it a new name.
*
* @param folderId
* - the id of folder to move.
* @param destinationFolderId
* - the id of the destination folder.
* @param newName
* - the new name of moved folder; if <code>newName</code> is
* <code>null</code>, the moved folder has same name as the
* original.
* @return The moved folder.
*/
public BoxFolder moveFolder(String folderId, String destinationFolderId, String newName) {
try {
LOG.debug("Moving 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 folderToMove = new BoxFolder(boxConnection, folderId);
BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId);
if (newName == null) {
return (BoxFolder) folderToMove.move(destinationFolder).getResource();
} else {
return (BoxFolder) folderToMove.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);
}
}
use of com.box.sdk.BoxFolder in project camel by apache.
the class BoxFoldersManager method deleteFolder.
/**
* Delete folder.
*
* @param folderId
* - the id of folder to delete.
*/
public void deleteFolder(String folderId) {
try {
LOG.debug("Deleting folder(id=" + folderId + ")");
if (folderId == null) {
throw new IllegalArgumentException("Parameter 'folderId' can not be null");
}
BoxFolder folder = new BoxFolder(boxConnection, folderId);
folder.delete(true);
} catch (BoxAPIException e) {
throw new RuntimeException(String.format("Box API returned the error code %d\n\n%s", e.getResponseCode(), e.getResponse()), e);
}
}
Aggregations