List of usage examples for io.vertx.core.json JsonObject getJsonArray
public JsonArray getJsonArray(String key)
From source file:DbHelper.java
private void getFileFromFrolder(String projectId, List<JsonObject> listFolders, Handler<JsonArray> handler) { String queryFile = "SELECT files.`name` as name, files.crete_date as dateCreated, files.modify_date as dateModified , files.pk_id_file as id, files.FOLDERS_pk_id_folder as folderId FROM folders RIGHT JOIN files ON folders.pk_id_folder=files.pk_id_file and folders.pk_id_folder IN (SELECT pk_id_folder FROM folders WHERE `PROJECT_pk_id_project`=" + projectId + ")"; mySQLClient.getConnection(resConnection -> { if (resConnection.succeeded()) { SQLConnection connection;//from w w w .ja va 2 s. c o m connection = resConnection.result(); connection.setAutoCommit(false, autoCommit -> { if (autoCommit.succeeded()) { connection.query(queryFile, handlerQuery -> { if (handlerQuery.succeeded()) { ResultSet resultSet = handlerQuery.result(); List<JsonObject> listFiles = resultSet.getRows(); // System.out.println(new JsonArray(list).toString()); for (JsonObject listFile : listFiles) { int folderId = listFile.getInteger("folderId"); // System.out.println("id folder " + folderId); for (JsonObject listFolder : listFolders) { if (listFolder.getInteger("id") == folderId) { try { listFolder.getJsonArray("files").add(listFile); } catch (Exception e) { List<JsonObject> listTmpFile = new ArrayList<>(); listTmpFile.add(listFile); listFolder.put("files", listTmpFile); } } } } // System.out.println(new JsonArray(listFolders).toString()); handler.handle(new JsonArray(listFolders)); } else { System.out.println("failed " + handlerQuery.cause()); } connection.close(); }); } else { System.out.println("auto commit failed"); } }); // Got a connection } else { // Failed to get connection - deal with it System.out.println("true failes"); } }); }
From source file:com.chibchasoft.vertx.verticle.deployment.DependentsDeployment.java
License:Open Source License
/** * Populates this object with the information from the supplied JsonObject * @param json The JSON Object// www.j a v a 2 s .c om */ public void fromJson(JsonObject json) { Objects.requireNonNull(json, "json is required"); if (json.getValue("configurations") instanceof JsonArray) { json.getJsonArray("configurations").forEach(item -> { if (item instanceof JsonObject) { DeploymentConfiguration cfg = new DeploymentConfiguration(); cfg.fromJson((JsonObject) item); getConfigurations().add(cfg); } }); } }
From source file:com.chibchasoft.vertx.verticle.deployment.DeploymentConfiguration.java
License:Open Source License
/** * Populates this object with the information from the supplied JsonObject * @param json The JSON Object/* w w w. jav a 2 s.c o m*/ */ public void fromJson(JsonObject json) { Objects.requireNonNull(json, "json is required"); if (json.getValue("name") instanceof String) setName((String) json.getValue("name")); if (json.getValue("deploymentOptions") instanceof JsonObject) { setDeploymentOptions(new DeploymentOptions()); DeploymentOptionsConverter.fromJson((JsonObject) json.getValue("deploymentOptions"), this.getDeploymentOptions()); } if (json.getValue("dependents") instanceof JsonArray) { json.getJsonArray("dependents").forEach(item -> { if (item instanceof JsonObject) { DependentsDeployment deps = new DependentsDeployment(); deps.fromJson((JsonObject) item); getDependents().add(deps); } }); } }
From source file:com.cyngn.vertx.opentsdb.Util.java
License:Apache License
/** * Add another metric to a bulk metric./* ww w . java 2 s . c o m*/ * * @param bulkMetricObj the bulk metric obj to add more metrics to * @param metricToAdd the properly constructed individual metric object */ public static void addBulkMetric(JsonObject bulkMetricObj, JsonObject metricToAdd) { JsonArray metricHolder = bulkMetricObj.getJsonArray(MetricsParser.METRICS_FIELD); if (metricHolder == null) { throw new IllegalArgumentException( "Could not find a valid " + MetricsParser.METRICS_FIELD + " in the object"); } metricHolder.add(metricToAdd); }
From source file:com.englishtown.vertx.elasticsearch.ElasticSearchAdminServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { try {/* w ww.j ava 2 s . c o m*/ JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); } accessed(); switch (action) { case "putMapping": { service.putMapping(convertList(json.getJsonArray("indices").getList()), (java.lang.String) json.getValue("type"), (io.vertx.core.json.JsonObject) json.getValue("source"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.MappingOptions( json.getJsonObject("options")), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } } catch (Throwable t) { msg.reply(new ServiceException(500, t.getMessage())); throw t; } }
From source file:com.englishtown.vertx.elasticsearch.ElasticSearchServiceVertxProxyHandler.java
License:Apache License
public void handle(Message<JsonObject> msg) { JsonObject json = msg.body(); String action = msg.headers().get("action"); if (action == null) { throw new IllegalStateException("action not specified"); }/*from w w w . j a v a 2 s.co m*/ accessed(); switch (action) { case "start": { service.start(); break; } case "stop": { service.stop(); break; } case "index": { service.index((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (io.vertx.core.json.JsonObject) json.getValue("source"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.IndexOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "update": { service.update((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.UpdateOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "get": { service.get((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.GetOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "search": { service.search(convertList(json.getJsonArray("indices").getList()), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.SearchOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "searchScroll": { service.searchScroll((java.lang.String) json.getValue("scrollId"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.SearchScrollOptions(json.getJsonObject("options")), createHandler(msg)); break; } case "delete": { service.delete((java.lang.String) json.getValue("index"), (java.lang.String) json.getValue("type"), (java.lang.String) json.getValue("id"), json.getJsonObject("options") == null ? null : new com.englishtown.vertx.elasticsearch.DeleteOptions(json.getJsonObject("options")), createHandler(msg)); break; } default: { throw new IllegalStateException("Invalid action: " + action); } } }
From source file:com.funmix.service.LineServiceImpl.java
@Override public Future<Optional<Line>> insert(JsonObject json) { log.info(json.toString());/*from w ww. j av a2 s .c om*/ Future<Optional<Line>> result = Future.future(); JsonArray params = new JsonArray(); // licenseplate,drivername,startaddr,starttime,endtime,endaddr,linename,path params.add(json.getString("licenseplate")); params.add(json.getString("drivername")); params.add(json.getString("startaddr")); params.add(json.getString("starttime")); params.add(json.getString("endtime")); params.add(json.getString("endaddr")); params.add(json.getString("linename")); params.add(json.getJsonArray("path").toString()); StringBuffer updateOrder = new StringBuffer("update torder set status=2 where orderno in ("); JsonArray setparams = new JsonArray(); if (json.getValue("orderlist") != null) { JsonArray ja = json.getJsonArray("orderlist"); ja.forEach(r -> { updateOrder.append("?,"); setparams.add(r); }); updateOrder.deleteCharAt(updateOrder.length() - 1).append(")"); } log.info(setparams.toString()); log.info(params.toString()); client.getConnection(connHandler(result, connection -> { connection.updateWithParams(updateOrder.toString(), setparams, ru -> { if (ru.failed()) { result.fail(ru.cause()); log.info(ru.cause()); } else { connection.updateWithParams(SQL_INSERT, params, r -> { if (r.failed()) { result.fail(r.cause()); log.info(r.cause()); } else { UpdateResult urs = r.result(); params.clear(); params.add(urs.getKeys().getInteger(0)); log.info(urs.getKeys().getInteger(0)); connection.queryWithParams(SQL_QUERY, params, rs -> { if (rs.failed()) { result.fail(rs.cause()); log.info(rs.cause()); } else { List<JsonObject> list = rs.result().getRows(); if (list == null || list.isEmpty()) { result.complete(Optional.empty()); } else { result.complete(Optional.of(new Line(list.get(0)))); } } }); } connection.close(); }); } }); })); return result; }
From source file:com.github.ithildir.airbot.service.impl.MapQuestGeoServiceImpl.java
License:Open Source License
private Location _getLocation(JsonObject jsonObject) { JsonArray resultsJsonArray = jsonObject.getJsonArray("results"); JsonObject resultJsonObject = resultsJsonArray.getJsonObject(0); JsonArray locationsJsonArray = resultJsonObject.getJsonArray("locations"); JsonObject locationJsonObject = locationsJsonArray.getJsonObject(0); JsonObject latLngJsonObject = locationJsonObject.getJsonObject("latLng"); double latitude = latLngJsonObject.getDouble("lat"); double longitude = latLngJsonObject.getDouble("lng"); String country = locationJsonObject.getString("adminArea1"); return new Location(latitude, longitude, country); }
From source file:com.github.ithildir.numbers.game.NumbersGameVerticle.java
License:Open Source License
private void _handle(RoutingContext routingContext) { JsonObject requestJSON = routingContext.getBodyAsJson(); JsonArray inputsJSON = requestJSON.getJsonArray("inputs"); JsonObject inputJSON = inputsJSON.getJsonObject(0); String intent = inputJSON.getString("intent"); if (intent.equals(ConversationUtil.INTENT_MAIN)) { _handleMain(routingContext.response()); } else {// w w w . j av a2s . co m _handleText(requestJSON, inputJSON, routingContext.response()); } }
From source file:com.github.ithildir.numbers.game.NumbersGameVerticle.java
License:Open Source License
private void _handleText(JsonObject requestJSON, JsonObject inputJSON, HttpServerResponse httpServerResponse) { JsonArray rawInputsJSON = inputJSON.getJsonArray("raw_inputs"); JsonObject rawInputJSON = rawInputsJSON.getJsonObject(0); String query = rawInputJSON.getString("query"); JsonObject conversationJSON = requestJSON.getJsonObject("conversation"); int correctAnswer = Integer.parseInt(conversationJSON.getString("conversation_token")); int answer;/*from w w w .ja va 2 s .com*/ try { answer = Integer.parseInt(query); } catch (NumberFormatException nfe) { ConversationUtil.ask(httpServerResponse, String.valueOf(correctAnswer), "That's not a number, say it again!", _NO_INPUT_PROMPTS); return; } String textToSpeech = "You're right, it is " + correctAnswer + "!"; if (answer != correctAnswer) { textToSpeech = "You're wrong, it was " + correctAnswer + "!"; } ConversationUtil.tell(httpServerResponse, textToSpeech); }