Search in sources :

Example 1 with BoxFileVersion

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

the class BoxFilesManager method promoteFileVersion.

/**
     * Promote a previous version of file.
     * 
     * @param fileId
     *            - the id of file.
     * @param version
     *            - the version of file to promote; initial version of file has
     *            value of <code>0</code>, second version of file is
     *            <code>1</code> and so on.
     * @return The promoted version of file.
     */
public BoxFileVersion promoteFileVersion(String fileId, Integer version) {
    try {
        LOG.debug("Promoting 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> fileVersions = (List<BoxFileVersion>) file.getVersions();
        BoxFileVersion fileVersion = fileVersions.get(version);
        fileVersion.promote();
        return fileVersion;
    } 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 2 with BoxFileVersion

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

the class BoxFilesManager method downloadPreviousFileVersion.

/**
     * Download a previous version of file.
     * 
     * @param fileId
     *            - the id of file.
     * @param version
     *            - the version of file to download; initial version of file has
     *            value of <code>0</code>, second version of file is
     *            <code>1</code> and so on.
     * @param output
     *            - the stream to which the version contents will be written.
     * @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
     *         version.
     */
public OutputStream downloadPreviousFileVersion(String fileId, Integer version, OutputStream output, ProgressListener listener) {
    try {
        LOG.debug("Downloading 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");
        }
        if (output == null) {
            throw new IllegalArgumentException("Parameter 'output' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        List<BoxFileVersion> fileVersions = (List<BoxFileVersion>) file.getVersions();
        BoxFileVersion fileVersion = fileVersions.get(version);
        if (listener != null) {
            fileVersion.download(output, listener);
        } else {
            fileVersion.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) List(java.util.List) BoxAPIException(com.box.sdk.BoxAPIException) BoxFileVersion(com.box.sdk.BoxFileVersion)

Example 3 with BoxFileVersion

use of com.box.sdk.BoxFileVersion 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)

Aggregations

BoxAPIException (com.box.sdk.BoxAPIException)3 BoxFile (com.box.sdk.BoxFile)3 BoxFileVersion (com.box.sdk.BoxFileVersion)3 List (java.util.List)3