Search in sources :

Example 6 with BoxAPIException

use of com.box.sdk.BoxAPIException 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);
    }
}
Also used : FileUploadParams(com.box.sdk.FileUploadParams) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 7 with BoxAPIException

use of com.box.sdk.BoxAPIException 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);
    }
}
Also used : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException)

Example 8 with BoxAPIException

use of com.box.sdk.BoxAPIException 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);
    }
}
Also used : BoxFile(com.box.sdk.BoxFile) BoxAPIException(com.box.sdk.BoxAPIException)

Example 9 with BoxAPIException

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

the class BoxTasksManager method deleteTask.

/**
     * Delete task.
     * 
     * @param taskId
     *            - the id of task to delete.
     */
public void deleteTask(String taskId) {
    try {
        LOG.debug("Deleting task(id=" + taskId + ")");
        if (taskId == null) {
            throw new IllegalArgumentException("Parameter 'taskId' can not be null");
        }
        BoxTask task = new BoxTask(boxConnection, taskId);
        task.delete();
    } 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 : BoxTask(com.box.sdk.BoxTask) BoxAPIException(com.box.sdk.BoxAPIException)

Example 10 with BoxAPIException

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

the class BoxTasksManager method addAssignmentToTask.

/**
     * Add assignment for task.
     * 
     * @param taskId
     *            - the id of task to add assignment for.
     * @param assignTo
     *            - the user to assign to task.
     * @return The assigned task.
     */
// compiler for some reason thinks 'if (assignTo
@SuppressWarnings("unused")
public // == null)' clause is dead code.
BoxTask addAssignmentToTask(String taskId, BoxUser assignTo) {
    try {
        LOG.debug("Assigning task(id=" + taskId + ") to user(id=" + assignTo.getID() + ")");
        if (taskId == null) {
            throw new IllegalArgumentException("Parameter 'commentId' can not be null");
        }
        if (assignTo == null) {
            throw new IllegalArgumentException("Parameter 'assignTo' can not be null");
        }
        BoxTask task = new BoxTask(boxConnection, taskId);
        task.addAssignment(assignTo);
        return task;
    } 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 : BoxTask(com.box.sdk.BoxTask) 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