Skip to content

Commit

Permalink
Merge pull request #94 from dterefe/new-document-handlers
Browse files Browse the repository at this point in the history
Added FolderPicker API to the Dropbox Connector.
  • Loading branch information
dterefe authored Aug 16, 2024
2 parents 4997f4c + a79f0e7 commit c91eade
Showing 1 changed file with 34 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.Collectors;


Expand Down Expand Up @@ -280,31 +281,47 @@ public List<DUUIDocument> listDocuments(String path, String fileExtension, boole

@Override
public DUUIFolder getFolderStructure() {
return getFolderStructure("/", "Files");
}

public DUUIFolder getFolderStructure(String path, String name) {
DUUIFolder root = new DUUIFolder("", "Files");

DUUIFolder root = new DUUIFolder(path, name);
listFolderContents(root);

ListFolderResult result = null;
return root;
}

/**
* Recursively traverses the dropbox directory and saves the directory
* tree in the root folder.
*
* @param root Root folder containing entire directory structure
*/
private void listFolderContents(DUUIFolder root) {
try {
result = client
.files()
.listFolderBuilder(path)
ListFolderResult result = client.files().listFolderBuilder(root.id)
.withRecursive(false)
.withIncludeMediaInfo(false)
.withIncludeDeleted(false)
.withIncludeHasExplicitSharedMembers(false)
.withIncludeMountedFolders(true)
.withLimit(2000L)
.start();

} catch (DbxException e) {
return null;
do {
result.getEntries().parallelStream()
.filter(entry -> entry instanceof FolderMetadata)
.map(entry -> (FolderMetadata) entry)
.map(entry -> new DUUIFolder(entry.getPathDisplay(), entry.getName()))
.peek(root::addChild)
.forEach(this::listFolderContents);

if (result.getHasMore()) {
result = client.files().listFolderContinue(result.getCursor());
} else break;

} while (true);
} catch (Exception e) {
new RuntimeException(e);
}

result.getEntries().stream()
.filter(f -> f instanceof FolderMetadata)
.map(f -> getFolderStructure(((FolderMetadata) f).getId(), f.getName()))
.filter(Objects::nonNull)
.forEach(root::addChild);

return root;
}
}

0 comments on commit c91eade

Please sign in to comment.