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

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

Introduction

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

Prototype

public JsonObject() 

Source Link

Document

Create a new, empty instance

Usage

From source file:com.baldmountain.depot.models.Cart.java

License:Open Source License

public Cart save(MongoService mongoService, Handler<AsyncResult<String>> resultHandler) {
    JsonObject json = new JsonObject();
    if (!"0".equals(id)) {
        if (dirty) {
            setDates(json);//from  w  w w.ja v a  2 s.  com
            // update existing
            mongoService.replace(collection, new JsonObject().put("_id", id), json, (Void) -> {
                dirty = false;
                saveLineItems(mongoService, resultHandler);
            });
        } else {
            resultHandler.handle(new ConcreteAsyncResult<>(id));
        }
    } else {
        setDates(json);
        mongoService.save(collection, json, res -> {
            if (res.succeeded()) {
                this.id = res.result();
                dirty = false;
                saveLineItems(mongoService, resultHandler);
            } else {
                resultHandler.handle(new ConcreteAsyncResult<>(res.cause()));
            }
        });
    }
    return this;
}

From source file:com.baldmountain.depot.models.Cart.java

License:Open Source License

@Override
public BaseModel delete(MongoService service, Handler<AsyncResult<Void>> resultHandler) {
    assert !"0".equals(id);
    cache.remove(id);//  www  .  j  av  a  2  s .c  o m
    service.remove(collection, new JsonObject().put("_id", id), res -> {
        if (res.succeeded()) {
            id = "0";
            resultHandler.handle(new ConcreteAsyncResult<>((Void) null));
        } else {
            resultHandler.handle(new ConcreteAsyncResult<>(res.cause()));
        }
    });
    return this;
}

From source file:com.baldmountain.depot.models.LineItem.java

License:Open Source License

public LineItem save(MongoService service, Handler<AsyncResult<String>> resultHandler) {
    JsonObject json = new JsonObject().put("cart", cartId).put("product", productId).put("count", count);
    if (!"0".equals(id)) {
        // update existing
        if (dirty) {
            setDates(json);//from www . j  a  v a 2  s. c o m
            service.replace(collection, new JsonObject().put("_id", id), json,
                    (Void) -> resultHandler.handle(new ConcreteAsyncResult<>(id)));
        } else {
            resultHandler.handle(new ConcreteAsyncResult<>(id));
        }
    } else {
        setDates(json);
        service.save(collection, json, resultHandler);
    }
    return this;
}

From source file:com.baldmountain.depot.models.LineItem.java

License:Open Source License

public static void findForCart(MongoService service, String cart,
        Handler<AsyncResult<List<LineItem>>> resultHandler) {
    assert !"0".equals(cart);
    JsonObject query = new JsonObject().put("cart", cart);
    service.find("line_items", query, res -> {
        if (res.succeeded()) {
            List<LineItem> lineItems = res.result().stream().map(LineItem::new).collect(Collectors.toList());
            resultHandler.handle(new ConcreteAsyncResult<>(lineItems));
        } else {/*from  w ww. j a  v a 2  s .c  om*/
            resultHandler.handle(new ConcreteAsyncResult<>(res.cause()));
        }
    });
}

From source file:com.baldmountain.depot.models.Product.java

License:Open Source License

public Product save(MongoService service, Handler<AsyncResult<String>> resultHandler) {
    if (!"0".equals(id)) {
        // update existing
        if (dirty) {
            JsonObject json = new JsonObject().put("title", title).put("description", description)
                    .put("imageUrl", imageUrl).put("price", price.doubleValue());
            setDates(json);/* w ww  .  ja va 2s  .com*/
            service.replace("products", new JsonObject().put("_id", id), json,
                    (Void) -> resultHandler.handle(new ConcreteAsyncResult<>(id)));
        } else {
            resultHandler.handle(new ConcreteAsyncResult<>(id));
        }
    } else {
        JsonObject json = new JsonObject().put("title", title).put("description", description)
                .put("imageUrl", imageUrl).put("price", price.doubleValue());
        setDates(json);
        service.save("products", json, resultHandler);
    }
    return this;
}

From source file:com.baldmountain.depot.models.Product.java

License:Open Source License

public static void find(MongoService service, String id, Handler<AsyncResult<Product>> resultHandler) {
    assert !"0".equals(id);
    JsonObject query = new JsonObject().put("_id", id);
    service.findOne("products", query, null, res -> {
        if (res.succeeded()) {
            resultHandler.handle(new ConcreteAsyncResult<>(new Product(res.result())));
        } else {/* ww w.  ja v  a  2 s  . co m*/
            resultHandler.handle(new ConcreteAsyncResult<>(res.cause()));
        }
    });
}

From source file:com.baldmountain.depot.models.Product.java

License:Open Source License

public static void all(MongoService service, Handler<AsyncResult<List<Product>>> resultHandler) {
    service.find("products", new JsonObject(), res -> {
        if (res.succeeded()) {
            List<Product> products = res.result().stream().map(Product::new).collect(Collectors.toList());
            products.sort((p1, p2) -> p1.getTitle().compareTo(p2.getTitle()));
            resultHandler.handle(new ConcreteAsyncResult<>(products));
        } else {/*from   w w  w.  j av a 2  s  . c o  m*/
            resultHandler.handle(new ConcreteAsyncResult<>(res.cause()));
        }
    });
}

From source file:com.chibchasoft.vertx.verticle.deployment.DependentsDeployment.java

License:Open Source License

/**
 * Returns a JsonObject populated with the information from this object
 * @return The JsonObject//from  www  .ja  va 2s.c o  m
 */
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    if (this.getConfigurations() != null) {
        JsonArray array = new JsonArray();
        this.getConfigurations().forEach(item -> array.add(item.toJson()));
        json.put("configurations", array);
    }
    return json;
}

From source file:com.chibchasoft.vertx.verticle.deployment.DeploymentConfiguration.java

License:Open Source License

/**
 * Returns a JsonObject populated with the information from this object
 * @return The JsonObject//w  w  w. j a  v  a2  s . c om
 */
public JsonObject toJson() {
    JsonObject json = new JsonObject();
    json.put("name", name);
    if (deploymentOptions != null) {
        JsonObject depOptJson = new JsonObject();
        DeploymentOptionsConverter.toJson(deploymentOptions, depOptJson);
        json.put("deploymentOptions", depOptJson);
    }
    if (this.getDependents() != null) {
        JsonArray array = new JsonArray();
        this.getDependents().forEach(item -> array.add(item.toJson()));
        json.put("dependents", array);
    }
    return json;
}

From source file:com.cisco.ef.VertxMain.java

@Override
public void start() throws Exception {

    /* Vertx HTTP Server. */
    final io.vertx.core.http.HttpServer vertxHttpServer = this.getVertx().createHttpServer();

    /* Route one call to a vertx handler. */
    final Router router = createRouterAndVertxOnlyRoute();

    final HttpServer httpServer = getHttpServerAndRoutes(vertxHttpServer, router);

    systemManager = managedServiceBuilder.getSystemManager();

    managedServiceBuilder.addEndpointService(new EventHandleService());
    //        managedServiceBuilder.addEndpointService(new OauthService(vertx));

    /*//from w w  w .  j  a v  a2  s .c  o m
    * Create and start new service endpointServer.
    */
    managedServiceBuilder.getEndpointServerBuilder().setHttpServer(httpServer).build().startServer();

    /*
     * Associate the router as a request handler for the vertxHttpServer.
     */
    vertxHttpServer.requestHandler(router::accept).listen(managedServiceBuilder.getPort());

    logger.info("[Client Credential flow] started...");

    OAuth2Auth oauth2 = OAuth2Auth.create(vertx, OAuth2FlowType.CLIENT,
            new JsonObject().put("clientID", "f4f9ea5a8e2fe081f337")
                    .put("clientSecret", "df8aadec3990f219b9326b67a0c7506356d14215")
                    .put("site", "https://github.com/login").put("tokenPath", "/oauth/access_token")
                    .put("authorizationPath", "/oauth/authorize")

    );

    JsonObject tokenConfig = new JsonObject();

    // Callbacks
    // Save the access token
    oauth2.getToken(tokenConfig, res -> {
        if (res.failed()) {
            logger.info("[Access Token Error]: " + res.cause().getMessage());
        } else {
            // Get the access token object (the authorization code is given from the previous step).
            AccessToken token = res.result();
            logger.info("[Access Token SUCCESS]: principal => " + token.principal().encodePrettily());
            logger.info("[Access Token SUCCESS]: expired => " + token.expired());
        }
    });

    //        vertx.deployVerticle("com.cisco.ef.service.OauthService");
    vertx.deployVerticle("com.cisco.ef.service.ConsulService", new DeploymentOptions().setWorker(true));
    //        DsaService dsaService = new DsaService();
    //        dsaService.start();

}