Search in sources :

Example 11 with BoxFolder

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

the class BoxFilesManagerIntegrationTest method createTestFile.

private void createTestFile() throws FileNotFoundException {
    BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
    InputStream stream = getClass().getResourceAsStream(CAMEL_TEST_FILE);
    testFile = rootFolder.uploadFile(stream, CAMEL_TEST_FILE_NAME).getResource();
}
Also used : InputStream(java.io.InputStream) BoxFolder(com.box.sdk.BoxFolder)

Example 12 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 13 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 14 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)

Example 15 with BoxFolder

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

the class BoxFoldersManagerIntegrationTest method createTestFolder.

private void createTestFolder() {
    BoxFolder rootFolder = BoxFolder.getRootFolder(getConnection());
    testFolder = rootFolder.createFolder(CAMEL_TEST_FOLDER).getResource();
}
Also used : BoxFolder(com.box.sdk.BoxFolder)

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