Example usage for io.vertx.core.json JsonArray JsonArray

List of usage examples for io.vertx.core.json JsonArray JsonArray

Introduction

In this page you can find the example usage for io.vertx.core.json JsonArray JsonArray.

Prototype

public JsonArray() 

Source Link

Document

Create an empty instance

Usage

From source file:io.openshift.booster.service.impl.JdbcProductStore.java

License:Apache License

@Override
public Single<JsonObject> create(JsonObject item) {
    if (item == null) {
        return Single.error(new IllegalArgumentException("The item must not be null"));
    }//from  w w w. j av  a  2s. co  m
    if (item.getString("name") == null || item.getString("name").isEmpty()) {
        return Single.error(new IllegalArgumentException("The name must not be null or empty"));
    }
    if (item.getInteger("stock", 0) < 0) {
        return Single.error(new IllegalArgumentException("The stock must greater or equal to 0"));
    }
    if (item.containsKey("id")) {
        return Single.error(new IllegalArgumentException("The created item already contains an 'id'"));
    }

    return db.rxGetConnection().flatMap(conn -> {
        JsonArray params = new JsonArray().add(item.getValue("name")).add(item.getValue("stock", 0));
        return conn.rxUpdateWithParams(INSERT, params).map(ur -> item.put("id", ur.getKeys().getLong(0)))
                .doAfterTerminate(conn::close);
    });
}

From source file:io.openshift.booster.service.impl.JdbcProductStore.java

License:Apache License

@Override
public Single<JsonObject> read(long id) {
    return db.rxGetConnection().flatMap(conn -> {
        JsonArray param = new JsonArray().add(id);
        return conn.rxQueryWithParams(SELECT_ONE, param).map(ResultSet::getRows).flatMap(list -> {
            if (list.isEmpty()) {
                return Single.error(new NoSuchElementException("Item '" + id + "' not found"));
            } else {
                return Single.just(list.get(0));
            }/* ww  w  . j a va2  s . c o  m*/
        }).doAfterTerminate(conn::close);
    });
}

From source file:io.openshift.booster.service.impl.JdbcProductStore.java

License:Apache License

@Override
public Completable update(long id, JsonObject item) {
    if (item == null) {
        return Completable.error(new IllegalArgumentException("The item must not be null"));
    }/*from w  w w .ja  v  a2  s . co m*/
    if (item.getString("name") == null || item.getString("name").isEmpty()) {
        return Completable.error(new IllegalArgumentException("The name must not be null or empty"));
    }
    if (item.getInteger("stock", 0) < 0) {
        return Completable.error(new IllegalArgumentException("The stock must greater or equal to 0"));
    }
    if (item.containsKey("id") && id != item.getInteger("id")) {
        return Completable.error(new IllegalArgumentException("The 'id' cannot be changed"));
    }

    return db.rxGetConnection().flatMapCompletable(conn -> {
        JsonArray params = new JsonArray().add(item.getValue("name")).add(item.getValue("stock", 0)).add(id);
        return conn.rxUpdateWithParams(UPDATE, params).flatMapCompletable(up -> {
            if (up.getUpdated() == 0) {
                return Completable.error(new NoSuchElementException("Unknown item '" + id + "'"));
            }
            return Completable.complete();
        }).doAfterTerminate(conn::close);
    });
}

From source file:io.openshift.booster.service.impl.JdbcProductStore.java

License:Apache License

@Override
public Completable delete(long id) {
    return db.rxGetConnection().flatMapCompletable(conn -> {
        JsonArray params = new JsonArray().add(id);
        return conn.rxUpdateWithParams(DELETE, params).flatMapCompletable(up -> {
            if (up.getUpdated() == 0) {
                return Completable.error(new NoSuchElementException("Unknown item '" + id + "'"));
            }//from  www  . jav  a 2s .  com
            return Completable.complete();
        }).doAfterTerminate(conn::close);
    });
}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

License:Apache License

@SuppressWarnings("checkstyle:JavadocMethod")
public void listBeans(final RoutingContext routingContext) {
    JsonArray beans = new JsonArray();

    gatewayRegistry.keySet().forEach(beans::add);

    routingContext.response().end(beans.encodePrettily());
}

From source file:io.silverware.microservices.providers.cdi.internal.RestInterface.java

License:Apache License

@SuppressWarnings("checkstyle:JavadocMethod")
public void listMethods(final RoutingContext routingContext) {
    String microserviceName = routingContext.request().getParam("microservice");
    Bean bean = gatewayRegistry.get(microserviceName);

    if (bean == null) {
        routingContext.response().setStatusCode(503).end("Resource not available");
    } else {//from   www  .j a va 2  s  . c  o  m
        JsonArray methods = new JsonArray();

        for (final Method m : bean.getBeanClass().getDeclaredMethods()) {
            if (Modifier.isPublic(m.getModifiers())) {
                JsonObject method = new JsonObject();
                method.put("methodName", m.getName());
                JsonArray params = new JsonArray();
                for (Class c : m.getParameterTypes()) {
                    params.add(c.getName());
                }
                method.put("parameters", params);
                method.put("returns", m.getReturnType().getName());

                methods.add(method);
            }
        }

        routingContext.response().end(methods.encodePrettily());
    }
}

From source file:io.techcode.logbulk.pipeline.input.SyslogInput.java

License:Open Source License

/**
 * Default implementation returns a list of structured data elements with
 * no internal parsing.//from   www  .  j  a  va2  s  . com
 *
 * @param reader the reader.
 * @return the structured data.
 */
private JsonArray parseStructuredDataElements(Reader reader) {
    JsonArray fragments = new JsonArray();
    while (reader.is('[')) {
        reader.mark();
        reader.skipTo(']');
        fragments.add(reader.getMarkedSegment());
    }
    return fragments;
}

From source file:net.kuujo.vertigo.cluster.ClusterOptions.java

License:Apache License

@SuppressWarnings("unchecked")
public ClusterOptions(JsonObject options) {
    this.clustered = options.containsKey("clustered") ? options.getBoolean("clustered")
            : options.getString("cluster") != null;
    this.clusterAddress = options.getString("cluster", clusterAddress);
    this.nodeAddress = options.getString("node", nodeAddress);
    this.nodes = new HashSet(options.getJsonArray("nodes", new JsonArray()).getList());
}

From source file:net.kuujo.vertigo.context.impl.InputPortContextImpl.java

License:Apache License

@Override
public JsonObject toJson() {
    JsonArray connectionJson = new JsonArray();
    connections.forEach(connection -> connectionJson.add(connection.toJson()));

    JsonObject json = new JsonObject().put("name", name).put("connections", connectionJson);

    if (type != null && type != Object.class) {
        json.put("type", type.toString());
    }//w w  w.  j a v  a  2 s  . co m

    if (codec != null) {
        json.put("codec", codec.toString());
    }

    //    if (persistent) {
    //      json.put("persistent", persistent);
    //    }

    return json;

}

From source file:net.kuujo.vertigo.impl.AbstractResolver.java

License:Apache License

/**
 * Converts a Typesafe configuration list to {@link JsonObject}
 *
 * @param configs The Typesafe configuration list to convert.
 * @return The converted configuration.//from  w w w  . j  ava 2  s  . co m
 */
@SuppressWarnings("unchecked")
protected static JsonArray configListToJson(ConfigList configs) {
    JsonArray json = new JsonArray();
    for (ConfigValue value : configs) {
        if (value.valueType() == ConfigValueType.OBJECT) {
            json.add(configObjectToJson((Config) value));
        } else if (value.valueType() == ConfigValueType.LIST) {
            json.add(configListToJson((ConfigList) value));
        } else {
            json.add(value.unwrapped());
        }
    }
    return json;
}