Search in sources :

Example 71 with BoxAPIException

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

the class BoxSearchManager method searchFolder.

/**
     * Search folder and all descendant folders using the given query.
     * 
     * @param folderId
     *            - the id of folder searched.
     * @param query
     *            - the search query.
     * 
     * @return A collection of matching items.
     */
public Collection<BoxItem> searchFolder(String folderId, String query) {
    try {
        LOG.debug("Searching folder(id=" + folderId + ") with query=" + query);
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (query == null) {
            throw new IllegalArgumentException("Parameter 'query' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        Collection<BoxItem> results = new ArrayList<BoxItem>();
        for (BoxItem.Info info : folder.search(query)) {
            results.add((BoxItem) info.getResource());
        }
        return results;
    } 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 : ArrayList(java.util.ArrayList) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder) BoxItem(com.box.sdk.BoxItem)

Example 72 with BoxAPIException

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

the class BoxTasksManager method deleteTaskAssignment.

// TODO Add this method when BoxTaskAssignment API fixed:
// BoxTaskAssignment.update method currently
// takes BoxTask.Info instead of BoxTaskAssignment.Info
// /**
// * Update task assignment information.
// *
// * @param taskAssignmentId
// * - the id of task assignment.
// * @param info
// * - the updated information
// * @return The updated task assignment.
// */
// public BoxTaskAssignment updateTaskAssignmentInfo(String
// taskAssignmentId, BoxTaskAssignment.Info info) {
// try {
// LOG.debug("Updating info for task(id=" + taskAssignmentId + ")");
// if (taskAssignmentId == null) {
// throw new IllegalArgumentException("Parameter 'taskAssignmentId' can not
// be null");
// }
// if (info == null) {
// throw new IllegalArgumentException("Parameter 'info' can not be null");
// }
//
// BoxTaskAssignment taskAssignment = new BoxTaskAssignment(boxConnection,
// taskAssignmentId);
// taskAssignment.updateInfo(info);
//
// return taskAssignment;
// } catch (BoxAPIException e) {
// throw new RuntimeException(
// String.format("Box API returned the error code %d\n\n%s",
// e.getResponseCode(), e.getResponse()), e);
// }
// }
/**
     * Delete task assignment.
     * 
     * @param taskAssignmentId
     *            - the id of task assignment to delete.
     */
public void deleteTaskAssignment(String taskAssignmentId) {
    try {
        LOG.debug("Deleting task(id=" + taskAssignmentId + ")");
        if (taskAssignmentId == null) {
            throw new IllegalArgumentException("Parameter 'taskAssignmentId' can not be null");
        }
        BoxTaskAssignment taskAssignment = new BoxTaskAssignment(boxConnection, taskAssignmentId);
        taskAssignment.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 : BoxTaskAssignment(com.box.sdk.BoxTaskAssignment) BoxAPIException(com.box.sdk.BoxAPIException)

Example 73 with BoxAPIException

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

the class BoxTasksManager method addFileTask.

/**
     * Add task to file.
     * 
     * @param fileId
     *            - the id of file to add task to.
     * @param action
     *            - the action the task assignee will be prompted to do.
     * @param dueAt
     *            - - the day at which this task is due.
     * @param message
     *            - an optional message to include with the task.
     * @return The new task.
     */
public BoxTask addFileTask(String fileId, BoxTask.Action action, Date dueAt, String message) {
    try {
        LOG.debug("Adding task to file(id=" + fileId + ") to '" + message + "'");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (action == null) {
            throw new IllegalArgumentException("Parameter 'action' can not be null");
        }
        if (dueAt == null) {
            throw new IllegalArgumentException("Parameter 'dueAt' can not be null");
        }
        BoxFile fileToAddTaskOn = new BoxFile(boxConnection, fileId);
        return (BoxTask) fileToAddTaskOn.addTask(action, message, dueAt).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) BoxTask(com.box.sdk.BoxTask) BoxAPIException(com.box.sdk.BoxAPIException)

Example 74 with BoxAPIException

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

the class BoxFilesManagerIntegrationTest method testDeleteFileMetadata.

@Test
public void testDeleteFileMetadata() throws Exception {
    testFile.createMetadata(new Metadata());
    // using String message body for single parameter "fileId"
    requestBody("direct://DELETEFILEMETADATA", testFile.getID());
    try {
        testFile.getMetadata();
    } catch (BoxAPIException e) {
        if (e.getResponseCode() == 404) {
            // Box API should return a
            return;
        }
    }
    fail("deleteFileMetadata metadata");
}
Also used : Metadata(com.box.sdk.Metadata) BoxAPIException(com.box.sdk.BoxAPIException) Test(org.junit.Test)

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