List of usage examples for io.vertx.core.json JsonObject getJsonObject
public JsonObject getJsonObject(String key)
From source file:com.groupon.vertx.utils.config.Config.java
License:Apache License
public Config(JsonObject config) { final JsonObject verticleJson = config.getJsonObject(VERTICLES_FIELD); if (verticleJson == null) { throw new IllegalStateException("Required config field `" + VERTICLES_FIELD + "` is missing"); }/*ww w .j a v a 2s.c o m*/ Set<String> verticleNames = verticleJson.fieldNames(); total = verticleNames.size(); verticles = new ConcurrentHashMap<>(total); for (String verticleName : verticleNames) { JsonObject verticleConfig = verticleJson.getJsonObject(verticleName); verticles.put(verticleName, new VerticleConfig(verticleName, verticleConfig)); } determineLoadOrder(); }
From source file:com.hpe.sw.cms.verticle.ApiVerticle.java
License:Apache License
private JsonObject createObj(JsonObject event) { try {//from w w w.ja v a2 s .c om JsonObject image = new JsonObject(); String timestamp = event.getString("timestamp"); if (timestamp != null && timestamp.length() > 19) { timestamp = timestamp.substring(0, 10) + " " + timestamp.substring(11, 19); image.put("timestamp", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(timestamp).getTime()); } String url = event.getJsonObject("target").getString("url"); image.put("name", event.getJsonObject("target").getString("repository")); image.put("host", event.getJsonObject("request").getString("host")); image.put(Image.EVENT_URL, url); return image; } catch (Exception e) { LOG.error("Error in reading event to object ", e); return null; } }
From source file:com.hubrick.vertx.rest.RestClientOptions.java
License:Apache License
public RestClientOptions(final JsonObject json) { super(json);/*from www . j a v a 2s .com*/ final JsonObject jsonObjectGlobalRequestCacheOptions = json.getJsonObject("globalRequestCacheOptions"); if (jsonObjectGlobalRequestCacheOptions != null) { final RequestCacheOptions requestCacheOptions = new RequestCacheOptions(); final Integer ttlInMillis = jsonObjectGlobalRequestCacheOptions.getInteger("ttlInMillis"); final Boolean evictBefore = jsonObjectGlobalRequestCacheOptions.getBoolean("evictBefore"); if (jsonObjectGlobalRequestCacheOptions.getJsonArray("cachedStatusCodes") != null) { final Set<Integer> cachedStatusCodes = jsonObjectGlobalRequestCacheOptions .getJsonArray("cachedStatusCodes").stream().map(e -> (Integer) e) .collect(Collectors.toSet()); requestCacheOptions.withCachedStatusCodes(cachedStatusCodes); } if (ttlInMillis != null) { requestCacheOptions.withExpiresAfterWriteMillis(ttlInMillis); } if (evictBefore != null) { requestCacheOptions.withEvictBefore(evictBefore); } globalRequestCacheOptions = requestCacheOptions; } globalHeaders = new CaseInsensitiveHeaders(); globalRequestTimeoutInMillis = json.getLong("globalRequestTimeoutInMillis", DEFAULT_GLOBAL_REQUEST_TIMEOUT_IN_MILLIS); }
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 a v a 2 s . co 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);/* w w w .j a va 2 s. c o m*/ } } 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 www .ja va2s . c om } } return matchesArr; }
From source file:com.nasa.ElasticSearchAdapter.java
public JsonObject postFeedback(JsonObject feedback) throws IOException { JsonObject result = new JsonObject(); String data = feedback.toString(); // normalize or remove non ascii characters data = Normalizer.normalize(data, Normalizer.Form.NFD); data = data.replaceAll("[^\\x00-\\x7F]", ""); JsonObject response = doPost(ES_URL + "/healthy-travel/feedback", data); result.put("success", response.getJsonObject("_shards").getInteger("successful") > 0); return result; }
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;/*from ww w.j av 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("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;// w ww .j a v a 2s.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++;// www. j a v a 2 s .co m } 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; }