Search in sources :

Example 1 with GeoRocketClient

use of io.georocket.client.GeoRocketClient in project georocket by georocket.

the class AbstractQueryCommand method query.

/**
 * Query data store using a search query and a layer
 * @param query the search query (may be null)
 * @param layer the layer to export (may be null)
 * @param out the writer to write the results to
 * @param handler the handler that should be called when all
 * chunks have been exported
 * @throws IOException if the query or the layer was invalid
 */
protected void query(String query, String layer, PrintWriter out, Handler<Integer> handler) throws IOException {
    GeoRocketClient client = createClient();
    client.getStore().search(query, layer, ar -> {
        if (ar.failed()) {
            error(ar.cause().getMessage());
            if (!(ar.cause() instanceof NoSuchElementException) && !(ar.cause() instanceof NoStackTraceThrowable)) {
                log.error("Could not query store", ar.cause());
            }
            handler.handle(1);
        } else {
            ar.result().handler(buf -> {
                out.write(buf.toString("utf-8"));
            });
            ar.result().endHandler(v -> {
                client.close();
                handler.handle(0);
            });
        }
    });
}
Also used : GeoRocketClient(io.georocket.client.GeoRocketClient) NoSuchElementException(java.util.NoSuchElementException) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 2 with GeoRocketClient

use of io.georocket.client.GeoRocketClient in project georocket by georocket.

the class AddTagCommand method doRun.

@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
    GeoRocketClient client = createClient();
    client.getStore().appendTags(query, layer, tags, ar -> {
        if (ar.failed()) {
            client.close();
            Throwable t = ar.cause();
            error(t.getMessage());
            if (!(t instanceof NoStackTraceThrowable)) {
                log.error("Could not add the tags", t);
            }
            handler.handle(1);
        } else {
            handler.handle(0);
        }
    });
}
Also used : NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) GeoRocketClient(io.georocket.client.GeoRocketClient) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 3 with GeoRocketClient

use of io.georocket.client.GeoRocketClient in project georocket by georocket.

the class GetPropertyCommand method doRun.

@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
    GeoRocketClient client = createClient();
    client.getStore().getPropertyValues(property, query, layer, ar -> {
        if (ar.failed()) {
            Throwable t = ar.cause();
            error(t.getMessage());
            if (!(t instanceof NoStackTraceThrowable)) {
                log.error("Could not get values of property " + property, t);
            }
            handler.handle(1);
        } else {
            ar.result().handler(buf -> {
                out.write(buf.toString("utf-8"));
            });
            ar.result().endHandler(v -> {
                client.close();
                handler.handle(0);
            });
        }
    });
}
Also used : NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) GeoRocketClient(io.georocket.client.GeoRocketClient) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 4 with GeoRocketClient

use of io.georocket.client.GeoRocketClient in project georocket by georocket.

the class DeleteCommand method doRun.

@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
    GeoRocketClient client = createClient();
    client.getStore().delete(query, layer, ar -> {
        if (ar.failed()) {
            client.close();
            Throwable t = ar.cause();
            error(t.getMessage());
            if (!(t instanceof NoStackTraceThrowable)) {
                log.error("Could not delete from store", t);
            }
            handler.handle(1);
        } else {
            handler.handle(0);
        }
    });
}
Also used : NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) GeoRocketClient(io.georocket.client.GeoRocketClient) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Example 5 with GeoRocketClient

use of io.georocket.client.GeoRocketClient in project georocket by georocket.

the class RemovePropertyCommand method doRun.

@Override
public void doRun(String[] remainingArgs, InputReader in, PrintWriter out, Handler<Integer> handler) throws OptionParserException, IOException {
    GeoRocketClient client = createClient();
    client.getStore().removeProperties(query, layer, properties, ar -> {
        if (ar.failed()) {
            client.close();
            Throwable t = ar.cause();
            error(t.getMessage());
            if (!(t instanceof NoStackTraceThrowable)) {
                log.error("Could not remove properties", t);
            }
            handler.handle(1);
        } else {
            handler.handle(0);
        }
    });
}
Also used : NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable) GeoRocketClient(io.georocket.client.GeoRocketClient) NoStackTraceThrowable(io.vertx.core.impl.NoStackTraceThrowable)

Aggregations

GeoRocketClient (io.georocket.client.GeoRocketClient)9 NoStackTraceThrowable (io.vertx.core.impl.NoStackTraceThrowable)7 Splitter (com.google.common.base.Splitter)2 InputReader (de.undercouch.underline.InputReader)2 ArgumentType (de.undercouch.underline.Option.ArgumentType)2 OptionDesc (de.undercouch.underline.OptionDesc)2 OptionParserException (de.undercouch.underline.OptionParserException)2 UnknownAttributes (de.undercouch.underline.UnknownAttributes)2 DurationFormat (io.georocket.util.DurationFormat)2 AsyncResult (io.vertx.core.AsyncResult)2 Future (io.vertx.core.Future)2 Handler (io.vertx.core.Handler)2 Buffer (io.vertx.core.buffer.Buffer)2 AsyncFile (io.vertx.core.file.AsyncFile)2 OpenOptions (io.vertx.core.file.OpenOptions)2 Pump (io.vertx.core.streams.Pump)2 WriteStream (io.vertx.core.streams.WriteStream)2 ObservableFuture (io.vertx.rx.java.ObservableFuture)2 RxHelper (io.vertx.rx.java.RxHelper)2 Vertx (io.vertx.rxjava.core.Vertx)2