Search in sources :

Example 1 with BoxAPIException

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

the class BoxCommentsManager method replyToComment.

/**
     * Reply to a comment.
     * 
     * @param commentId
     *            - the id of comment to reply to.
     * @param message
     *            - the message for the reply.
     * @return The newly created reply comment.
     */
public BoxComment replyToComment(String commentId, String message) {
    try {
        LOG.debug("Replying to comment(id=" + commentId + ") with message=" + message);
        if (commentId == null) {
            throw new IllegalArgumentException("Parameter 'commentId' can not be null");
        }
        if (message == null) {
            throw new IllegalArgumentException("Parameter 'message' can not be null");
        }
        BoxComment comment = new BoxComment(boxConnection, commentId);
        return comment.reply(message).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 : BoxComment(com.box.sdk.BoxComment) BoxAPIException(com.box.sdk.BoxAPIException)

Example 2 with BoxAPIException

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

Example 3 with BoxAPIException

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

the class BoxEventLogsManager method getEnterpriseEvents.

/**
     * Create an event stream with optional starting initial position and add
     * listener that will be notified when an event is received.
     * 
     * @param position
     *            - the starting position of the event stream. May be
     *            <code>null</code> in which case all events within bounds
     *            returned.
     * @param after
     *            - the lower bound on the timestamp of the events returned.
     * @param after
     *            - the upper bound on the timestamp of the events returned.
     * @param types
     *            - an optional list of event types to filter by.
     * 
     * @return A list of all the events that met the given criteria.
     */
public List<BoxEvent> getEnterpriseEvents(String position, Date after, Date before, BoxEvent.Type... types) {
    try {
        LOG.debug("Getting all enterprise events occuring between " + (after == null ? after : SimpleDateFormat.getDateTimeInstance().format(after)) + " and " + (before == null ? before : SimpleDateFormat.getDateTimeInstance().format(before)) + (position == null ? position : (" starting at " + position)));
        if (after == null) {
            throw new IllegalArgumentException("Parameter 'after' can not be null");
        }
        if (before == null) {
            throw new IllegalArgumentException("Parameter 'before' can not be null");
        }
        if (types == null) {
            types = new BoxEvent.Type[0];
        }
        EventLog eventLog = EventLog.getEnterpriseEvents(boxConnection, position, after, before, types);
        List<BoxEvent> results = new ArrayList<BoxEvent>();
        for (BoxEvent event : eventLog) {
            results.add(event);
        }
        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 : BoxEvent(com.box.sdk.BoxEvent) EventLog(com.box.sdk.EventLog) ArrayList(java.util.ArrayList) BoxAPIException(com.box.sdk.BoxAPIException)

Example 4 with BoxAPIException

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

Example 5 with BoxAPIException

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