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

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

Introduction

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

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

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

License:Apache License

public void updateUserLocation(String userId, double latitude, double longitude, String country,
        Handler<AsyncResult<Void>> handler) {
    if (closed) {
        handler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//w w  w.  j  a  v a  2 s . c  o  m
    }
    JsonObject _json = new JsonObject();
    _json.put("userId", userId);
    _json.put("latitude", latitude);
    _json.put("longitude", longitude);
    _json.put("country", country);
    DeliveryOptions _deliveryOptions = (_options != null) ? new DeliveryOptions(_options)
            : new DeliveryOptions();
    _deliveryOptions.addHeader("action", "updateUserLocation");
    _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            handler.handle(Future.failedFuture(res.cause()));
        } else {
            handler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java

License:Open Source License

public static void ask(HttpServerResponse httpServerResponse, String conversationToken, String initialPrompt,
        String[] noInputPrompts) {

    httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8");
    httpServerResponse.putHeader("Google-Assistant-API-Version", "v1");

    JsonObject responseJSON = new JsonObject();

    if (conversationToken != null) {
        responseJSON.put("conversation_token", conversationToken);
    }//  w ww  .jav  a  2  s. com

    responseJSON.put("expect_user_response", true);
    responseJSON.put("expected_inputs",
            JsonUtil.getArray(_getExpectedInputJSON(initialPrompt, noInputPrompts)));

    httpServerResponse.end(responseJSON.encode());
}

From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java

License:Open Source License

public static void tell(HttpServerResponse httpServerResponse, String textToSpeech) {

    httpServerResponse.putHeader(HttpHeaders.CONTENT_TYPE, "application/json; charset=utf-8");
    httpServerResponse.putHeader("Google-Assistant-API-Version", "v1");

    JsonObject responseJSON = new JsonObject();

    JsonObject finalResponseJSON = new JsonObject();

    finalResponseJSON.put("speech_response", _getPromptJSON(textToSpeech));

    responseJSON.put("final_response", finalResponseJSON);

    httpServerResponse.end(responseJSON.encode());
}

From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java

License:Open Source License

private static JsonObject _getExpectedInputJSON(String initialPrompt, String[] noInputPrompts) {

    JsonObject expectedInputJSON = new JsonObject();

    JsonObject inputPromptJSON = new JsonObject();

    inputPromptJSON.put("initial_prompts", JsonUtil.getArray(_getPromptJSON(initialPrompt)));

    if (noInputPrompts.length > 0) {
        JsonArray noInputPromptsJSON = new JsonArray();

        for (String noInputPrompt : noInputPrompts) {
            noInputPromptsJSON.add(_getPromptJSON(noInputPrompt));
        }//from   www .  j av  a2 s .  co m

        inputPromptJSON.put("no_input_prompts", noInputPromptsJSON);
    }

    expectedInputJSON.put("input_prompt", inputPromptJSON);

    expectedInputJSON.put("possible_intents", _getPossibleIntentsJSON(INTENT_TEXT));

    return expectedInputJSON;
}

From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java

License:Open Source License

private static JsonArray _getPossibleIntentsJSON(String intent) {
    JsonObject jsonObject = new JsonObject();

    jsonObject.put("intent", intent);

    return JsonUtil.getArray(jsonObject);
}

From source file:com.github.ithildir.numbers.game.util.ConversationUtil.java

License:Open Source License

private static JsonObject _getPromptJSON(String textToSpeech) {
    JsonObject jsonObject = new JsonObject();

    jsonObject.put("text_to_speech", textToSpeech);

    return jsonObject;
}

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

License:Apache License

private void createWithoutValidate(JsonObject data, RBatch redissonBatch,
        AsyncResultHandler<String> resultHandler) {
    AtomicReference<String> id = new AtomicReference<>();
    Async.waterfall().<String>task(this::newId).<String>task((i, t) -> {
        id.set(i);/* ww w.  ja v a 2 s  . c om*/
        ensureUniqueAndIndexing(id.get(), data, true, rs -> {
            if (rs.succeeded() && rs.result() == null) {
                t.handle(Future.succeededFuture());
            } else if (rs.result() != null) {
                t.handle(Future.failedFuture(new RepositoryException(rs.result())));
            } else {
                t.handle(Future.failedFuture(rs.cause()));
            }
        });
    }).<Boolean>task((rs, t) -> {
        persist(id.get(), data.put("id", id.get()), redissonBatch, t);
    }).run(run -> {
        resultHandler
                .handle(run.succeeded() ? Future.succeededFuture(id.get()) : Future.failedFuture(run.cause()));
    });
}

From source file:com.github.mcollovati.vertx.vaadin.VaadinVerticle.java

License:Open Source License

@Override
public void start(Future<Void> startFuture) throws Exception {
    log.info("Starting vaadin verticle " + getClass().getName());

    VaadinVerticleConfiguration vaadinVerticleConfiguration = getClass()
            .getAnnotation(VaadinVerticleConfiguration.class);

    JsonObject vaadinConfig = new JsonObject();
    vaadinConfig.put("serviceName", this.deploymentID());
    vaadinConfig.put("mountPoint", Optional.ofNullable(vaadinVerticleConfiguration)
            .map(VaadinVerticleConfiguration::mountPoint).orElse("/"));
    readUiFromEnclosingClass(vaadinConfig);
    readConfigurationAnnotation(vaadinConfig);
    vaadinConfig.mergeIn(config().getJsonObject("vaadin", new JsonObject()));

    String mountPoint = vaadinConfig.getString("mountPoint");
    VertxVaadin vertxVaadin = createVertxVaadin(vaadinConfig);
    vaadinService = vertxVaadin.vaadinService();

    HttpServerOptions serverOptions = new HttpServerOptions().setCompressionSupported(true);
    httpServer = vertx.createHttpServer(serverOptions);

    Router router = Router.router(vertx);
    router.mountSubRouter(mountPoint, vertxVaadin.router());

    httpServer.websocketHandler(vertxVaadin.webSocketHandler());
    httpServer.requestHandler(router::accept).listen(config().getInteger("httpPort", 8080));

    serviceInitialized(vaadinService, router);

    log.info("Started vaadin verticle " + getClass().getName());
    startFuture.complete();//ww w  .  j ava 2 s .c  om
}

From source file:com.github.mcollovati.vertx.vaadin.VaadinVerticle.java

License:Open Source License

private void readUiFromEnclosingClass(JsonObject vaadinConfig) {
    Class<?> enclosingClass = getClass().getEnclosingClass();

    if (enclosingClass != null && UI.class.isAssignableFrom(enclosingClass)) {
        vaadinConfig.put(VaadinSession.UI_PARAMETER, enclosingClass.getName());
    }/*from   ww  w  .  j a v a2s  .c o m*/
}

From source file:com.github.mcollovati.vertx.vaadin.VaadinVerticle.java

License:Open Source License

private void readConfigurationAnnotation(JsonObject vaadinConfig) {

    VaadinServletConfiguration configAnnotation = getClass().getAnnotation(VaadinServletConfiguration.class);
    if (configAnnotation != null) {
        Method[] methods = VaadinServletConfiguration.class.getDeclaredMethods();
        for (Method method : methods) {
            VaadinServletConfiguration.InitParameterName name = method
                    .getAnnotation(VaadinServletConfiguration.InitParameterName.class);
            assert name != null : "All methods declared in VaadinServletConfiguration should have a @InitParameterName annotation";

            try {
                Object value = method.invoke(configAnnotation);

                String stringValue;
                if (value instanceof Class<?>) {
                    stringValue = ((Class<?>) value).getName();
                } else {
                    stringValue = value.toString();
                }// w w w.  j av  a  2s.c  om

                vaadinConfig.put(name.value(), stringValue);
            } catch (Exception e) {
                // This should never happen
                throw new VertxException("Could not read @VaadinServletConfiguration value " + method.getName(),
                        e);
            }
        }
    }
}