List of usage examples for io.vertx.core.eventbus Message body
@CacheReturn T body();
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private JsonObject getSessionByUserId(Message<JsonObject> message) { final String userId = message.body().getString("userId"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[getSessionByUserId] Invalid userId : " + message.body().encode()); return null; }/*from w w w.j a v a2 s . co m*/ LoginInfo info = getLoginInfo(userId); if (info == null) { // disconnected user : ignore action sendOK(message); return null; } JsonObject session = null; try { session = unmarshal(sessions.get(info.sessionId)); } catch (Exception e) { logger.error("Error in deserializing hazelcast session " + info.sessionId, e); } if (session == null) { sendError(message, "Session not found. 7"); return null; } return session; }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void updateSessionByUserId(Message<JsonObject> message, JsonObject session) { final String userId = message.body().getString("userId"); if (userId == null || userId.trim().isEmpty()) { sendError(message, "[updateSessionByUserId] Invalid userId : " + message.body().encode()); return;//from w ww . j a va 2s . com } List<LoginInfo> infos = logins.get(userId); if (infos == null || infos.isEmpty()) { sendError(message, "[updateSessionByUserId] info is null - Invalid userId : " + message.body().encode()); return; } for (LoginInfo info : infos) { try { sessions.put(info.sessionId, session.encode()); } catch (Exception e) { logger.error("Error putting session in hazelcast map : " + info.sessionId, e); } } }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void doRemoveAttribute(Message<JsonObject> message) { JsonObject session = getSessionByUserId(message); if (session == null) { return;/*from www .j a v a 2s . c o m*/ } String key = message.body().getString("key"); if (key == null || key.trim().isEmpty()) { sendError(message, "Invalid key."); return; } session.getJsonObject("cache").remove(key); updateSessionByUserId(message, session); sendOK(message); }
From source file:org.entcore.session.AuthManager.java
License:Open Source License
private void generateSessionInfos(final String userId, final Handler<JsonObject> handler) { final String query = "MATCH (n:User {id : {id}}) " + "WHERE HAS(n.login) " + "OPTIONAL MATCH n-[:IN]->(gp:Group) " + "OPTIONAL MATCH gp-[:DEPENDS]->(s:Structure) " + "OPTIONAL MATCH gp-[:DEPENDS]->(c:Class) " + "OPTIONAL MATCH n-[rf:HAS_FUNCTION]->fg-[:CONTAINS_FUNCTION*0..1]->(f:Function) " + "OPTIONAL MATCH n<-[:RELATED]-(child:User) " + "RETURN distinct " + "n.classes as classNames, n.level as level, n.login as login, COLLECT(distinct [c.id, c.name]) as classes, " + "n.lastName as lastName, n.firstName as firstName, n.externalId as externalId, n.federated as federated, " + "n.birthDate as birthDate, " + "n.displayName as username, HEAD(n.profiles) as type, COLLECT(distinct [child.id, child.lastName, child.firstName]) as childrenInfo, " + "COLLECT(distinct [s.id, s.name]) as structures, COLLECT(distinct [f.externalId, rf.scope]) as functions, " + "COLLECT(distinct s.UAI) as uai, " + "COLLECT(distinct gp.id) as groupsIds, n.federatedIDP as federatedIDP, n.functions as aafFunctions"; final String query2 = "MATCH (n:User {id : {id}})-[:IN]->()-[:AUTHORIZED]->(:Role)-[:AUTHORIZE]->(a:Action)" + "<-[:PROVIDE]-(app:Application) " + "WHERE HAS(n.login) " + "RETURN DISTINCT COLLECT(distinct [a.name,a.displayName,a.type]) as authorizedActions, " + "COLLECT(distinct [app.name,app.address,app.icon,app.target,app.displayName,app.display,app.prefix]) as apps"; final String query3 = "MATCH (u:User {id: {id}})-[:IN]->(g:Group)-[auth:AUTHORIZED]->(w:Widget) " + "WHERE HAS(u.login) " + "AND ( NOT(w<-[:HAS_WIDGET]-(:Application)-[:PROVIDE]->(:WorkflowAction)) " + "XOR w<-[:HAS_WIDGET]-(:Application)-[:PROVIDE]->(:WorkflowAction)<-[:AUTHORIZE]-(:Role)<-[:AUTHORIZED]-g ) " + "OPTIONAL MATCH (w)<-[:HAS_WIDGET]-(app:Application) " + "WITH w, app, collect(auth) as authorizations " + "RETURN DISTINCT COLLECT({" + "id: w.id, name: w.name, " + "path: coalesce(app.address, '') + w.path, " + "js: coalesce(app.address, '') + w.js, " + "i18n: coalesce(app.address, '') + w.i18n, " + "application: app.name, " + "mandatory: ANY(a IN authorizations WHERE HAS(a.mandatory) AND a.mandatory = true)" + "}) as widgets"; final String query4 = "MATCH (s:Structure) return s.id as id, s.externalId as externalId"; final String query5 = "MATCH (u:User {id: {id}})-[:PREFERS]->(uac:UserAppConf) RETURN uac AS preferences"; JsonObject params = new JsonObject(); params.put("id", userId); JsonArray statements = new fr.wseduc.webutils.collections.JsonArray() .add(new JsonObject().put("statement", query).put("parameters", params)) .add(new JsonObject().put("statement", query2).put("parameters", params)) .add(new JsonObject().put("statement", query3).put("parameters", params)) .add(new JsonObject().put("statement", query4)) .add(new JsonObject().put("statement", query5).put("parameters", params)); neo4j.executeTransaction(statements, null, true, new Handler<Message<JsonObject>>() { @Override//from ww w . j av a 2 s.c o m public void handle(Message<JsonObject> message) { JsonArray results = message.body().getJsonArray("results"); if ("ok".equals(message.body().getString("status")) && results != null && results.size() == 5 && results.getJsonArray(0).size() > 0 && results.getJsonArray(1).size() > 0) { JsonObject j = results.getJsonArray(0).getJsonObject(0); JsonObject j2 = results.getJsonArray(1).getJsonObject(0); JsonObject j3 = results.getJsonArray(2).getJsonObject(0); JsonObject structureMapping = new JsonObject(); for (Object o : results.getJsonArray(3)) { if (!(o instanceof JsonObject)) continue; JsonObject jsonObject = (JsonObject) o; structureMapping.put(jsonObject.getString("externalId"), jsonObject.getString("id")); } j.put("userId", userId); JsonObject functions = new JsonObject(); JsonArray actions = new fr.wseduc.webutils.collections.JsonArray(); JsonArray apps = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : getOrElse(j2.getJsonArray("authorizedActions"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; JsonArray a = (JsonArray) o; actions.add(new JsonObject().put("name", a.getString(0)).put("displayName", a.getString(1)) .put("type", a.getString(2))); } for (Object o : getOrElse(j2.getJsonArray("apps"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; JsonArray a = (JsonArray) o; apps.add(new JsonObject().put("name", (String) a.getString(0)) .put("address", (String) a.getString(1)).put("icon", (String) a.getString(2)) .put("target", (String) a.getString(3)).put("displayName", (String) a.getString(4)) .put("display", ((a.getValue(5) == null) || a.getBoolean(5))) .put("prefix", (String) a.getString(6))); } for (Object o : getOrElse(j.getJsonArray("aafFunctions"), new fr.wseduc.webutils.collections.JsonArray())) { if (o == null) continue; String[] sf = o.toString().split("\\$"); if (sf.length == 5) { JsonObject jo = functions.getJsonObject(sf[1]); if (jo == null) { jo = new JsonObject().put("code", sf[1]).put("functionName", sf[2]) .put("scope", new fr.wseduc.webutils.collections.JsonArray()) .put("structureExternalIds", new fr.wseduc.webutils.collections.JsonArray()) .put("subjects", new JsonObject()); functions.put(sf[1], jo); } JsonObject subject = jo.getJsonObject("subjects").getJsonObject(sf[3]); if (subject == null) { subject = new JsonObject().put("subjectCode", sf[3]).put("subjectName", sf[4]) .put("scope", new fr.wseduc.webutils.collections.JsonArray()) .put("structureExternalIds", new fr.wseduc.webutils.collections.JsonArray()); jo.getJsonObject("subjects").put(sf[3], subject); } jo.getJsonArray("structureExternalIds").add(sf[0]); subject.getJsonArray("structureExternalIds").add(sf[0]); String sid = structureMapping.getString(sf[0]); if (sid != null) { jo.getJsonArray("scope").add(sid); subject.getJsonArray("scope").add(sid); } } } j.remove("aafFunctions"); for (Object o : getOrElse(j.getJsonArray("functions"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; JsonArray a = (JsonArray) o; String code = a.getString(0); if (code != null) { functions.put(code, new JsonObject().put("code", code).put("scope", a.getJsonArray(1))); } } final JsonObject children = new JsonObject(); final List<String> childrenIds = new ArrayList<String>(); for (Object o : getOrElse(j.getJsonArray("childrenInfo"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; final JsonArray a = (JsonArray) o; final String childId = a.getString(0); if (childId != null) { childrenIds.add(childId); JsonObject jo = children.getJsonObject(childId); if (jo == null) { jo = new JsonObject().put("lastName", a.getString(1)).put("firstName", a.getString(2)); children.put(childId, jo); } } } j.remove("childrenInfo"); final List<String> classesIds = new ArrayList<String>(); final List<String> classesNames = new ArrayList<String>(); for (Object o : getOrElse(j.getJsonArray("classes"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; final JsonArray c = (JsonArray) o; if (c.getString(0) != null) { classesIds.add(c.getString(0)); classesNames.add(c.getString(1)); } } j.remove("classes"); final List<String> structureIds = new ArrayList<String>(); final List<String> structureNames = new ArrayList<String>(); for (Object o : getOrElse(j.getJsonArray("structures"), new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonArray)) continue; final JsonArray s = (JsonArray) o; if (s.getString(0) != null) { structureIds.add(s.getString(0)); structureNames.add(StringUtils.trimToBlank(s.getString(1))); } } j.remove("structures"); j.put("structures", new fr.wseduc.webutils.collections.JsonArray(structureIds)); j.put("structureNames", new fr.wseduc.webutils.collections.JsonArray(structureNames)); j.put("classes", new fr.wseduc.webutils.collections.JsonArray(classesIds)); j.put("realClassesNames", new fr.wseduc.webutils.collections.JsonArray(classesNames)); j.put("functions", functions); j.put("authorizedActions", actions); j.put("apps", apps); j.put("childrenIds", new fr.wseduc.webutils.collections.JsonArray(childrenIds)); j.put("children", children); final JsonObject cache = (results.getJsonArray(4) != null && results.getJsonArray(4).size() > 0 && results.getJsonArray(4).getJsonObject(0) != null) ? results.getJsonArray(4).getJsonObject(0) : new JsonObject(); j.put("cache", cache); j.put("widgets", getOrElse(j3.getJsonArray("widgets"), new fr.wseduc.webutils.collections.JsonArray())); handler.handle(j); } else { handler.handle(null); } } }); }
From source file:org.entcore.timeline.controllers.TimelineController.java
License:Open Source License
@BusAddress("wse.timeline") public void busApi(final Message<JsonObject> message) { if (message == null) { return;/*from w w w. jav a 2s . co m*/ } final JsonObject json = message.body(); if (json == null) { message.reply(new JsonObject().put("status", "error").put("message", "Invalid body.")); return; } final Handler<JsonObject> handler = new Handler<JsonObject>() { public void handle(JsonObject event) { message.reply(event); } }; String action = json.getString("action"); if (action == null) { log.warn("Invalid action."); message.reply(new JsonObject().put("status", "error").put("message", "Invalid action.")); return; } switch (action) { case "add": final String sender = json.getString("sender"); if (sender == null || sender.startsWith("no-reply") || json.getBoolean("disableAntiFlood", false) || antiFlood.add(sender)) { store.add(json, new Handler<JsonObject>() { public void handle(JsonObject result) { notificationHelper.sendImmediateNotifications( new JsonHttpServerRequest(json.getJsonObject("request")), json); handler.handle(result); } }); if (refreshTypesCache && eventTypes != null && !eventTypes.contains(json.getString("type"))) { eventTypes = null; } } else { message.reply(new JsonObject().put("status", "error").put("message", "flood")); } break; case "get": UserInfos u = new UserInfos(); u.setUserId(json.getString("recipient")); u.setExternalId(json.getString("externalId")); store.get(u, null, json.getInteger("offset", 0), json.getInteger("limit", 25), null, false, handler); break; case "delete": store.delete(json.getString("resource"), handler); break; case "deleteSubResource": store.deleteSubResource(json.getString("sub-resource"), handler); case "list-types": store.listTypes(new Handler<JsonArray>() { @Override public void handle(JsonArray types) { message.reply(new JsonObject().put("status", "ok").put("types", types)); } }); break; default: message.reply(new JsonObject().put("status", "error").put("message", "Invalid action.")); } }
From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java
License:Open Source License
@Override public void get(final UserInfos user, List<String> types, int offset, int limit, JsonObject restrictionFilter, boolean mine, final Handler<JsonObject> result) { final String recipient = user.getUserId(); final String externalId = user.getExternalId(); if (recipient != null && !recipient.trim().isEmpty()) { final JsonObject query = new JsonObject().put("deleted", new JsonObject().put("$exists", false)) .put("date", new JsonObject().put("$lt", MongoDb.now())); if (externalId == null || externalId.trim().isEmpty()) { query.put(mine ? "sender" : "recipients.userId", recipient); } else {//from w ww . j a v a2 s . c o m query.put(mine ? "sender" : "recipients.userId", new JsonObject().put("$in", new fr.wseduc.webutils.collections.JsonArray().add(recipient).add(externalId))); } query.put("reportAction.action", new JsonObject().put("$ne", "DELETE")); if (types != null && !types.isEmpty()) { if (types.size() == 1) { query.put("type", types.get(0)); } else { JsonArray typesFilter = new fr.wseduc.webutils.collections.JsonArray(); for (String t : types) { typesFilter.add(new JsonObject().put("type", t)); } query.put("$or", typesFilter); } } if (restrictionFilter != null && restrictionFilter.size() > 0) { JsonArray nor = new fr.wseduc.webutils.collections.JsonArray(); for (String type : restrictionFilter.getMap().keySet()) { for (Object eventType : restrictionFilter.getJsonArray(type, new fr.wseduc.webutils.collections.JsonArray())) { nor.add(new JsonObject().put("type", type).put("event-type", eventType.toString())); } query.put("$nor", nor); } } JsonObject sort = new JsonObject().put("created", -1); JsonObject keys = new JsonObject().put("message", 1).put("params", 1).put("date", 1).put("sender", 1) .put("comments", 1).put("type", 1).put("event-type", 1).put("resource", 1) .put("sub-resource", 1).put("add-comment", 1); if (!mine) { keys.put("recipients", new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId()))); keys.put("reporters", new JsonObject().put("$elemMatch", new JsonObject().put("userId", user.getUserId()))); } mongo.find(TIMELINE_COLLECTION, query, sort, keys, offset, limit, 100, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> message) { result.handle(message.body()); } }); } else { result.handle(invalidArguments()); } }
From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java
License:Open Source License
@Override public void listTypes(final Handler<JsonArray> result) { mongo.distinct(TIMELINE_COLLECTION, "type", new Handler<Message<JsonObject>>() { @Override//from www. j ava 2 s . co m public void handle(Message<JsonObject> event) { if ("ok".equals(event.body().getString("status"))) { result.handle( event.body().getJsonArray("values", new fr.wseduc.webutils.collections.JsonArray())); } else { result.handle(new fr.wseduc.webutils.collections.JsonArray()); } } }); }
From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java
License:Open Source License
private Handler<Message<JsonObject>> resultHandler(final Handler<JsonObject> result) { return new Handler<Message<JsonObject>>() { @Override/* w w w.j ava 2s . co m*/ public void handle(Message<JsonObject> message) { result.handle(message.body()); } }; }
From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java
License:Open Source License
private void markEventsAsRead(Message<JsonObject> message, String recipient) { JsonArray events = message.body().getJsonArray("results"); if (events != null && "ok".equals(message.body().getString("status"))) { JsonArray ids = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : events) { if (!(o instanceof JsonObject)) continue; JsonObject json = (JsonObject) o; ids.add(json.getString("_id")); }// w w w .ja va2s. c o m JsonObject q = new JsonObject().put("_id", new JsonObject().put("$in", ids)).put("recipients", new JsonObject().put("$elemMatch", new JsonObject().put("userId", recipient).put("unread", 1))); mongo.update(TIMELINE_COLLECTION, q, new JsonObject().put("$set", new JsonObject().put("recipients.$.unread", 0)), false, true); } }
From source file:org.entcore.timeline.services.impl.DefaultTimelineMailerService.java
License:Open Source License
/** * Retrieves all timeline notifications from mongodb for a single user, from a specific date in the past. * * @param userId : Userid//from w w w . java2 s . c om * @param from : The starting date * @param handler : Handles the notifications */ private void getUserNotifications(String userId, Date from, final Handler<JsonArray> handler) { JsonObject matcher = MongoQueryBuilder.build(QueryBuilder.start("recipients") .elemMatch(QueryBuilder.start("userId").is(userId).get()).and("date").greaterThanEquals(from)); JsonObject keys = new JsonObject().put("_id", 0).put("type", 1).put("event-type", 1).put("params", 1) .put("date", 1); mongo.find("timeline", matcher, null, keys, new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> event) { if ("error".equals(event.body().getString("status", "error"))) { handler.handle(new fr.wseduc.webutils.collections.JsonArray()); } else { handler.handle(event.body().getJsonArray("results")); } } }); }