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();
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations