List of usage examples for io.vertx.core.json JsonArray add
public JsonArray add(Object value)
From source file:com.nasa.ElasticSearchAdapter.java
public JsonObject getSymptoms(String word) throws IOException { JsonObject result = new JsonObject(); JsonArray matchesArr = new JsonArray(); String data = "{\n" + " \"size\": 0,\n" + " \"aggs\" : {\n" + " \"langs\" : {\n" + " \"terms\" : { \"field\" : \"symptoms.name\" }\n" + " }\n" + " }\n" + "}"; JsonObject response = doPost(ES_URL + "/healthy-travel/feedback/_search", data); JsonArray items = response.getJsonObject("aggregations").getJsonObject("langs").getJsonArray("buckets"); for (Object item : items) { JsonObject obj = (JsonObject) item; String key = obj.getString("key"); if (key != null && obj.getString("key").startsWith(word)) { matchesArr.add(key); }/*from w ww . j ava 2 s . c o m*/ } result.put("symptoms", matchesArr); return result; }
From source file:com.nasa.ElasticSearchAdapter.java
public JsonObject getConditions(String word) throws IOException { JsonObject result = new JsonObject(); JsonArray matchesArr = new JsonArray(); String data = "{\n" + " \"size\": 0,\n" + " \"aggs\" : {\n" + " \"langs\" : {\n" + " \"terms\" : { \"field\" : \"condition\" }\n" + " }\n" + " }\n" + "}"; JsonObject response = doPost(ES_URL + "/healthy-travel/feedback/_search", data); JsonArray items = response.getJsonObject("aggregations").getJsonObject("langs").getJsonArray("buckets"); for (Object item : items) { JsonObject obj = (JsonObject) item; String key = obj.getString("key"); if (key != null && obj.getString("key").startsWith(word)) { matchesArr.add(key); }/*from w ww . ja v a 2s .com*/ } result.put("conditions", matchesArr); return result; }
From source file:com.nasa.ElasticSearchAdapter.java
public JsonArray getCheck(Float lat, Float lon) throws IOException { JsonArray matchesArr = new JsonArray(); String data = "{\n" + " \"size\": 0,\n" + " \"query\": {\n" + " \"filtered\": {\n" + " \"query\": {\n" + " \"match_all\": {}\n" + " },\n" + " \"filter\": {\n" + " \"geo_distance\": {\n" + " \"distance\": \"100km\",\n" + " \"location\": {\n" + " \"lat\": " + lat + ",\n" + " \"lon\": " + lon + "\n" + " }\n" + " }\n" + " }\n" + " }\n" + " },\n" + " \"aggs\": {\n" + " \"langs\": {\n" + " \"terms\": {\n" + " \"field\": \"condition\"\n" + " }\n" + " }\n" + " }\n" + "}"; JsonObject response = doPost(ES_URL + "/healthy-travel/feedback/_search", data); JsonArray items = response.getJsonObject("aggregations").getJsonObject("langs").getJsonArray("buckets"); for (Object item : items) { JsonObject obj = (JsonObject) item; String key = obj.getString("key"); int value = obj.getInteger("doc_count"); if (key != null && value > 0) { JsonObject cond = new JsonObject(); cond.put("name", key); cond.put("reported_cases", value); matchesArr.add(cond); }/*from w w w .ja va 2 s . c om*/ } return matchesArr; }
From source file:com.nasa.Transformer.java
public static JsonObject weatherToMap(JsonObject jsonObject) { JsonObject result = new JsonObject(); JsonArray featuresArr = new JsonArray(); JsonArray items = jsonObject.getJsonObject("hits").getJsonArray("hits"); int idx = 0;// w ww. j a v a 2 s .co m for (Object hit : items) { JsonObject source = ((JsonObject) hit).getJsonObject("_source"); JsonObject feature = new JsonObject(); feature.put("type", "Feature"); feature.put("id", idx); JsonObject properties = new JsonObject(); float mag = source.getJsonObject("weather").getFloat("temp"); properties.put("mag", mag); feature.put("properties", properties); JsonObject geometry = new JsonObject(); geometry.put("type", "Point"); JsonArray coordinates = new JsonArray(); Float lon = source.getJsonObject("location").getFloat("lon"); Float lat = source.getJsonObject("location").getFloat("lat"); coordinates.add(lon); coordinates.add(lat); geometry.put("coordinates", coordinates); feature.put("geometry", geometry); featuresArr.add(feature); idx++; } result.put("type", "FeatureCollection"); result.put("features", featuresArr); return result; }
From source file:com.nasa.Transformer.java
public static JsonObject pollutionToMap(JsonObject jsonObject) { JsonObject result = new JsonObject(); JsonArray featuresArr = new JsonArray(); JsonArray items = jsonObject.getJsonObject("hits").getJsonArray("hits"); int idx = 0;//from w w w. jav a 2 s .c o m for (Object hit : items) { JsonObject source = ((JsonObject) hit).getJsonObject("_source"); JsonObject feature = new JsonObject(); feature.put("type", "Feature"); feature.put("id", idx); JsonObject properties = new JsonObject(); float mag = source.getJsonObject("pollution").getFloat("aqi"); properties.put("mag", mag); feature.put("properties", properties); JsonObject geometry = new JsonObject(); geometry.put("type", "Point"); JsonArray coordinates = new JsonArray(); Float lon = source.getJsonObject("location").getFloat("lon"); Float lat = source.getJsonObject("location").getFloat("lat"); coordinates.add(lon); coordinates.add(lat); geometry.put("coordinates", coordinates); feature.put("geometry", geometry); featuresArr.add(feature); idx++; } result.put("type", "FeatureCollection"); result.put("features", featuresArr); return result; }
From source file:com.nasa.Transformer.java
public static JsonObject conditionToMap(JsonObject jsonObject) { // private String conditionsMap = "{\n" // + " \"Diseases\": [\n" // + " {\n" // + " \"lat\": 46.77029284,\n" // + " \"lng\": 23.57641889,\n" // + " \"type\": \"something good\",\n" // + " \"description\": \"good\",\n" // + " \"rating\": 1.23\n" // + " },\n" // + " {\n" // + " \"lat\": 46.78185201,\n" // + " \"lng\": 23.68522613,\n" // + " \"type\": \"something not bad\",\n" // + " \"description\": \"not bad\",\n" // + " \"rating\": 3.99\n" // + " },\n" // + " {\n" // + " \"lat\": 46.7558097,\n" // + " \"lng\": 23.5940353,\n" // + " \"type\": \"something bad\",\n" // + " \"description\": \"bad\",\n" // + " \"rating\": 4.75\n" // + " }\n" // + " ]\n" // + "}"; JsonObject result = new JsonObject(); JsonArray featuresArr = new JsonArray(); JsonArray items = jsonObject.getJsonObject("hits").getJsonArray("hits"); for (Object hit : items) { JsonObject source = ((JsonObject) hit).getJsonObject("_source"); JsonObject feature = new JsonObject(); Float lon = source.getJsonObject("location").getFloat("lon"); Float lat = source.getJsonObject("location").getFloat("lat"); feature.put("lat", lat); feature.put("lng", lon); feature.put("type", source.getString("condition")); String symptoms = ""; int ratingSum = 0; int ratingCount = 0; JsonArray symptomsJ = source.getJsonArray("symptoms"); for (Object sym : symptomsJ) { JsonObject symJ = (JsonObject) sym; symptoms += symJ.getString("name") + ", "; ratingSum += symJ.getInteger("rating"); ratingCount++;/*from w w w . j av a2 s . com*/ } feature.put("description", symptoms); if (ratingCount > 0) { feature.put("rating", ratingSum / ratingCount); } else { feature.put("rating", 0); } featuresArr.add(feature); } result.put("Diseases", featuresArr); return result; }
From source file:de.bischinger.anotherblog.RestVerticle.java
License:Open Source License
private void handleListBlogs(RoutingContext routingContext) { JsonArray arr = new JsonArray(); vertx.executeBlocking(future -> { SearchResponse searchResponse = client.prepareSearch(indexName).execute().actionGet(); future.complete(searchResponse); }, result -> {/*from w w w.j a va2s . c o m*/ SearchResponse searchResponse = (SearchResponse) result.result(); searchResponse.getHits().forEach(hit -> arr.add(hit.getSourceAsString())); routingContext.response().putHeader("content-type", "application/json").end(arr.encodePrettily()); }); }
From source file:de.braintags.netrelay.controller.api.DataTablesController.java
License:Open Source License
private JsonObject createJsonObject(IMapper mapper, List<IStoreObject<?, ?>> selection, DataTableLinkDescriptor descr, long completeCount, long tableCount) { LOGGER.info("tableCount: " + tableCount + ", completeCount: " + completeCount); JsonObject json = new JsonObject(); json.put("recordsTotal", tableCount); json.put("recordsFiltered", completeCount); JsonArray resArray = new JsonArray(); json.put("data", resArray); for (IStoreObject<?, ?> ob : selection) { resArray.add(handleObject(mapper, ob, descr)); }//w w w.ja v a 2s . co m return json; }
From source file:de.braintags.netrelay.controller.api.DataTablesController.java
License:Open Source License
private JsonArray handleObject(IMapper mapper, IStoreObject<?, ?> sto, DataTableLinkDescriptor descr) { JsonArray json = new JsonArray(); for (ColDef colDef : descr.getColumns()) { if (colDef != null && colDef.name != null && colDef.name.hashCode() != 0) { IField field = mapper.getField(colDef.name); Objects.requireNonNull(field, "Could not find defined field for '" + colDef.name + "'"); Object value = sto.get(field); json.add(value == null ? "" : value); } else {//from w ww .j a v a 2 s. c om json.add(""); } } return json; }
From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java
License:Open Source License
protected JsonArray buildJsonFilesArray(ElFinderContext efContext, ITarget target) { JsonArray returnArray = new JsonArray(); returnArray.add(getTargetInfo(efContext, target)); return returnArray; }