Search in sources :

Example 21 with BoxFile

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

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

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

Example 24 with BoxFile

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

the class BoxFilesManager method moveFile.

/**
     * Move file to destination folder while optionally giving it a new name.
     * 
     * @param fileId
     *            - the id of file to move.
     * @param destinationFolderId
     *            - the id of the destination folder.
     * @param newName
     *            - the new name of moved file; if <code>newName</code> is
     *            <code>null</code>, the moved file has same name as the
     *            original.
     * @return The moved file.
     */
public BoxFile moveFile(String fileId, String destinationFolderId, String newName) {
    try {
        LOG.debug("Moving file(id=" + fileId + ") to destination_folder(id=" + destinationFolderId + ")" + (newName == null ? "" : " with new name '" + newName + "'"));
        if (fileId == null) {
            throw new IllegalArgumentException("Parameter 'fileId' can not be null");
        }
        if (destinationFolderId == null) {
            throw new IllegalArgumentException("Parameter 'destinationFolderId' can not be null");
        }
        BoxFile fileToMove = new BoxFile(boxConnection, fileId);
        BoxFolder destinationFolder = new BoxFolder(boxConnection, destinationFolderId);
        if (newName == null) {
            return (BoxFile) fileToMove.move(destinationFolder).getResource();
        } else {
            return (BoxFile) fileToMove.move(destinationFolder, newName).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) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

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