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

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

Introduction

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

Prototype

public Double getDouble(int pos) 

Source Link

Document

Get the Double at position pos in the array,

Usage

From source file:org.azrul.langmera.DecisionService.java

private void getHistory(RoutingContext routingContext) {
    final HistoryRequest req = Json.decodeValue(routingContext.getBodyAsString(), HistoryRequest.class);
    List<HistoryResponseElement> histResponses = new ArrayList<>();
    String driver = config.getProperty("jdbc.driver", String.class);
    String url = config.getProperty("jdbc.url", String.class);
    String username = config.getProperty("jdbc.username", String.class);
    String password = config.getProperty("jdbc.password", String.class);

    JDBCClient client = JDBCClient.createShared(vertx, new JsonObject().put("url", url)
            .put("driver_class", driver).put("user", username).put("password", password));
    JsonArray param = new JsonArray();
    param.add(req.getContext()).add(req.getFrom()).add(req.getTo());
    //        for (int i = 0; i < InMemoryDB.store.get(0).size(); i++) {
    //            HistoryResponseElement resp = new HistoryResponseElement();
    //            String context = (String) InMemoryDB.store.get(0).get(i);
    //            if (context.equals(req.getContext())) {
    //                Date time = (Date) InMemoryDB.store.get(3).get(i);
    //                if (time.after(req.getFrom()) && time.before(req.getTo())) {
    //                    resp.setContext(context);
    //                    resp.setDecision((String) InMemoryDB.store.get(1).get(i));
    //                    resp.setInterest((Double) InMemoryDB.store.get(2).get(i));
    //                    resp.setTime(time);
    //                    histResponses.add(resp);
    //                }
    //            }
    //        }//from   w  w  w. j  av  a 2s . co  m

    client.getConnection(ar -> {
        SQLConnection connection = ar.result();
        connection.queryWithParams(
                "SELECT * FROM Trace ORDER BY decisiontime desc where context=? and decisiontime between ? and ?",
                param, r -> {
                    if (r.succeeded()) {
                        for (JsonArray row : r.result().getResults()) {
                            HistoryResponseElement respElement = new HistoryResponseElement();
                            respElement.setContext(row.getString(1));
                            respElement.setDecision(row.getString(6));
                            respElement.setInterest(row.getDouble(8));
                            respElement.setTime(new Date(row.getLong(5)));
                            histResponses.add(respElement);
                        }
                        HistoryResponse resp = new HistoryResponse();
                        resp.setElements(histResponses);

                        routingContext.response().setStatusCode(201)
                                .putHeader("content-type", "application/json; charset=utf-8")
                                .exceptionHandler(ex -> {
                                    logger.log(Level.SEVERE, "Problem encountered when making decision", ex);
                                }).end(Json.encodePrettily(resp));
                    }

                    connection.close();
                });

    });

}