Search in sources :

Example 16 with BoxAPIException

use of com.box.sdk.BoxAPIException 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 17 with BoxAPIException

use of com.box.sdk.BoxAPIException 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 18 with BoxAPIException

use of com.box.sdk.BoxAPIException 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 19 with BoxAPIException

use of com.box.sdk.BoxAPIException 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 20 with BoxAPIException

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