Search in sources :

Example 6 with BoxFile

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

the class BoxFilesManager method updateFileInfo.

/**
     * Update file information.
     * 
     * @param fileId
     *            - the id of file to update.
     * @param info
     *            - the updated information
     * @return The updated file.
     */
public BoxFile updateFileInfo(String fileId, BoxFile.Info info) {
    try {
        LOG.debug("Updating info for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (info == null) {
            throw new IllegalArgumentException("Parameter 'info' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        file.updateInfo(info);
        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 7 with BoxFile

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

the class BoxFilesManager method getFileInfo.

/**
     * Get file information.
     * 
     * @param fileId
     *            - the id of file.
     * @param fields
     *            - the information fields to retrieve; if <code>null</code> all
     *            information fields are retrieved.
     * @return The file information.
     */
public BoxFile.Info getFileInfo(String fileId, String... fields) {
    try {
        LOG.debug("Getting info for file(id=" + fileId + ")");
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        if (fields == null || fields.length == 0) {
            return file.getInfo();
        } else {
            return file.getInfo(fields);
        }
    } 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 8 with BoxFile

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

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

the class BoxFilesManager method deleteFile.

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

Example 10 with BoxFile

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

the class BoxFilesManager method getFileThumbnail.

/**
     * 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.
     * @param fileType
     *            - either PNG of JPG.
     * @param minWidth
     *            - minimum width.
     * @param minHeight
     *            - minimum height.
     * @param maxWidth
     *            - maximum width.
     * @param maxHeight
     *            - maximum height.
     * @return The byte array of the thumbnail image.
     */
public byte[] getFileThumbnail(String fileId, BoxFile.ThumbnailFileType fileType, Integer minWidth, Integer minHeight, Integer maxWidth, Integer maxHeight) {
    try {
        LOG.debug("Getting thumbnail for file(id=" + fileId + ") fileType=" + fileType + " minWidth=" + minWidth + " minHeight=" + minHeight + " maxWidth=" + maxWidth + " maxHeight=" + maxHeight);
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (fileType == null) {
            throw new IllegalArgumentException("Parameter 'fileType' can not be null");
        }
        if (minWidth == null) {
            throw new IllegalArgumentException("Parameter 'minWidth' can not be null");
        }
        if (minHeight == null) {
            throw new IllegalArgumentException("Parameter 'minHeight' can not be null");
        }
        if (maxWidth == null) {
            throw new IllegalArgumentException("Parameter 'maxWidth' can not be null");
        }
        if (maxHeight == null) {
            throw new IllegalArgumentException("Parameter 'maxHeight' can not be null");
        }
        BoxFile file = new BoxFile(boxConnection, fileId);
        return file.getThumbnail(fileType, minWidth, minHeight, maxWidth, maxHeight);
    } 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