Example usage for io.vertx.core.eventbus Message body

List of usage examples for io.vertx.core.eventbus Message body

Introduction

In this page you can find the example usage for io.vertx.core.eventbus Message body.

Prototype

@CacheReturn
T body();

Source Link

Document

The body of the message.

Usage

From source file:org.entcore.communication.filters.CommunicationFilter.java

License:Open Source License

private void check(String query, JsonObject params, final Handler<Boolean> handler) {
    neo4j.execute(query, params, new Handler<Message<JsonObject>>() {
        @Override//from   w w  w  .  j  a  va 2s .c  o  m
        public void handle(Message<JsonObject> event) {
            JsonArray r = event.body().getJsonArray("result");
            handler.handle("ok".equals(event.body().getString("status")) && r != null && r.size() == 1
                    && (r.getJsonObject(0)).getBoolean("exists", false));
        }
    });
}

From source file:org.entcore.communication.services.impl.DefaultCommunicationService.java

License:Open Source License

@Override
public void initDefaultRules(JsonArray structureIds, JsonObject defaultRules,
        final Handler<Either<String, JsonObject>> handler) {
    final StatementsBuilder s1 = new StatementsBuilder();
    final StatementsBuilder s2 = new StatementsBuilder();
    final StatementsBuilder s3 = new StatementsBuilder();
    s3.add("MATCH (s:Structure)<-[:DEPENDS*1..2]-(g:ProfileGroup) " + "WHERE NOT(HAS(g.communiqueWith)) "
            + "SET g.communiqueWith = [] ")
            .add("MATCH (fg:FunctionGroup) " + "WHERE fg.name ENDS WITH 'AdminLocal' "
                    + "SET fg.users = 'BOTH' ")
            .add("MATCH (ag:FunctionalGroup) " + "SET ag.users = 'BOTH' ");
    for (String attr : defaultRules.fieldNames()) {
        initDefaultRules(structureIds, attr, defaultRules.getJsonObject(attr), s1, s2);
    }/* ww  w . j  av a2s.c  o m*/
    neo4j.executeTransaction(s1.build(), null, false, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> event) {
            if ("ok".equals(event.body().getString("status"))) {
                Integer transactionId = event.body().getInteger("transactionId");
                neo4j.executeTransaction(s2.build(), transactionId, false, new Handler<Message<JsonObject>>() {
                    @Override
                    public void handle(Message<JsonObject> event) {
                        if ("ok".equals(event.body().getString("status"))) {
                            Integer transactionId = event.body().getInteger("transactionId");
                            neo4j.executeTransaction(s3.build(), transactionId, true,
                                    new Handler<Message<JsonObject>>() {
                                        @Override
                                        public void handle(Message<JsonObject> message) {
                                            if ("ok".equals(message.body().getString("status"))) {
                                                handler.handle(
                                                        new Either.Right<String, JsonObject>(new JsonObject()));
                                                log.info("Default communication rules initialized.");
                                            } else {
                                                handler.handle(new Either.Left<String, JsonObject>(
                                                        message.body().getString("message")));
                                                log.error("Error init default com rules : "
                                                        + message.body().getString("message"));
                                            }
                                        }
                                    });
                        } else {
                            handler.handle(
                                    new Either.Left<String, JsonObject>(event.body().getString("message")));
                            log.error("Error init default com rules : " + event.body().getString("message"));
                        }
                    }
                });
            } else {
                handler.handle(new Either.Left<String, JsonObject>(event.body().getString("message")));
                log.error("Error init default com rules : " + event.body().getString("message"));
            }
        }
    });
}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

@BusAddress("org.entcore.conversation")
public void conversationEventBusHandler(Message<JsonObject> message) {
    switch (message.body().getString("action", "")) {
    case "send":
        send(message);/* w  w  w  . java2 s .c om*/
        break;
    default:
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.action"));
    }
}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

private void send(final Message<JsonObject> message) {
    JsonObject m = message.body().getJsonObject("message");
    if (m == null) {
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.message"));
    }/*  w w w .  ja v a  2 s .  com*/
    final HttpServerRequest request = new JsonHttpServerRequest(
            message.body().getJsonObject("request", new JsonObject()));
    final UserInfos user = new UserInfos();
    user.setUserId(message.body().getString("userId"));
    user.setUsername(message.body().getString("username"));
    if (!m.containsKey("from")) {
        m.put("from", user.getUserId());
    }
    neoConversationService.addDisplayNames(m, null, new Handler<JsonObject>() {
        public void handle(final JsonObject m) {
            saveAndSend(null, m, user, null, null, new Handler<Either<String, JsonObject>>() {
                @Override
                public void handle(Either<String, JsonObject> event) {
                    if (event.isRight()) {
                        JsonObject result = event.right().getValue();
                        JsonObject timelineParams = new JsonObject().put("subject", result.getString("subject"))
                                .put("id", result.getString("id")).put("sentIds", m.getJsonArray("allUsers",
                                        new fr.wseduc.webutils.collections.JsonArray()));
                        timelineNotification(request, timelineParams, user);
                        JsonObject s = new JsonObject().put("status", "ok").put("result",
                                new fr.wseduc.webutils.collections.JsonArray().add(new JsonObject()));
                        message.reply(s);
                    } else {
                        JsonObject error = new JsonObject().put("error", event.left().getValue());
                        message.reply(error);
                    }
                }
            });
        }
    });

}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

private void getUserQuota(String userId, final Handler<JsonObject> handler) {
    JsonObject message = new JsonObject();
    message.put("action", "getUserQuota");
    message.put("userId", userId);

    eb.send(QUOTA_BUS_ADDRESS, message, handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> reply) {
            handler.handle(reply.body());
        }//www  .  j  a va  2 s.co  m
    }));
}

From source file:org.entcore.conversation.controllers.ConversationController.java

License:Open Source License

private void updateUserQuota(final String userId, long size, final Handler<Void> continuation) {
    JsonObject message = new JsonObject();
    message.put("action", "updateUserQuota");
    message.put("userId", userId);
    message.put("size", size);
    message.put("threshold", threshold);

    eb.send(QUOTA_BUS_ADDRESS, message, handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> reply) {
            JsonObject obj = reply.body();
            UserUtils.addSessionAttribute(eb, userId, "storage", obj.getLong("storage"), null);
            if (obj.getBoolean("notify", false)) {
                notifyEmptySpaceIsSmall(userId);
            }/*from www  .  ja  v  a 2  s  .c  om*/

            if (continuation != null)
                continuation.handle(null);
        }
    }));
}

From source file:org.entcore.conversation.service.impl.ConversationRepositoryEvents.java

License:Open Source License

@Override
public void deleteGroups(JsonArray groups) {
    SqlStatementsBuilder builder = new SqlStatementsBuilder();

    String setTO = "UPDATE conversation.messages " + "SET " + "\"to\" = \"to\" - ?, "
            + "\"toName\" = COALESCE(\"toName\", '[]')::jsonb || (?)::jsonb, "
            + "\"displayNames\" = \"displayNames\" - (? || '$ $' || ? || '$ ') - (? || '$ $' || ? || '$' || ?) "
            + "WHERE \"to\" @> (?)::jsonb";

    String setCC = "UPDATE conversation.messages " + "SET " + "\"cc\" = \"cc\" - ?, "
            + "\"ccName\" = COALESCE(\"ccName\", '[]')::jsonb || (?)::jsonb, "
            + "\"displayNames\" = \"displayNames\" - (? || '$ $' || ? || '$ ') - (? || '$ $' || ? || '$' || ?) "
            + "WHERE \"cc\" @> (?)::jsonb";

    for (Object o : groups) {
        if (!(o instanceof JsonObject))
            continue;
        JsonObject group = (JsonObject) o;

        JsonArray params = new fr.wseduc.webutils.collections.JsonArray();

        params.add(group.getString("group", ""));
        params.add(new fr.wseduc.webutils.collections.JsonArray().add(group.getString("groupName", ""))
                .toString());//from w  w w  .  j  av a  2s.c o m
        params.add(group.getString("group", ""));
        params.add(group.getString("groupName", ""));
        params.add(group.getString("group", ""));
        params.add(group.getString("groupName", ""));
        params.add(group.getString("groupName", ""));
        params.add(new fr.wseduc.webutils.collections.JsonArray().add(group.getString("group", "")).toString());

        builder.prepared(setTO, params);
        builder.prepared(setCC, params);
    }
    sql.transaction(builder.build(), new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> event) {
            if (!"ok".equals(event.body().getString("status"))) {
                log.error("Error updating delete groups in conversation : " + event.body().encode());
            }
        }
    });
}

From source file:org.entcore.conversation.service.impl.DefaultConversationService.java

License:Open Source License

private void addDisplayNames(final JsonObject message, final Handler<JsonObject> handler) {
    String query = "MATCH (v:Visible) " + "WHERE v.id IN {ids} "
            + "RETURN COLLECT(distinct (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' '))) as displayNames ";
    Set<String> ids = new HashSet<>();
    ids.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
    ids.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
    if (message.containsKey("from")) {
        ids.add(message.getString("from"));
    }/*from   w  w w  . j  a va2 s  .  c om*/
    neo.execute(query,
            new JsonObject().put("ids", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ids))),
            new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> m) {
                    JsonArray r = m.body().getJsonArray("result");
                    if ("ok".equals(m.body().getString("status")) && r != null && r.size() == 1) {
                        JsonObject j = r.getJsonObject(0);
                        JsonArray d = j.getJsonArray("displayNames");
                        if (d != null && d.size() > 0) {
                            message.put("displayNames", d);
                        }
                    }
                    handler.handle(message);
                }
            });
}

From source file:org.entcore.conversation.service.impl.Neo4jConversationService.java

License:Open Source License

public void addDisplayNames(final JsonObject message, final JsonObject parentMessage,
        final Handler<JsonObject> handler) {
    if (!displayNamesCondition(message)) {
        handler.handle(message);/*from w  w  w  .  j  a v a 2  s. co m*/
        return;
    }

    String query = "MATCH (v:Visible) " + "WHERE v.id IN {ids} "
            + "RETURN COLLECT(distinct (v.id + '$' + coalesce(v.displayName, ' ') + '$' + "
            + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' '))) as displayNames ";

    Set<String> ids = new HashSet<>();
    ids.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
    ids.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
    if (message.containsKey("from")) {
        ids.add(message.getString("from"));
    }
    if (parentMessage != null) {
        ids.addAll(parentMessage.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
        ids.addAll(parentMessage.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());
        if (parentMessage.containsKey("from"))
            ids.add(parentMessage.getString("from"));
    }
    neo.execute(query,
            new JsonObject().put("ids", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(ids))),
            new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> m) {
                    JsonArray r = m.body().getJsonArray("result");
                    if ("ok".equals(m.body().getString("status")) && r != null && r.size() == 1) {
                        JsonObject j = r.getJsonObject(0);
                        JsonArray d = j.getJsonArray("displayNames");
                        if (d != null && d.size() > 0) {
                            message.put("displayNames", d);
                        }
                    }
                    handler.handle(message);
                }
            });
}

From source file:org.entcore.conversation.service.impl.Neo4jConversationService.java

License:Open Source License

public void findInactives(final JsonObject message, long size, final Handler<JsonObject> handler) {
    Set<Object> dest = new HashSet<>();
    dest.addAll(message.getJsonArray("to", new fr.wseduc.webutils.collections.JsonArray()).getList());
    dest.addAll(message.getJsonArray("cc", new fr.wseduc.webutils.collections.JsonArray()).getList());

    JsonObject params = new JsonObject().put("dest",
            new fr.wseduc.webutils.collections.JsonArray(new ArrayList<Object>(dest)));

    String returnClause = "";
    if (size > 0) {
        returnClause = "RETURN "
                + "[t IN targets WHERE t.quotaLeft IS NULL OR t.quotaLeft < {attachmentsSize} | t.users.displayName] as undelivered, "
                + "[t IN targets WHERE t.quotaLeft IS NOT NULL AND t.quotaLeft >= {attachmentsSize} | t.users.id] as userTargets ";
        params.put("attachmentsSize", size);
    } else {/*from w  ww .j  ava  2  s . c  o m*/
        returnClause = "RETURN "
                + "[t IN targets WHERE t.users.activationCode IS NOT NULL | t.users.displayName] as inactives, "
                + "EXTRACT(t IN targets | t.users.id) as userTargets ";
    }

    String query = "MATCH (v:Visible)<-[:IN*0..1]-(u:User) " + "WHERE v.id IN {dest} "
            + "OPTIONAL MATCH (u)-[:USERBOOK]->(ub:UserBook) "
            + "WITH COLLECT(DISTINCT {users: u, quotaLeft: (ub.quota - ub.storage)}) as targets "
            + returnClause;

    neo.execute(query, params, new Handler<Message<JsonObject>>() {
        public void handle(Message<JsonObject> event) {
            JsonArray r = event.body().getJsonArray("result");

            JsonObject formattedResult = new JsonObject()
                    .put("inactives", new fr.wseduc.webutils.collections.JsonArray())
                    .put("actives", new fr.wseduc.webutils.collections.JsonArray())
                    .put("allUsers", new fr.wseduc.webutils.collections.JsonArray());

            if ("ok".equals(event.body().getString("status")) && r != null && r.size() == 1) {
                JsonObject j = r.getJsonObject(0);
                formattedResult.put("inactives",
                        j.getJsonArray("inactives", new fr.wseduc.webutils.collections.JsonArray()));
                formattedResult.put("undelivered",
                        j.getJsonArray("undelivered", new fr.wseduc.webutils.collections.JsonArray()));
                formattedResult.put("allUsers",
                        j.getJsonArray("userTargets", new fr.wseduc.webutils.collections.JsonArray()));
            }

            handler.handle(formattedResult);
        }
    });
}