use of com.box.sdk.BoxFile in project camel by apache.
the class BoxCommentsManager method addFileComment.
/**
* Add comment to file.
*
* @param fileId
* - the id of file to rename.
* @param message
* - the comment's message.
* @return The commented file.
*/
public BoxFile addFileComment(String fileId, String message) {
try {
LOG.debug("Adding comment to file(id=" + fileId + ") to '" + message + "'");
if (fileId == null) {
throw new IllegalArgumentException("Parameter 'fileId' can not be null");
}
if (message == null) {
throw new IllegalArgumentException("Parameter 'message' can not be null");
}
BoxFile fileToCommentOn = new BoxFile(boxConnection, fileId);
fileToCommentOn.addComment(message);
return fileToCommentOn;
} 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.BoxFile in project camel by apache.
the class BoxFilesManager method uploadNewFileVersion.
/**
* Upload a new version of file.
*
* @param fileId
* - the id of file.
* @param fileContent
* - a stream containing contents of the file to upload.
* @param modified
* - the content modified date that will be given to the uploaded
* file.
* @param fileSize
* - 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 uploadNewFileVersion(String fileId, InputStream fileContent, Date modified, Long fileSize, ProgressListener listener) {
try {
LOG.debug("Uploading new version of file(id=" + fileId + ")");
if (fileId == null) {
throw new IllegalArgumentException("Parameter 'fileId' can not be null");
}
if (fileContent == null) {
throw new IllegalArgumentException("Paramerer 'fileContent' can not be null");
}
BoxFile file = new BoxFile(boxConnection, fileId);
if (modified != null) {
if (fileSize != null && listener != null) {
file.uploadVersion(fileContent, modified, fileSize, listener);
} else {
file.uploadVersion(fileContent, modified);
}
} else {
file.uploadVersion(fileContent);
}
return file;
} 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.BoxFile in project camel by apache.
the class BoxFilesManager method deleteFileMetadata.
/**
* Delete the file properties metadata.
*
* @param fileId
* - the id of file to delete.
*/
public void deleteFileMetadata(String fileId) {
try {
LOG.debug("Deleting metadata for file(id=" + fileId + ")");
if (fileId == null) {
throw new IllegalArgumentException("Parameter 'fileId' can not be null");
}
BoxFile file = new BoxFile(boxConnection, fileId);
file.deleteMetadata();
} 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.BoxFile in project camel by apache.
the class BoxFilesManager method renameFile.
/**
* Rename file giving it the name <code>newName</code>
*
* @param fileId
* - the id of file to rename.
* @param newFileName
* - the new name of file.
* @return The renamed file.
*/
public BoxFile renameFile(String fileId, String newFileName) {
try {
LOG.debug("Renaming file(id=" + fileId + ") to '" + newFileName + "'");
if (fileId == null) {
throw new IllegalArgumentException("Parameter 'fileId' can not be null");
}
if (newFileName == null) {
throw new IllegalArgumentException("Parameter 'newName' can not be null");
}
BoxFile fileToRename = new BoxFile(boxConnection, fileId);
fileToRename.rename(newFileName);
return fileToRename;
} 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.BoxFile in project camel by apache.
the class BoxFilesManager method createFileSharedLink.
/**
* Create a shared link to file.
*
* @param fileId
* - the id of the file 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 createFileSharedLink(String fileId, BoxSharedLink.Access access, Date unshareDate, BoxSharedLink.Permissions permissions) {
try {
LOG.debug("Creating shared link for file(id=" + fileId + ") with access=" + access + (unshareDate == null ? "" : " unsharedDate=" + SimpleDateFormat.getDateTimeInstance().format(unshareDate) + " permissions=" + permissions));
if (fileId == null) {
throw new IllegalArgumentException("Parameter 'fileId' can not be null");
}
if (access == null) {
throw new IllegalArgumentException("Parameter 'access' can not be null");
}
BoxFile file = new BoxFile(boxConnection, fileId);
return file.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);
}
}
Aggregations