Search in sources :

Example 16 with BoxFolder

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

the class BoxFoldersManager method updateFolderInfo.

/**
     * Update folder information.
     * 
     * @param folderId
     *            - the id of folder to update.
     * @param info
     *            - the updated information
     * @return The updated folder.
     */
public BoxFolder updateFolderInfo(String folderId, BoxFolder.Info info) {
    try {
        LOG.debug("Updating info for folder(id=" + folderId + ")");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (info == null) {
            throw new IllegalArgumentException("Parameter 'info' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        folder.updateInfo(info);
        return folder;
    } 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 : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 17 with BoxFolder

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

Example 18 with BoxFolder

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

the class BoxFoldersManager method renameFolder.

/**
     * Rename folder giving it the name <code>newName</code>
     * 
     * @param folderId
     *            - the id of folder to rename.
     * @param newFolderName
     *            - the new name of folder.
     * @return The renamed folder.
     */
public BoxFolder renameFolder(String folderId, String newFolderName) {
    try {
        LOG.debug("Renaming folder(id=" + folderId + ") to '" + newFolderName + "'");
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (newFolderName == null) {
            throw new IllegalArgumentException("Parameter 'newFolderName' can not be null");
        }
        BoxFolder folderToRename = new BoxFolder(boxConnection, folderId);
        folderToRename.rename(newFolderName);
        return folderToRename;
    } 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 : BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder)

Example 19 with BoxFolder

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

the class BoxFoldersManager method getFolderItems.

/**
     * Returns a specific range of child items in folder and specifies which
     * fields of each item to retrieve.
     * 
     * @param folderId
     *            - the id of folder.
     * @param offset
     *            - the index of first child item to retrieve; if
     *            <code>null</code> all child items are retrieved.
     * @param limit
     *            - the maximum number of children to retrieve after the offset;
     *            if <code>null</code> all child items are retrieved.
     * @param fields
     *            - the item fields to retrieve for each child item; if
     *            <code>null</code> all item fields are retrieved.
     * @return The Items in folder
     */
public Collection<BoxItem.Info> getFolderItems(String folderId, Long offset, Long limit, String... fields) {
    try {
        LOG.debug("Getting folder items in folder(id=" + folderId + ") at offset=" + offset + " and limit=" + limit + " with fields=" + Arrays.toString(fields));
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        if (fields == null) {
            fields = new String[0];
        }
        if (offset != null && limit != null) {
            return folder.getChildrenRange(offset, limit, fields);
        } else {
            Collection<BoxItem.Info> folderItems = new ArrayList<BoxItem.Info>();
            Iterable<BoxItem.Info> iterable;
            if (fields.length > 0) {
                iterable = folder.getChildren(fields);
            } else {
                iterable = folder.getChildren();
            }
            for (BoxItem.Info itemInfo : iterable) {
                folderItems.add(itemInfo);
            }
            return folderItems;
        }
    } 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 : ArrayList(java.util.ArrayList) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder) BoxItem(com.box.sdk.BoxItem)

Example 20 with BoxFolder

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

the class BoxSearchManager method searchFolder.

/**
     * Search folder and all descendant folders using the given query.
     * 
     * @param folderId
     *            - the id of folder searched.
     * @param query
     *            - the search query.
     * 
     * @return A collection of matching items.
     */
public Collection<BoxItem> searchFolder(String folderId, String query) {
    try {
        LOG.debug("Searching folder(id=" + folderId + ") with query=" + query);
        if (folderId == null) {
            throw new IllegalArgumentException("Parameter 'folderId' can not be null");
        }
        if (query == null) {
            throw new IllegalArgumentException("Parameter 'query' can not be null");
        }
        BoxFolder folder = new BoxFolder(boxConnection, folderId);
        Collection<BoxItem> results = new ArrayList<BoxItem>();
        for (BoxItem.Info info : folder.search(query)) {
            results.add((BoxItem) info.getResource());
        }
        return results;
    } 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 : ArrayList(java.util.ArrayList) BoxAPIException(com.box.sdk.BoxAPIException) BoxFolder(com.box.sdk.BoxFolder) BoxItem(com.box.sdk.BoxItem)

Aggregations

BoxFolder (com.box.sdk.BoxFolder)26 BoxAPIException (com.box.sdk.BoxAPIException)17 InputStream (java.io.InputStream)5 BoxFile (com.box.sdk.BoxFile)2 BoxItem (com.box.sdk.BoxItem)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 FileUploadParams (com.box.sdk.FileUploadParams)1