Example usage for io.vertx.core.json JsonObject getValue

List of usage examples for io.vertx.core.json JsonObject getValue

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getValue.

Prototype

public Object getValue(String key) 

Source Link

Document

Get the value with the specified key, as an Object with types respecting the limitations of JSON.

Usage

From source file:com.github.edgar615.util.vertx.wheel.KeepaliveOptionsConverter.java

License:Apache License

public static void fromJson(JsonObject json, KeepaliveOptions obj) {
    if (json.getValue("disConnAddress") instanceof String) {
        obj.setDisConnAddress((String) json.getValue("disConnAddress"));
    }/*from   www. j ava2  s. c  o m*/
    if (json.getValue("firstConnAddress") instanceof String) {
        obj.setFirstConnAddress((String) json.getValue("firstConnAddress"));
    }
    if (json.getValue("interval") instanceof Number) {
        obj.setInterval(((Number) json.getValue("interval")).intValue());
    }
    if (json.getValue("step") instanceof Number) {
        obj.setStep(((Number) json.getValue("step")).intValue());
    }
}

From source file:com.github.edgar615.util.vertx.wheel.TimerWheelOptionsConverter.java

License:Apache License

public static void fromJson(JsonObject json, TimerWheelOptions obj) {
    if (json.getValue("announceAddress") instanceof String) {
        obj.setAnnounceAddress((String) json.getValue("announceAddress"));
    }//from   w w  w  .  j  av  a  2  s.  co  m
    if (json.getValue("cancelAddress") instanceof String) {
        obj.setCancelAddress((String) json.getValue("cancelAddress"));
    }
    if (json.getValue("interval") instanceof Number) {
        obj.setInterval(((Number) json.getValue("interval")).intValue());
    }
}

From source file:com.github.ithildir.airbot.model.LocationConverter.java

License:Apache License

public static void fromJson(JsonObject json, Location obj) {
    if (json.getValue("country") instanceof String) {
        obj.setCountry((String) json.getValue("country"));
    }/*w w  w. j  a v  a 2  s  . c om*/
    if (json.getValue("latitude") instanceof Number) {
        obj.setLatitude(((Number) json.getValue("latitude")).doubleValue());
    }
    if (json.getValue("longitude") instanceof Number) {
        obj.setLongitude(((Number) json.getValue("longitude")).doubleValue());
    }
}

From source file:com.github.ithildir.airbot.model.MeasurementConverter.java

License:Apache License

public static void fromJson(JsonObject json, Measurement obj) {
    if (json.getValue("aqi") instanceof Number) {
        obj.setAqi(((Number) json.getValue("aqi")).intValue());
    }//from  w  w w. j  ava  2 s  .  c  o  m
    if (json.getValue("city") instanceof String) {
        obj.setCity((String) json.getValue("city"));
    }
    if (json.getValue("comments") instanceof String) {
        obj.setComments((String) json.getValue("comments"));
    }
    if (json.getValue("mainPollutant") instanceof String) {
        obj.setMainPollutant((String) json.getValue("mainPollutant"));
    }
    if (json.getValue("time") instanceof Number) {
        obj.setTime(((Number) json.getValue("time")).longValue());
    }
    if (json.getValue("values") instanceof JsonObject) {
        java.util.Map<String, java.lang.Double> map = new java.util.LinkedHashMap<>();
        json.getJsonObject("values").forEach(entry -> {
            if (entry.getValue() instanceof Number)
                map.put(entry.getKey(), ((Number) entry.getValue()).doubleValue());
        });
        obj.setValues(map);
    }
}

From source file:com.github.ithildir.airbot.service.GeoServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {// ww w  .j av a  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 "getLocationByCoordinates": {
            service.getLocationByCoordinates(
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "getLocationByQuery": {
            service.getLocationByQuery((java.lang.String) json.getValue("query"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:com.github.ithildir.airbot.service.MeasurementServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//ww  w .  ja  v  a2s .  com
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "getMeasurement": {
            service.getMeasurement(
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "getName": {
            service.getName(createHandler(msg));
            break;
        }
        case "init": {
            service.init(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.github.ithildir.airbot.service.UserServiceVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//  w ww.  j  a v a 2 s . c om
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "getUserLocation": {
            service.getUserLocation((java.lang.String) json.getValue("userId"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "updateUserLocation": {
            service.updateUserLocation((java.lang.String) json.getValue("userId"),
                    json.getValue("latitude") == null ? null : (json.getDouble("latitude").doubleValue()),
                    json.getValue("longitude") == null ? null : (json.getDouble("longitude").doubleValue()),
                    (java.lang.String) json.getValue("country"), 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.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void prepareEnsureUnique(String id, JsonObject instance, RBatch redissonBatch, ArrayList<String> pList,
        String parent) throws RepositoryException {
    try {/*www. j  a va 2 s  .c  o m*/
        BeanMap pMap = new BeanMap(cls.newInstance());
        pMap.keySet().forEach(e -> {
            if ("class".equals(e) || instance.getValue(e.toString()) == null) {
                return;
            }
            Class type = pMap.getType(e.toString());
            String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString());
            if (isRedisEntity(type)) {
                try {
                    RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type);
                    innerRepo.prepareEnsureUnique(id, instance.getJsonObject(e.toString()), redissonBatch,
                            pList, fieldName);
                } catch (RepositoryException ex) {
                    throw new RuntimeException(ex);
                }
            } else {
                try {
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonUnique.class)) {
                        redissonBatch.getMap(getUniqueKey(e.toString()))
                                .putIfAbsentAsync(instance.getValue(e.toString()), id);
                        pList.add(fieldName);
                    }
                } catch (NoSuchFieldException | SecurityException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
    } catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
        throw new RepositoryException(ex);
    }
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void prepareUndoUnique(String id, JsonObject instance, RBatch redissonBatch, ArrayList<String> pList,
        String parent) throws RepositoryException {
    try {//from w ww . j a  va  2s  .  co m
        BeanMap pMap = new BeanMap(cls.newInstance());
        pMap.keySet().forEach(e -> {
            if ("class".equals(e) || instance.getValue(e.toString()) == null) {
                return;
            }
            Class type = pMap.getType(e.toString());
            String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString());
            if (isRedisEntity(type)) {
                try {
                    RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type);
                    innerRepo.prepareUndoUnique(id, instance.getJsonObject(e.toString()), redissonBatch, pList,
                            fieldName);
                } catch (RepositoryException ex) {
                    throw new RuntimeException(ex);
                }
            } else {
                try {
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonUnique.class)
                            && pList.contains(fieldName)) {
                        redissonBatch.getMap(getUniqueKey(e.toString()))
                                .removeAsync(instance.getValue(e.toString()), id);
                    }
                } catch (NoSuchFieldException | SecurityException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
    } catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
        throw new RepositoryException(ex);
    }
}

From source file:com.github.jackygurui.vertxredissonrepository.repository.Impl.RedisRepositoryImpl.java

License:Apache License

private void prepareEnsuerIndex(String id, T r, JsonObject instance, Boolean isNew, RBatch redissonBatch,
        ArrayList<String> pList, String parent) throws RepositoryException {
    try {/*from  w  w w.ja va  2s. c  o  m*/
        BeanMap pMap = new BeanMap(r == null ? cls.newInstance() : r);
        pMap.keySet().forEach(e -> {
            if ("class".equals(e) || instance.getValue(e.toString()) == null) {
                return;
            }
            Class type = pMap.getType(e.toString());
            String fieldName = (parent == null ? "" : parent.concat(".")).concat(e.toString());
            if (isRedisEntity(type)) {
                try {
                    RedisRepositoryImpl innerRepo = (RedisRepositoryImpl) factory.instance(type);
                    innerRepo.prepareEnsuerIndex(id, pMap.get(e), instance.getJsonObject(e.toString()), isNew,
                            redissonBatch, pList, fieldName);
                } catch (RepositoryException ex) {
                    throw new RuntimeException(ex);
                }
            } else {
                try {
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonIndex.class)) {
                        RedissonIndex index = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonIndex.class);
                        if (index.indexOnSave()) {
                            prepareEnsuerIndex(id, r, instance, redissonBatch, index, e.toString(),
                                    pMap.get(e));
                        }
                    } else if (cls.getDeclaredField(e.toString())
                            .isAnnotationPresent(RedissonIndex.List.class)) {
                        RedissonIndex.List indexList = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonIndex.List.class);
                        Arrays.stream(indexList.value()).filter(f -> f.indexOnSave())
                                .forEach(index -> prepareEnsuerIndex(id, r, instance, redissonBatch, index,
                                        e.toString(), pMap.get(e)));
                    }
                    if (cls.getDeclaredField(e.toString()).isAnnotationPresent(RedissonCounter.class)) {
                        RedissonCounter counter = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonCounter.class);
                        prepareEnsuerCounter(id, r, instance, isNew, redissonBatch, counter, e.toString(),
                                pMap.get(e));
                    } else if (cls.getDeclaredField(e.toString())
                            .isAnnotationPresent(RedissonCounter.List.class)) {
                        RedissonCounter.List counterList = cls.getDeclaredField(e.toString())
                                .getAnnotation(RedissonCounter.List.class);
                        Arrays.stream(counterList.value()).forEach(index -> prepareEnsuerCounter(id, r,
                                instance, isNew, redissonBatch, index, e.toString(), pMap.get(e)));
                    }
                } catch (NoSuchFieldException ex) {
                    throw new RuntimeException(ex);
                }
            }
        });
    } catch (InstantiationException | IllegalAccessException | RuntimeException ex) {
        throw new RepositoryException(ex);
    }
}