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.common.storage.impl.GridfsStorage.java

License:Open Source License

@Override
public void copyFile(String id, Handler<JsonObject> handler) {
    JsonObject find = new JsonObject();
    find.put("action", "copy");
    find.put("query", new JsonObject("{ \"_id\": \"" + id + "\"}"));
    byte[] header = null;
    try {// w  ww . j  av a2s.c  o m
        header = find.toString().getBytes("UTF-8");
    } catch (UnsupportedEncodingException e) {
        handler.handle(new JsonObject().put("status", "error"));
    }
    if (header != null) {
        Buffer buf = Buffer.buffer(header);
        buf.appendInt(header.length);
        eb.send(gridfsAddress, buf, handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
            @Override
            public void handle(Message<JsonObject> res) {
                handler.handle(res.body());
            }
        }));
    }
}

From source file:org.entcore.common.storage.impl.GridfsStorage.java

License:Open Source License

@Override
public void writeToFileSystem(String[] ids, String destinationPath, JsonObject alias,
        final Handler<JsonObject> handler) {
    QueryBuilder q = QueryBuilder.start("_id").in(ids);
    JsonObject e = new JsonObject().put("action", "write").put("path", destinationPath).put("alias", alias)
            .put("query", MongoQueryBuilder.build(q));
    eb.send(gridfsAddress + ".json", e, handlerToAsyncHandler(new Handler<Message<JsonObject>>() {
        @Override// w  w  w .j  a  v  a  2 s. c o m
        public void handle(Message<JsonObject> event) {
            handler.handle(event.body());
        }
    }));
}

From source file:org.entcore.common.storage.impl.GridfsStorage.java

License:Open Source License

@Override
public void stats(final Handler<AsyncResult<BucketStats>> handler) {
    mongoDb.command(new JsonObject().put("collStats", bucket + ".chunks").encode(),
            new Handler<Message<JsonObject>>() {
                @Override/* w  ww.j  av  a  2s  .c o  m*/
                public void handle(Message<JsonObject> event) {
                    final JsonObject chunksStats = event.body().getJsonObject("result");
                    if ("ok".equals(event.body().getString("status")) && chunksStats != null) {
                        final BucketStats bucketStats = new BucketStats();
                        bucketStats.setStorageSize(chunksStats.getLong("size"));
                        mongoDb.command(new JsonObject().put("collStats", bucket + ".files").encode(),
                                new Handler<Message<JsonObject>>() {
                                    @Override
                                    public void handle(Message<JsonObject> event) {
                                        final JsonObject filesStats = event.body().getJsonObject("result");
                                        if ("ok".equals(event.body().getString("status"))
                                                && filesStats != null) {
                                            bucketStats.setObjectNumber(filesStats.getLong("count"));
                                            handler.handle(new DefaultAsyncResult<>(bucketStats));
                                        } else {
                                            handler.handle(new DefaultAsyncResult<BucketStats>(
                                                    new StorageException(event.body().getString("message"))));
                                        }
                                    }
                                });
                    } else {
                        handler.handle(new DefaultAsyncResult<BucketStats>(
                                new StorageException(event.body().getString("message"))));
                    }
                }
            });
}

From source file:org.entcore.common.storage.impl.MongoDBApplicationStorage.java

License:Open Source License

@Override
public void getInfo(final String fileId, final Handler<AsyncResult<FileInfos>> handler) {
    final JsonObject query = new JsonObject().put(mapping.getString("file", "file"), fileId);
    mongo.findOne(collection, query, keys, new Handler<Message<JsonObject>>() {
        @Override/*w  ww  . j a v a 2  s.c  o  m*/
        public void handle(Message<JsonObject> event) {
            if ("ok".equals(event.body().getString("status"))) {
                JsonObject res = event.body().getJsonObject("result");
                if (res != null) {
                    final FileInfos fi = new FileInfos();
                    fi.setApplication(application);
                    fi.setId(fileId);
                    fi.setName(res.getString(mapping.getString("title", "title")));
                    fi.setOwner(res.getString(mapping.getString("owner", "owner")));
                    handler.handle(new DefaultAsyncResult<>(fi));
                } else {
                    handler.handle(new DefaultAsyncResult<>((FileInfos) null));
                }
            } else {
                handler.handle(new DefaultAsyncResult<FileInfos>(
                        new StorageException(event.body().getString("message"))));
            }
        }
    });
}

From source file:org.entcore.common.storage.impl.MongoDBApplicationStorage.java

License:Open Source License

@Override
public void updateInfo(String fileId, FileInfos fileInfos, final Handler<AsyncResult<Integer>> handler) {
    final JsonObject query = new JsonObject().put(mapping.getString("file", "file"), fileId);
    final JsonObject modifier = new JsonObject().put("$set", fileInfos.toJsonExcludeEmpty(mapping));
    mongo.update(collection, query, modifier, new Handler<Message<JsonObject>>() {
        @Override// w  ww  . j  av a 2s.  com
        public void handle(Message<JsonObject> event) {
            if ("ok".equals(event.body().getString("status"))) {
                handler.handle(new DefaultAsyncResult<>(event.body().getInteger("number")));
            } else {
                handler.handle(new DefaultAsyncResult<Integer>(
                        new StorageException(event.body().getString("message"))));
            }
        }
    });
}

From source file:org.entcore.common.storage.impl.PostgresqlApplicationStorage.java

License:Open Source License

@Override
public void updateInfo(String fileId, FileInfos fileInfos, final Handler<AsyncResult<Integer>> handler) {
    JsonArray params = new fr.wseduc.webutils.collections.JsonArray();
    final String query = "update " + table + " set "
            + generateColumns(fileInfos.toJsonExcludeEmpty(mapping), params) + "where "
            + mapping.getString("id", "id") + " = ?;";
    params.add(fileId);/*from w  w  w  . ja v  a  2 s.co m*/
    sql.prepared(query, params, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> event) {
            Integer count = event.body().getInteger("rows");
            if (count != null) {
                handler.handle(new DefaultAsyncResult<>(count));
            } else {
                handler.handle(new DefaultAsyncResult<Integer>(
                        new StorageException(event.body().getString("message"))));
            }
        }
    });
}

From source file:org.entcore.common.user.RepositoryHandler.java

License:Open Source License

@Override
public void handle(Message<JsonObject> message) {
    String action = message.body().getString("action", "");
    switch (action) {
    case "export":
        final String exportId = message.body().getString("exportId", "");
        String userId = message.body().getString("userId", "");
        String path = message.body().getString("path", "");
        final String locale = message.body().getString("locale", "fr");
        final String host = message.body().getString("host", "");
        JsonArray groupIds = message.body().getJsonArray("groups",
                new fr.wseduc.webutils.collections.JsonArray());
        repositoryEvents.exportResources(exportId, userId, groupIds, path, locale, host,
                new Handler<Boolean>() {
                    @Override//from   w  w  w  .  j ava 2  s .  c  om
                    public void handle(Boolean isExported) {
                        JsonObject exported = new JsonObject().put("action", "exported")
                                .put("status", (isExported ? "ok" : "error")).put("exportId", exportId)
                                .put("locale", locale).put("host", host);
                        eb.publish("entcore.export", exported);
                    }
                });
        break;
    case "delete-groups":
        JsonArray groups = message.body().getJsonArray("old-groups",
                new fr.wseduc.webutils.collections.JsonArray());
        repositoryEvents.deleteGroups(groups);
        break;
    case "delete-users":
        JsonArray users = message.body().getJsonArray("old-users",
                new fr.wseduc.webutils.collections.JsonArray());
        repositoryEvents.deleteUsers(users);
        break;
    case "users-classes-update":
        JsonArray updates = message.body().getJsonArray("users-classes-update",
                new fr.wseduc.webutils.collections.JsonArray());
        repositoryEvents.usersClassesUpdated(updates);
        break;
    case "transition":
        JsonObject structure = message.body().getJsonObject("structure");
        repositoryEvents.transition(structure);
        break;
    case "merge-users":
        JsonObject body = message.body();
        repositoryEvents.mergeUsers(body.getString("keepedUserId"), body.getString("deletedUserId"));
        break;
    default:
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.action"));
    }
}

From source file:org.entcore.common.user.UserUtils.java

License:Open Source License

public static void deleteCacheSession(EventBus eb, String userId, final Handler<Boolean> handler) {
    JsonObject json = new JsonObject().put("action", "dropCacheSession").put("userId", userId);
    eb.send(SESSION_ADDRESS, json, handlerToAsyncHandler(new Handler<Message<JsonObject>>() {

        @Override//from   w  w w  . j ava 2s . co  m
        public void handle(Message<JsonObject> res) {
            if (handler != null) {
                handler.handle("ok".equals(res.body().getString("status")));
            }
        }
    }));
}

From source file:org.entcore.communication.controllers.CommunicationController.java

License:Open Source License

@BusAddress("wse.communication.users")
public void visibleUsers(final Message<JsonObject> message) {
    String userId = message.body().getString("userId");
    if (userId != null && !userId.trim().isEmpty()) {
        String action = message.body().getString("action", "");
        String schoolId = message.body().getString("schoolId");
        JsonArray expectedTypes = message.body().getJsonArray("expectedTypes");
        Handler<Either<String, JsonArray>> responseHandler = new Handler<Either<String, JsonArray>>() {

            @Override/* www. j a v  a 2 s .  c  o m*/
            public void handle(Either<String, JsonArray> res) {
                JsonArray j;
                if (res.isRight()) {
                    j = res.right().getValue();
                } else {
                    log.warn(res.left().getValue());
                    j = new fr.wseduc.webutils.collections.JsonArray();
                }
                message.reply(j);
            }
        };
        switch (action) {
        case "visibleUsers":
            String preFilter = message.body().getString("preFilter");
            String customReturn = message.body().getString("customReturn");
            JsonObject ap = message.body().getJsonObject("additionnalParams");
            boolean itSelf = message.body().getBoolean("itself", false);
            boolean myGroup = message.body().getBoolean("mygroup", false);
            boolean profile = message.body().getBoolean("profile", true);
            communicationService.visibleUsers(userId, schoolId, expectedTypes, itSelf, myGroup, profile,
                    preFilter, customReturn, ap, responseHandler);
            break;
        case "usersCanSeeMe":
            communicationService.usersCanSeeMe(userId, responseHandler);
            break;
        case "visibleProfilsGroups":
            String pF = message.body().getString("preFilter");
            String c = message.body().getString("customReturn");
            JsonObject p = message.body().getJsonObject("additionnalParams");
            communicationService.visibleProfilsGroups(userId, c, p, pF, responseHandler);
            break;
        case "visibleManualGroups":
            String cr = message.body().getString("customReturn");
            JsonObject pa = message.body().getJsonObject("additionnalParams");
            communicationService.visibleManualGroups(userId, cr, pa, responseHandler);
            break;
        default:
            message.reply(new fr.wseduc.webutils.collections.JsonArray());
            break;
        }
    } else {
        message.reply(new fr.wseduc.webutils.collections.JsonArray());
    }
}

From source file:org.entcore.communication.controllers.CommunicationController.java

License:Open Source License

@BusAddress("wse.communication")
public void communicationEventBusHandler(final Message<JsonObject> message) {
    JsonObject initDefaultRules = config.getJsonObject("initDefaultCommunicationRules");
    final Handler<Either<String, JsonObject>> responseHandler = new Handler<Either<String, JsonObject>>() {

        @Override/*from   w ww.j  a v a2 s  . c o m*/
        public void handle(Either<String, JsonObject> res) {
            if (res.isRight()) {
                message.reply(res.right().getValue());
            } else {
                message.reply(new JsonObject().put("status", "error").put("message", res.left().getValue()));
            }
        }
    };
    switch (message.body().getString("action", "")) {
    case "initDefaultCommunicationRules":
        communicationService.initDefaultRules(message.body().getJsonArray("schoolIds"), initDefaultRules,
                responseHandler);
        break;
    case "initAndApplyDefaultCommunicationRules":
        communicationService.initDefaultRules(message.body().getJsonArray("schoolIds"), initDefaultRules,
                new Handler<Either<String, JsonObject>>() {
                    @Override
                    public void handle(Either<String, JsonObject> event) {
                        if (event.isRight()) {
                            communicationService.applyDefaultRules(message.body().getJsonArray("schoolIds"),
                                    responseHandler);
                        } else {
                            message.reply(new JsonObject().put("status", "error").put("message",
                                    event.left().getValue()));
                        }
                    }
                });
        break;
    case "setDefaultCommunicationRules":
        communicationService.applyDefaultRules(
                new fr.wseduc.webutils.collections.JsonArray().add(message.body().getString("schoolId")),
                responseHandler);
        break;
    case "setMultipleDefaultCommunicationRules":
        communicationService.applyDefaultRules(message.body().getJsonArray("schoolIds"), responseHandler);
        break;
    case "setCommunicationRules":
        communicationService.applyRules(message.body().getString("groupId"), responseHandler);
        break;
    default:
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.action"));
    }
}