use of io.georocket.client.GeoRocketClient in project georocket by georocket.
the class RemoveTagCommand method doRun.
@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
GeoRocketClient client = createClient();
client.getStore().removeTags(query, layer, tags, ar -> {
if (ar.failed()) {
client.close();
Throwable t = ar.cause();
error(t.getMessage());
if (!(t instanceof NoStackTraceThrowable)) {
log.error("Could not remove the tags", t);
}
handler.handle(1);
} else {
handler.handle(0);
}
});
}
use of io.georocket.client.GeoRocketClient in project georocket by georocket.
the class SetPropertyCommand method doRun.
@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
GeoRocketClient client = createClient();
client.getStore().setProperties(query, layer, properties, ar -> {
if (ar.failed()) {
client.close();
Throwable t = ar.cause();
error(t.getMessage());
if (!(t instanceof NoStackTraceThrowable)) {
log.error("Could not set properties", t);
}
handler.handle(1);
} else {
handler.handle(0);
}
});
}
use of io.georocket.client.GeoRocketClient in project georocket by georocket.
the class ImportCommand method doRun.
@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
long start = System.currentTimeMillis();
// resolve file patterns
Queue<String> queue = new ArrayDeque<>();
for (String p : patterns) {
// convert Windows backslashes to slashes (necessary for Files.newDirectoryStream())
if (SystemUtils.IS_OS_WINDOWS) {
p = FilenameUtils.separatorsToUnix(p);
}
// collect paths and glob patterns
List<String> roots = new ArrayList<>();
List<String> globs = new ArrayList<>();
String[] parts = p.split("/");
boolean rootParsed = false;
for (String part : parts) {
if (!rootParsed) {
if (hasGlobCharacter(part)) {
globs.add(part);
rootParsed = true;
} else {
roots.add(part);
}
} else {
globs.add(part);
}
}
if (globs.isEmpty()) {
// string does not contain a glob pattern at all
queue.add(p);
} else {
// string contains a glob pattern
if (roots.isEmpty()) {
// there are not paths in the string. start from the current
// working directory
roots.add(".");
}
// add all files matching the pattern
String root = String.join("/", roots);
String glob = String.join("/", globs);
Project project = new Project();
FileSet fs = new FileSet();
fs.setDir(new File(root));
fs.setIncludes(glob);
DirectoryScanner ds = fs.getDirectoryScanner(project);
Arrays.stream(ds.getIncludedFiles()).map(path -> Paths.get(root, path).toString()).forEach(queue::add);
}
}
if (queue.isEmpty()) {
error("given pattern didn't match any files");
return;
}
Vertx vertx = new Vertx(this.vertx);
GeoRocketClient client = createClient();
int queueSize = queue.size();
doImport(queue, client, vertx, exitCode -> {
client.close();
if (exitCode == 0) {
String m = "file";
if (queueSize > 1) {
m += "s";
}
System.out.println("Successfully imported " + queueSize + " " + m + " in " + DurationFormat.formatUntilNow(start));
}
handler.handle(exitCode);
});
}
use of io.georocket.client.GeoRocketClient in project georocket by georocket.
the class ImportCommand method importFile.
/**
* Upload a file to GeoRocket
* @param path path to file to import
* @param client the GeoRocket client
* @param vertx the Vert.x instance
* @return an observable that will emit when the file has been uploaded
*/
protected Observable<Void> importFile(String path, GeoRocketClient client, Vertx vertx) {
// open file
FileSystem fs = vertx.fileSystem();
OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false);
return fs.rxOpen(path, openOptions).flatMap(f -> fs.rxProps(path).map(props -> Pair.of(f, props.size()))).flatMapObservable(f -> {
ObservableFuture<Void> o = RxHelper.observableFuture();
Handler<AsyncResult<Void>> handler = o.toHandler();
AsyncFile file = f.getLeft().getDelegate();
WriteStream<Buffer> out = client.getStore().startImport(layer, tags, properties, Optional.of(f.getRight()), fallbackCRS, handler);
AtomicBoolean fileClosed = new AtomicBoolean();
Pump pump = Pump.pump(file, out);
file.endHandler(v -> {
file.close();
out.end();
fileClosed.set(true);
});
Handler<Throwable> exceptionHandler = t -> {
if (!fileClosed.get()) {
file.endHandler(null);
file.close();
}
handler.handle(Future.failedFuture(t));
};
file.exceptionHandler(exceptionHandler);
out.exceptionHandler(exceptionHandler);
pump.start();
return o;
});
}
Aggregations