Skip to content

Commit

Permalink
Merge pull request #100 from dterefe/new-document-handlers
Browse files Browse the repository at this point in the history
New document handlers
  • Loading branch information
dterefe authored Aug 27, 2024
2 parents 8c836b8 + ca4b352 commit a6b6284
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import com.github.dockerjava.api.model.*;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.core.command.LogContainerResultCallback;
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
import com.github.dockerjava.transport.DockerHttpClient;
import com.google.common.collect.ImmutableList;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.InvalidParameterException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -162,22 +166,21 @@ public class DUUIDockerInterface {
*/
public DUUIDockerInterface() throws IOException {

// GREAT TODO!!!
//URI dockerClientURI;
//if (System.getProperty("os.name").toLowerCase().contains("windows")) {
// dockerClientURI = URI.create("npipe:////./pipe/docker_engine");
//} else {
// dockerClientURI = URI.create("tcp://localhost:2375");
//}

//_docker = DockerClientBuilder.getInstance()
// .withDockerHttpClient(new ApacheDockerHttpClient.Builder()
// .dockerHost(dockerClientURI).build()).build();
_docker = DockerClientBuilder.getInstance().build();

if (!System.getProperty("os.name").contains("Windows")) {
_docker = DockerClientBuilder.getInstance().build();
} else {
// Windows
final DockerHttpClient http = new ApacheDockerHttpClient.Builder()
.connectionTimeout(Duration.ofSeconds(5))
.responseTimeout(Duration.ofMinutes(10))
.dockerHost(URI.create("npipe:////./pipe/docker_engine"))
// .dockerHost(URI.create("tcp://127.0.0.1:2375")) // if npipe doesn't work.
.build();
_docker = DockerClientBuilder.getInstance()
.withDockerHttpClient(http)
.build();

// DockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder().withDockerHost("tcp://localhost:2375").build();
// _docker = DockerClientBuilder.getInstance(config).build();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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 @@ -281,47 +280,31 @@ public List<DUUIDocument> listDocuments(String path, String fileExtension, boole

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

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

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

return root;
}
ListFolderResult result = null;

/**
* 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 {
ListFolderResult result = client.files().listFolderBuilder(root.id)
.withRecursive(false)
.withIncludeMediaInfo(false)
.withIncludeDeleted(false)
.withIncludeHasExplicitSharedMembers(false)
.withIncludeMountedFolders(true)
.withLimit(2000L)
result = client
.files()
.listFolderBuilder(path)
.start();

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);
} catch (DbxException e) {
return null;
}

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 a6b6284

Please sign in to comment.