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

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

Introduction

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

Prototype

public JsonObject putNull(String key) 

Source Link

Document

Put a null value into the JSON object with the specified key.

Usage

From source file:com.groupon.vertx.redis.RedisCommandHandler.java

License:Apache License

private JsonObject buildReply(String status, JsonObject data, String message) {
    JsonObject reply = new JsonObject();

    reply.put("status", status);

    if ("success".equals(status) || data != null) {
        reply.putNull("data");
    } else {//from   w  ww . jav  a 2 s.  c  o  m
        reply.put("message", message);
    }

    return reply;
}

From source file:org.entcore.feeder.timetable.AbstractTimetableImporter.java

License:Open Source License

public static void initStructure(final EventBus eb, final Message<JsonObject> message) {
    final JsonObject conf = message.body().getJsonObject("conf");
    if (conf == null) {
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.conf"));
        return;/*from  w w  w .j a  va 2  s .c o  m*/
    }
    final String query = "MATCH (s:Structure {id:{structureId}}) "
            + "RETURN (NOT(HAS(s.timetable)) OR s.timetable <> {type}) as update ";
    TransactionManager.getNeo4jHelper().execute(query, conf, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(final Message<JsonObject> event) {
            final JsonArray j = event.body().getJsonArray("result");
            if ("ok".equals(event.body().getString("status")) && j != null && j.size() == 1
                    && j.getJsonObject(0).getBoolean("update", false)) {
                try {
                    TransactionHelper tx = TransactionManager.getTransaction();
                    final String q1 = "MATCH (s:Structure {id : {structureId}})<-[:DEPENDS]-(fg:FunctionalGroup) "
                            + "WHERE NOT(HAS(s.timetable)) OR s.timetable <> {type} "
                            + "OPTIONAL MATCH fg<-[:IN]-(u:User) "
                            + "RETURN fg.id as group, fg.name as groupName, collect(u.id) as users ";
                    final String q2 = "MATCH (s:Structure {id: {structureId}}) "
                            + "WHERE NOT(HAS(s.timetable)) OR s.timetable <> {type} "
                            + "SET s.timetable = {typeUpdate} " + "WITH s "
                            + "MATCH s<-[:DEPENDS]-(fg:FunctionalGroup), s<-[:SUBJECT]-(sub:Subject) "
                            + "DETACH DELETE fg, sub ";
                    final String q3 = "MATCH (s:Structure {id: {structureId}})<-[:MAPPING]-(cm:ClassesMapping) "
                            + "DETACH DELETE cm";
                    tx.add(q1, conf);
                    tx.add(q2, (isEmpty(conf.getString("type")) ? conf.putNull("typeUpdate")
                            : conf.put("typeUpdate", conf.getString("type"))));
                    tx.add(q3, conf);
                    tx.commit(new Handler<Message<JsonObject>>() {
                        @Override
                        public void handle(Message<JsonObject> res) {
                            if ("ok".equals(res.body().getString("status"))) {
                                final JsonArray r = res.body().getJsonArray("results");
                                if (r != null && r.size() == 2) {
                                    Transition.publishDeleteGroups(eb, log, r.getJsonArray(0));
                                }
                                final JsonObject matcher = new JsonObject().put("structureId",
                                        conf.getString("structureId"));
                                MongoDb.getInstance().delete(COURSES, matcher,
                                        new Handler<Message<JsonObject>>() {
                                            @Override
                                            public void handle(Message<JsonObject> mongoResult) {
                                                if (!"ok".equals(mongoResult.body().getString("status"))) {
                                                    log.error("Error deleting courses : "
                                                            + mongoResult.body().getString("message"));
                                                }
                                                message.reply(event.body());
                                            }
                                        });
                            } else {
                                message.reply(res.body());
                            }
                        }
                    });
                } catch (TransactionException e) {
                    log.error("Transaction error when init timetable structure", e);
                    message.reply(new JsonObject().put("status", "error").put("message", e.getMessage()));
                }
            } else {
                message.reply(event.body());
            }
        }
    });
}