Search in sources :

Example 51 with BoxAPIException

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

the class BoxCommentsManager method deleteComment.

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

Example 52 with BoxAPIException

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

the class BoxCommentsManager method getFileComments.

/**
     * Get a list of any comments on this file.
     * 
     * @param fileId
     *            - the id of file.
     * @return The list of comments on this file.
     */
public List<BoxComment.Info> getFileComments(String fileId) {
    try {
        LOG.debug("Getting comments of file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        return file.getComments();
    } 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 53 with BoxAPIException

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

the class BoxEventsManager method listen.

/**
     * Create an event stream with optional starting initial position and add
     * listener that will be notified when an event is received.
     * 
     * @param startingPosition
     *            - the starting position of the event stream.
     * @param listener
     *            - the listener to add to event stream.
     * 
     * @return The event stream.
     */
public void listen(EventListener listener, Long startingPosition) {
    try {
        LOG.debug("Listening for events with listener=" + listener + " at startingPosition=" + startingPosition);
        if (listener == null) {
            LOG.debug("Parameter 'listener' is null: will not listen for events");
            return;
        }
        if (startingPosition != null) {
            eventStream = new EventStream(boxConnection, startingPosition);
        } else {
            eventStream = new EventStream(boxConnection);
        }
        eventStream.addListener(listener);
        eventStream.start();
    } 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 : EventStream(com.box.sdk.EventStream) BoxAPIException(com.box.sdk.BoxAPIException)

Example 54 with BoxAPIException

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

the class BoxFilesManager method deleteFileVersion.

/**
     * Delete a file version.
     * 
     * @param fileId
     *            - the id of file with version to delete.
     * @param version
     *            - the version of file to delete; initial version of file has
     *            value of <code>0</code>, second version of file is
     *            <code>1</code> and so on.
     */
public void deleteFileVersion(String fileId, Integer version) {
    try {
        LOG.debug("Deleting file(id=" + fileId + ", version=" + version + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (version == null) {
            throw new IllegalArgumentException("Parameter 'version' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        List<BoxFileVersion> versions = (List<BoxFileVersion>) file.getVersions();
        BoxFileVersion fileVersion = versions.get(version);
        fileVersion.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 : BoxFile(com.box.sdk.BoxFile) List(java.util.List) BoxAPIException(com.box.sdk.BoxAPIException) BoxFileVersion(com.box.sdk.BoxFileVersion)

Example 55 with BoxAPIException

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

the class BoxFilesManager method updateFileMetadata.

/**
     * Update the file properties metadata.
     * 
     * @param fileId
     *            - the id of file to delete.
     * @param metadata
     *            - the new metadata values.
     * @return The metadata returned from the server.
     */
public Metadata updateFileMetadata(String fileId, Metadata metadata) {
    try {
        LOG.debug("Updating metadata for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (metadata == null) {
            throw new IllegalArgumentException("Parameter 'metadata' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        return file.updateMetadata(metadata);
    } 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