Search in sources :

Example 11 with BoxFile

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

the class BoxTasksManager method getFileTasks.

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

use of com.box.sdk.BoxFile 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 13 with BoxFile

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

the class BoxFilesManager method getFilePreviewLink.

/**
     * Get an expiring URL for creating an embedded preview session. The URL
     * will expire after 60 seconds and the preview session will expire after 60
     * minutes.
     * 
     * @param fileId
     *            - the id of the file to get preview link on.
     * @return The preview link.
     */
public URL getFilePreviewLink(String fileId) {
    try {
        LOG.debug("Getting preview link for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        return file.getPreviewLink();
    } 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 14 with BoxFile

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

the class BoxFilesManager method getFileMetadata.

/**
     * Gets the file properties metadata.
     * 
     * @param fileId
     *            - the id of the file to retrieve metadata for.
     * @param typeName
     *            - the metadata template type name; if <code>null</code> the
     *            global properties template type is used.
     * @return The metadata returned from the server.
     */
public Metadata getFileMetadata(String fileId, String typeName) {
    try {
        LOG.debug("Get metadata for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        if (typeName != null) {
            return file.getMetadata(typeName);
        } else {
            return file.getMetadata();
        }
    } 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 15 with BoxFile

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

the class BoxFilesManager method downloadFile.

/**
     * Download a file.
     * 
     * @param fileId
     *            - the id of file.
     * @param output
     *            - the stream to which the file contents will be written.
     * @param rangeStart
     *            - the byte offset in file at which to start the download; if
     *            <code>null</code> the entire contents of file will be
     *            downloaded.
     * @param rangeEnd
     *            - the byte offset in file at which to stop the download; if
     *            <code>null</code> the entire contents of file will be
     *            downloaded.
     * @param listener
     *            - a listener for monitoring the download's progress; if
     *            <code>null</code> the download's progress will not be
     *            monitored.
     * @return The stream containing the contents of the downloaded file.
     */
public OutputStream downloadFile(String fileId, OutputStream output, Long rangeStart, Long rangeEnd, ProgressListener listener) {
    try {
        LOG.debug("Downloading file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (output == null) {
            throw new IllegalArgumentException("Parameter 'output' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        if (listener != null) {
            if (rangeStart != null && rangeEnd != null) {
                file.downloadRange(output, rangeStart, rangeEnd, listener);
            } else {
                file.download(output, listener);
            }
        } else {
            if (rangeStart != null && rangeEnd != null) {
                file.downloadRange(output, rangeStart, rangeEnd);
            } else {
                file.download(output);
            }
        }
        return output;
    } 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)24 BoxFile (com.box.sdk.BoxFile)24 BoxFileVersion (com.box.sdk.BoxFileVersion)3 List (java.util.List)3 BoxFolder (com.box.sdk.BoxFolder)2 BoxTask (com.box.sdk.BoxTask)1