List of usage examples for io.vertx.core.eventbus Message reply
default void reply(@Nullable Object message)
From source file:org.entcore.common.bus.BusResponseHandler.java
License:Open Source License
public static Handler<Either<String, JsonObject>> busResponseHandler(final Message<JsonObject> message) { return new Handler<Either<String, JsonObject>>() { @Override/*from w w w.j ava2 s . c o m*/ public void handle(Either<String, JsonObject> event) { if (event.isRight()) { message.reply(new JsonObject().put("status", "ok").put("result", event.right().getValue())); } else { JsonObject error = new JsonObject().put("status", "error").put("message", event.left().getValue()); message.reply(error); } } }; }
From source file:org.entcore.common.bus.BusResponseHandler.java
License:Open Source License
public static Handler<Either<String, JsonArray>> busArrayHandler(final Message<JsonObject> message) { return new Handler<Either<String, JsonArray>>() { @Override/*from w ww . j a v a 2s.co m*/ public void handle(Either<String, JsonArray> event) { if (event.isRight()) { message.reply(new JsonObject().put("status", "ok").put("result", event.right().getValue())); } else { JsonObject error = new JsonObject().put("status", "error").put("message", event.left().getValue()); message.reply(error); } } }; }
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 a v a 2 s. co m 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.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//from ww w . j a va 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 w w . ja va2 s .co 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")); } }
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);/*from ww w. j ava 2 s. co m*/ 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")); }//from w w w .j a va 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.directory.controllers.DirectoryController.java
License:Open Source License
@BusAddress("directory") public void directoryHandler(final Message<JsonObject> message) { String action = message.body().getString("action", ""); String userId = message.body().getString("userId"); switch (action) { case "usersInProfilGroup": boolean itSelf2 = message.body().getBoolean("itself", false); String excludeUserId = message.body().getString("excludeUserId"); userService.list(userId, itSelf2, excludeUserId, responseHandler(message)); break;//from w w w. j av a 2 s. com case "getUser": userService.get(userId, false, BusResponseHandler.busResponseHandler(message)); break; case "getUserInfos": userService.getInfos(userId, BusResponseHandler.busResponseHandler(message)); break; case "list-users": JsonArray userIds = message.body().getJsonArray("userIds", new fr.wseduc.webutils.collections.JsonArray()); JsonArray groupIds = message.body().getJsonArray("groupIds", new fr.wseduc.webutils.collections.JsonArray()); boolean itSelf = message.body().getBoolean("itself", false); String excludeId = message.body().getString("excludeUserId"); userService.list(groupIds, userIds, itSelf, excludeId, busArrayHandler(message)); break; case "list-structures": schoolService.list(message.body().getJsonArray("fields"), busArrayHandler(message)); break; case "list-groups": String structureId = message.body().getString("structureId"); String type = message.body().getString("type"); boolean subGroups = message.body().getBoolean("subGroups", false); groupService.list(structureId, type, subGroups, busArrayHandler(message)); break; case "list-adml": String sId = message.body().getString("structureId"); userService.listAdml(sId, responseHandler(message)); break; default: message.reply(new JsonObject().put("status", "error").put("message", "Invalid action.")); } }
From source file:org.entcore.directory.controllers.DirectoryController.java
License:Open Source License
private Handler<Either<String, JsonArray>> responseHandler(final Message<JsonObject> message) { return new Handler<Either<String, JsonArray>>() { @Override/* w w w .j a v a2 s . c om*/ 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); } }; }
From source file:org.entcore.directory.controllers.TimetableController.java
License:Open Source License
@BusAddress("timetable") @SuppressWarnings("unchecked") public void getTimetable(final Message<JsonObject> message) { final String action = message.body().getString("action"); if (action == null) { log.warn("[@BusAddress](timetable) Invalid action."); message.reply(new JsonObject().put("status", "error").put("message", "Invalid action.")); return;//from www . j a v a 2 s. c o m } final String structureId = message.body().getString("structureId"); switch (action) { case "get.course": final String teacherId = message.body().getString("teacherId"); final List<String> groupNames = message.body().getJsonArray("group", new JsonArray()).getList(); final String beginDate = message.body().getString("begin"); final String endDate = message.body().getString("end"); if (beginDate != null && endDate != null && beginDate.matches("\\d{4}-\\d{2}-\\d{2}") && endDate.matches("\\d{4}-\\d{2}-\\d{2}")) { timetableService.listCoursesBetweenTwoDates(structureId, teacherId, groupNames, beginDate, endDate, getBusResultHandler(message)); } else { message.reply(new JsonObject().put("status", "error").put("message", "timetable.invalid.dates")); } break; case "get.subjects": final List<String> teachers = message.body() .getJsonArray("teacherIds", new fr.wseduc.webutils.collections.JsonArray()).getList(); final String externalGroupId = message.body().getString("externalGroupId"); final boolean classes = message.body().getBoolean("classes", false); final boolean groups = message.body().getBoolean("groups", false); if (StringUtils.isEmpty(externalGroupId)) { timetableService.listSubjects(structureId, teachers, classes, groups, getBusResultHandler(message)); } else { timetableService.listSubjectsByGroup(structureId, externalGroupId, getBusResultHandler(message)); } break; default: message.reply(new JsonObject().put("status", "error").put("message", "Invalid action.")); break; } }