List of usage examples for io.vertx.core.json JsonObject fieldNames
public Set<String> fieldNames()
From source file:com.cyngn.vertx.opentsdb.Util.java
License:Apache License
/** * Take config specified tags and make a OpenTsDb tag string * * @param tags the map of tags to convert to their string form * @return list of tags in opentsdb format ie 'name1=value1 name2=value2' */// www .java2 s . c o m public static String createTagsFromJson(JsonObject tags) { String tagsString = ""; if (tags != null && tags.size() > 0) { StringBuilder builder = new StringBuilder(); for (String key : tags.fieldNames()) { builder.append(key).append("=").append(tags.getString(key)).append(" "); } // if necessary, grab all but the last character, since it's always a space if (builder.length() > 0) { tagsString = builder.substring(0, builder.length() - 1); } else { tagsString = builder.toString(); } } return tagsString; }
From source file:com.englishtown.vertx.jersey.impl.DefaultJerseyOptions.java
License:Open Source License
protected ResourceConfig getResourceConfig() { checkState();/* w w w .j a v a 2 s . c o m*/ JsonArray resources = config.getJsonArray(CONFIG_RESOURCES, null); if (resources == null || resources.size() == 0) { throw new RuntimeException( "At least one resource package name must be specified in the config " + CONFIG_RESOURCES); } String[] resourceArr = new String[resources.size()]; for (int i = 0; i < resources.size(); i++) { resourceArr[i] = resources.getString(i); } ResourceConfig rc = new ResourceConfig(); rc.packages(resourceArr); ClassLoader cl = Thread.currentThread().getContextClassLoader(); JsonArray features = config.getJsonArray(CONFIG_FEATURES, null); if (features != null && features.size() > 0) { for (int i = 0; i < features.size(); i++) { try { Class<?> clazz = cl.loadClass(features.getString(i)); rc.register(clazz); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } } } // Always register the InternalVertxJerseyBinder rc.register(new InternalVertxJerseyBinder(vertx)); // Register configured binders JsonArray binders = config.getJsonArray(CONFIG_BINDERS, null); if (binders != null && binders.size() > 0) { for (int i = 0; i < binders.size(); i++) { try { Class<?> clazz = cl.loadClass(binders.getString(i)); rc.register(clazz.newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } } final JsonObject resourceConfigAdditions = config.getJsonObject(CONFIG_RESOURCE_CONFIG); if (resourceConfigAdditions != null) { for (final String fieldName : resourceConfigAdditions.fieldNames()) { rc.property(fieldName, resourceConfigAdditions.getValue(fieldName)); } } return rc; }
From source file:com.github.ithildir.airbot.service.impl.WaqiMeasurementServiceImpl.java
License:Open Source License
private Measurement _getMeasurement(JsonObject jsonObject) { String status = jsonObject.getString("status"); if (!"ok".equals(status)) { _logger.warn("Unable to use response {0}", jsonObject); return null; }//from www . jav a 2s. c o m JsonObject dataJsonObject = jsonObject.getJsonObject("data"); JsonObject cityJsonObject = dataJsonObject.getJsonObject("city"); String city = cityJsonObject.getString("name"); JsonObject timeJsonObject = dataJsonObject.getJsonObject("time"); String dateTime = timeJsonObject.getString("s"); String dateTimeOffset = timeJsonObject.getString("tz"); String date = dateTime.substring(0, 10); String time = dateTime.substring(11); TemporalAccessor temporalAccessor = DateTimeFormatter.ISO_OFFSET_DATE_TIME .parse(date + "T" + time + dateTimeOffset); Instant instant = Instant.from(temporalAccessor); int aqi = dataJsonObject.getInteger("aqi"); String mainPollutant = dataJsonObject.getString("dominentpol"); Map<String, Double> values = new HashMap<>(); JsonObject valuesJsonObject = dataJsonObject.getJsonObject("iaqi"); for (String pollutant : valuesJsonObject.fieldNames()) { JsonObject pollutantJsonObject = valuesJsonObject.getJsonObject(pollutant); double value = pollutantJsonObject.getDouble("v"); values.put(pollutant, value); } return new Measurement(city, instant.toEpochMilli(), aqi, mainPollutant, values, null); }
From source file:com.groupon.vertx.memcache.MemcacheClusterConfig.java
License:Apache License
public MemcacheClusterConfig(JsonObject jsonConfig) { if (jsonConfig == null) { log.error("initialize", "exception", "noConfigFound"); throw new MemcacheException("No Memcache cluster config found"); }/* w w w. j av a 2 s .c om*/ this.eventBusAddressPrefix = jsonConfig.getString(EVENT_BUS_ADDRESS_PREFIX_KEY); this.retryInterval = jsonConfig.getLong(RETRY_INTERVAL, MemcacheConfig.DEFAULT_RETRY_INTERVAL); JsonObject clusters = jsonConfig.getJsonObject(CLUSTERS_KEY, new JsonObject()); if (eventBusAddressPrefix != null && !eventBusAddressPrefix.isEmpty() && clusters.size() > 0) { for (String clusterKey : clusters.fieldNames()) { JsonObject clusterConfig = clusters.getJsonObject(clusterKey, new JsonObject()).copy(); clusterConfig.put(EVENT_BUS_ADDRESS_KEY, eventBusAddressPrefix); clusterConfig.put(RETRY_INTERVAL, retryInterval); clusterMap.put(clusterKey, new MemcacheConfig(clusterConfig)); } } else { log.error("initialize", "exception", "invalidConfigFound", new String[] { "config" }, jsonConfig.encode()); throw new MemcacheException("Invalid Memcache config defined"); } log.info("initialize", "success", new String[] { "eventBusAddressPrefix", "clusters" }, eventBusAddressPrefix, clusterMap.size()); }
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"); }/*from ww w . j av a2 s.c om*/ 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:de.fraunhofer.fokus.redistest.DoInterestingThings.java
License:Creative Commons License
/** * transfer hash table from redis into Entry * @param json - JsonObject stored in redis, all fields are of type string * @return Entry/*from w w w.j a v a2s.c o m*/ */ private JsonObject toEntry(JsonObject json) { Entry entry = new Entry().setHandle(json.getString(Constants.KEY_RECORD_ID)); json.remove(Constants.KEY_RECORD_ID); for (String fn : json.fieldNames()) { switch (fn) { case Constants.KEY_DICE_VALUE: case Constants.KEY_FAMILYNAME: case Constants.KEY_FIRSTNAME: case Constants.KEY_DAY_OF_BIRTH: case Constants.KEY_MONTH_OF_BIRTH: case Constants.KEY_YEAR_OF_BIRTH: case Constants.KEY_PLACE_OF_BIRTH: case Constants.KEY_GENDER: json.put(fn, Double.parseDouble(json.getString(fn))); break; } } return entry.setDiceJson(json); }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
private void emptySize(final UserInfos userInfos, final Handler<Long> emptySizeHandler) { try {// www . ja v a 2 s .c om long quota = Long.valueOf(userInfos.getAttribute("quota").toString()); long storage = Long.valueOf(userInfos.getAttribute("storage").toString()); emptySizeHandler.handle(quota - storage); } catch (Exception e) { getUserQuota(userInfos.getUserId(), new Handler<JsonObject>() { @Override public void handle(JsonObject j) { long quota = j.getLong("quota", 0l); long storage = j.getLong("storage", 0l); for (String attr : j.fieldNames()) { UserUtils.addSessionAttribute(eb, userInfos.getUserId(), attr, j.getLong(attr), null); } emptySizeHandler.handle(quota - storage); } }); } }
From source file:fr.wseduc.rack.controllers.RackController.java
License:Open Source License
private void createThumbnailIfNeeded(final String collection, final JsonObject srcFile, final String documentId, JsonObject oldThumbnail, final List<String> thumbs) { if (documentId != null && thumbs != null && !documentId.trim().isEmpty() && !thumbs.isEmpty() && srcFile != null && isImage(srcFile) && srcFile.getString("_id") != null) { createThumbnails(thumbs, srcFile, collection, documentId); }// w ww . ja v a2 s.c om if (oldThumbnail != null) { for (String attr : oldThumbnail.fieldNames()) { storage.removeFile(oldThumbnail.getString(attr), null); } } }
From source file:io.apiman.gateway.platforms.vertx3.config.VertxEngineConfig.java
License:Apache License
public Map<String, String> getBasicAuthCredentials() { if (!basicAuthMap.isEmpty()) return basicAuthMap; JsonObject pairs = config.getJsonObject(API_AUTH).getJsonObject("basic"); for (String username : pairs.fieldNames()) { basicAuthMap.put(username, pairs.getString(username)); }//from www . j a v a 2s. co m return basicAuthMap; }
From source file:io.techcode.logbulk.pipeline.input.SyslogInput.java
License:Open Source License
@Override protected void onStart() { // Setup mapping JsonObject map = config.getJsonObject(CONF_MAPPING, new JsonObject()); mapping = Maps.newEnumMap(SyslogHeader.class); for (String entry : map.fieldNames()) { mapping.put(SyslogHeader.byName(entry), map.getString(entry)); }/*from w w w.j av a 2 s.c o m*/ skipStructuredData = config.getBoolean("skipStructuredData", false); }