List of usage examples for io.vertx.core.json JsonArray getString
public String getString(int pos)
From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java
License:Open Source License
public DuplicateUsers(JsonArray sourcesPriority, boolean updateCourses, boolean autoMergeOnlyInSameStructure, EventBus eb) {//from ww w . j av a 2s . com if (sourcesPriority == null) { sourcesPriority = new fr.wseduc.webutils.collections.JsonArray().add("AAF").add("AAF1D").add("CSV") .add("EDT").add("UDT").add("MANUAL"); } final int size = sourcesPriority.size(); for (int i = 0; i < size; i++) { sourcePriority.put(sourcesPriority.getString(i), size - i); } this.eb = eb; this.updateCourses = updateCourses; this.autoMergeOnlyInSameStructure = autoMergeOnlyInSameStructure; }
From source file:org.entcore.feeder.dictionary.structures.Importer.java
License:Open Source License
public void createOrUpdateStudent(JsonObject object, String profileExternalId, String module, JsonArray fieldOfStudy, String[][] linkClasses, String[][] linkGroups, JsonArray relative, boolean nodeQueries, boolean relationshipQueries) { final String error = studentValidator.validate(object); if (error != null) { report.addIgnored("Student", error, object); log.warn(error);//from w w w .ja va 2s .com } else { if (nodeQueries) { object.put("source", currentSource); userImportedExternalId.add(object.getString("externalId")); String query = "MERGE (u:`User` { externalId : {externalId}}) " + "ON CREATE SET u.id = {id}, u.login = {login}, u.activationCode = {activationCode}, " + "u.displayName = {displayName}, u.created = {created} " + "WITH u " + "WHERE u.checksum IS NULL OR u.checksum <> {checksum} " + "SET " + Neo4jUtils.nodeSetPropertiesFromJson("u", object, "id", "externalId", "login", "activationCode", "displayName", "email", "created"); transactionHelper.add(query, object); checkUpdateEmail(object); } if (relationshipQueries) { final String externalId = object.getString("externalId"); JsonArray structures = getMappingStructures(object.getJsonArray("structures")); if (externalId != null && structures != null && structures.size() > 0) { String query; JsonObject p = new JsonObject().put("userExternalId", externalId); if (structures.size() == 1) { query = "MATCH (s:Structure {externalId : {structureAdmin}})<-[:DEPENDS]-(g:ProfileGroup)-[:HAS_PROFILE]->(p:Profile {externalId : {profileExternalId}}), " + "(u:User { externalId : {userExternalId}}) " + "WHERE NOT(HAS(u.mergedWith)) " + "MERGE u-[:ADMINISTRATIVE_ATTACHMENT]->s " + "WITH u, g " + "MERGE u-[:IN]->g"; p.put("structureAdmin", structures.getString(0)).put("profileExternalId", profileExternalId); } else { query = "MATCH (s:Structure)<-[:DEPENDS]-(g:ProfileGroup)-[:HAS_PROFILE]->(p:Profile), " + "(u:User { externalId : {userExternalId}})) " + "WHERE s.externalId IN {structuresAdmin} AND NOT(HAS(u.mergedWith)) " + "AND p.externalId = {profileExternalId} " + "MERGE u-[:ADMINISTRATIVE_ATTACHMENT]->s " + "WITH u, g " + "MERGE u-[:IN]->g"; p.put("structuresAdmin", structures).put("profileExternalId", profileExternalId); } transactionHelper.add(query, p); String qs = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(:Group)-[:DEPENDS]->(s:Structure) " + "WHERE NOT(s.externalId IN {structures}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; JsonObject ps = new JsonObject().put("userExternalId", externalId).put("source", currentSource) .put("structures", structures); transactionHelper.add(qs, ps); final String daa = "MATCH (u:User {externalId : {userExternalId}})-[r:ADMINISTRATIVE_ATTACHMENT]->(s:Structure) " + "WHERE NOT(s.externalId IN {structures}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; transactionHelper.add(daa, ps); } JsonArray classes = new fr.wseduc.webutils.collections.JsonArray(); if (externalId != null && linkClasses != null) { for (String[] structClass : linkClasses) { if (structClass != null && structClass[0] != null && structClass[1] != null) { classes.add(structClass[1]); } } String query = "MATCH (c:Class)<-[:DEPENDS]-(g:ProfileGroup)" + "-[:DEPENDS]->(:ProfileGroup)-[:HAS_PROFILE]->(:Profile {externalId : {profileExternalId}}), " + "(u:User { externalId : {userExternalId}}) " + "WHERE c.externalId IN {classes} AND NOT(HAS(u.mergedWith)) " + "MERGE u-[:IN]->g"; JsonObject p0 = new JsonObject().put("userExternalId", externalId) .put("profileExternalId", profileExternalId).put("classes", classes); transactionHelper.add(query, p0); } if (externalId != null) { String q = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(:Group)-[:DEPENDS]->(c:Class) " + "WHERE NOT(c.externalId IN {classes}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("source", currentSource) .put("classes", classes); transactionHelper.add(q, p); } final JsonArray groups = new fr.wseduc.webutils.collections.JsonArray(); if (externalId != null && linkGroups != null) { for (String[] structGroup : linkGroups) { if (structGroup != null && structGroup[0] != null && structGroup[1] != null) { groups.add(structGroup[1]); } } String query = "MATCH (g:FunctionalGroup), (u:User { externalId : {userExternalId}}) " + "WHERE g.externalId IN {groups} AND NOT(HAS(u.mergedWith)) " + "MERGE u-[:IN]->g"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("groups", groups); transactionHelper.add(query, p); } if (externalId != null) { final String qdfg = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(g:FunctionalGroup) " + "WHERE NOT(g.externalId IN {groups}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; final JsonObject pdfg = new JsonObject().put("userExternalId", externalId) .put("source", currentSource).put("groups", groups); transactionHelper.add(qdfg, pdfg); } if (externalId != null && module != null) { String query = "MATCH (u:User {externalId:{userExternalId}}), " + "(m:Module {externalId:{moduleStudent}}) " + "MERGE u-[:FOLLOW]->m"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("moduleStudent", module); transactionHelper.add(query, p); } if (externalId != null && fieldOfStudy != null && fieldOfStudy.size() > 0) { String query = "MATCH (u:User {externalId:{userExternalId}}), (f:FieldOfStudy) " + "WHERE f.externalId IN {fieldOfStudyStudent} " + "MERGE u-[:COURSE]->f"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("fieldOfStudyStudent", fieldOfStudy); transactionHelper.add(query, p); } if (externalId != null && relative != null && relative.size() > 0) { String query2 = "MATCH (:User {externalId:{userExternalId}})-[r:RELATED]->(p:User) " + "WHERE NOT(p.externalId IN {relatives}) " + "DELETE r "; JsonObject p2 = new JsonObject().put("userExternalId", externalId).put("relatives", relative); transactionHelper.add(query2, p2); for (Object o : relative) { if (!(o instanceof String)) continue; String query = "MATCH (u:User {externalId:{userExternalId}}), " + "(:User {externalId:{user}})-[:MERGED*0..1]->(r:User) " + "WHERE NOT(HAS(r.mergedWith)) " + "MERGE u-[:RELATED]->r " + "WITH r, u " + "WHERE {user} <> r.externalId AND LENGTH(FILTER(eId IN u.relative WHERE eId STARTS WITH r.externalId)) = 0 " + "SET u.relative = coalesce(u.relative, []) + (r.externalId + '$10$1$1$0$0') "; JsonObject p = new JsonObject().put("userExternalId", externalId).put("user", (String) o); transactionHelper.add(query, p); } } } } }
From source file:org.entcore.feeder.dictionary.structures.Structure.java
License:Open Source License
public void addAttachment() { JsonArray functionalAttachment = struct.getJsonArray("functionalAttachment"); if (functionalAttachment != null && functionalAttachment.size() > 0 && !externalId.equals(functionalAttachment.getString(0))) { JsonObject params = new JsonObject().put("externalId", externalId); String query;/*from www .j a va 2 s. co m*/ if (functionalAttachment.size() == 1) { query = "MATCH (s:Structure { externalId : {externalId}}), " + "(ps:Structure { externalId : {functionalAttachment}}) " + "CREATE UNIQUE s-[:HAS_ATTACHMENT]->ps"; params.put("functionalAttachment", functionalAttachment.getString(0)); } else { query = "MATCH (s:Structure { externalId : {externalId}}), (ps:Structure) " + "WHERE ps.externalId IN {functionalAttachment} " + "CREATE UNIQUE s-[:HAS_ATTACHMENT]->ps"; params.put("functionalAttachment", functionalAttachment); } getTransaction().add(query, params); } }
From source file:org.entcore.feeder.dictionary.users.PersEducNat.java
License:Open Source License
public void createOrUpdatePersonnel(JsonObject object, String profileExternalId, JsonArray structuresByFunctions, String[][] linkClasses, String[][] linkGroups, boolean nodeQueries, boolean relationshipQueries) { final String error = personnelValidator.validate(object); if (error != null) { if (object.getJsonArray("profiles") != null && object.getJsonArray("profiles").size() == 1) { report.addIgnored(object.getJsonArray("profiles").getString(0), error, object); } else {/* w w w . j a v a 2 s. com*/ report.addIgnored("Personnel", error, object); } log.warn(error); } else { if (nodeQueries) { object.put("source", currentSource); if (userImportedExternalId != null) { userImportedExternalId.add(object.getString("externalId")); } StringBuilder sb = new StringBuilder(); JsonObject params; sb.append("MERGE (u:`User` { externalId : {externalId}}) "); sb.append("ON CREATE SET u.id = {id}, u.login = {login}, u.activationCode = {activationCode}, "); sb.append("u.displayName = {displayName}, u.created = {created} "); sb.append("WITH u "); if (!EDTImporter.EDT.equals(currentSource)) { sb.append("WHERE u.checksum IS NULL OR u.checksum <> {checksum} "); } sb.append("SET ").append(Neo4jUtils.nodeSetPropertiesFromJson("u", object, "id", "externalId", "login", "activationCode", "displayName", "email", "created")); if (EDTImporter.EDT.equals(currentSource)) { sb.append("RETURN u.id as id, u.IDPN as IDPN, head(u.profiles) as profile"); } params = object; transactionHelper.add(sb.toString(), params); checkUpdateEmail(object); } if (relationshipQueries) { final String externalId = object.getString("externalId"); JsonArray structures = getMappingStructures(object.getJsonArray("structures")); if (externalId != null && structures != null && structures.size() > 0) { String query; JsonObject p = new JsonObject().put("userExternalId", externalId); if (structures.size() == 1) { query = "MATCH (s:Structure {externalId : {structureAdmin}}), (u:User {externalId : {userExternalId}}) " + "MERGE u-[:ADMINISTRATIVE_ATTACHMENT]->s "; p.put("structureAdmin", structures.getString(0)); } else { query = "MATCH (s:Structure), (u:User {externalId : {userExternalId}}) " + "WHERE s.externalId IN {structuresAdmin} " + "MERGE u-[:ADMINISTRATIVE_ATTACHMENT]->s "; p.put("structuresAdmin", structures); } transactionHelper.add(query, p); } if (externalId != null && structuresByFunctions != null && structuresByFunctions.size() > 0) { String query; structuresByFunctions = getMappingStructures(structuresByFunctions); JsonObject p = new JsonObject().put("userExternalId", externalId); if (structuresByFunctions.size() == 1) { query = "MATCH (s:Structure {externalId : {structureAdmin}})<-[:DEPENDS]-(g:ProfileGroup)-[:HAS_PROFILE]->(p:Profile {externalId : {profileExternalId}}), " + "(u:User { externalId : {userExternalId}}) " + "WHERE NOT(HAS(u.mergedWith)) " + "MERGE u-[:IN]->g"; p.put("structureAdmin", structuresByFunctions.getString(0)).put("profileExternalId", profileExternalId); } else { query = "MATCH (s:Structure)<-[:DEPENDS]-(g:ProfileGroup)-[:HAS_PROFILE]->(p:Profile), " + "(u:User { externalId : {userExternalId}}) " + "WHERE s.externalId IN {structuresAdmin} AND NOT(HAS(u.mergedWith)) " + "AND p.externalId = {profileExternalId} " + "MERGE u-[:IN]->g "; p.put("structuresAdmin", structuresByFunctions).put("profileExternalId", profileExternalId); } transactionHelper.add(query, p); String qs = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(:Group)-[:DEPENDS]->(s:Structure) " + "WHERE NOT(s.externalId IN {structures}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; JsonObject ps = new JsonObject().put("userExternalId", externalId).put("source", currentSource) .put("structures", structuresByFunctions); transactionHelper.add(qs, ps); final String daa = "MATCH (u:User {externalId : {userExternalId}})-[r:ADMINISTRATIVE_ATTACHMENT]->(s:Structure) " + "WHERE NOT(s.externalId IN {structures}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; transactionHelper.add(daa, ps.copy().put("structures", getOrElse(structures, new JsonArray()))); } final JsonObject fosm = new JsonObject(); final JsonArray classes = new fr.wseduc.webutils.collections.JsonArray(); if (externalId != null && linkClasses != null) { final JsonObject fcm = new JsonObject(); for (String[] structClass : linkClasses) { if (structClass != null && structClass[0] != null && structClass[1] != null) { classes.add(structClass[1]); if (structClass.length > 2 && isNotEmpty(structClass[2])) { JsonArray fClasses = fcm.getJsonArray(structClass[2]); if (fClasses == null) { fClasses = new fr.wseduc.webutils.collections.JsonArray(); fcm.put(structClass[2], fClasses); } fClasses.add(structClass[1]); } } } String query = "MATCH (c:Class)<-[:DEPENDS]-(g:ProfileGroup)" + "-[:DEPENDS]->(pg:ProfileGroup)-[:HAS_PROFILE]->(p:Profile {externalId : {profileExternalId}}), " + "(u:User { externalId : {userExternalId}}) " + "WHERE c.externalId IN {classes} AND NOT(HAS(u.mergedWith)) " + "MERGE u-[:IN]->g"; JsonObject p0 = new JsonObject().put("userExternalId", externalId) .put("profileExternalId", profileExternalId).put("classes", classes); transactionHelper.add(query, p0); JsonObject p = new JsonObject().put("userExternalId", externalId).put("source", currentSource) .put("classes", classes); fosm.mergeIn(fcm); for (String fos : fcm.fieldNames()) { String q2 = "MATCH (u:User {externalId : {userExternalId}}), (f:FieldOfStudy {externalId:{feId}}) " + "MERGE u-[r:TEACHES_FOS]->f " + "SET r.classes = {classes} "; transactionHelper.add(q2, p.copy().put("classes", fcm.getJsonArray(fos)).put("feId", fos)); } } if (externalId != null) { String q = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(:Group)-[:DEPENDS]->(c:Class) " + "WHERE NOT(c.externalId IN {classes}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("source", currentSource) .put("classes", classes); transactionHelper.add(q, p); } final JsonArray groups = new fr.wseduc.webutils.collections.JsonArray(); final JsonObject fgm = new JsonObject(); if (externalId != null && linkGroups != null) { for (String[] structGroup : linkGroups) { if (structGroup != null && structGroup[0] != null && structGroup[1] != null) { groups.add(structGroup[1]); if (structGroup.length > 2 && isNotEmpty(structGroup[2])) { JsonArray fGroups = fgm.getJsonArray(structGroup[2]); if (fGroups == null) { fGroups = new fr.wseduc.webutils.collections.JsonArray(); fgm.put(structGroup[2], fGroups); } fGroups.add(structGroup[1]); } } } String query = "MATCH (g:Group), (u:User {externalId : {userExternalId}}) " + "WHERE (g:FunctionalGroup OR g:FunctionGroup OR g:HTGroup) AND g.externalId IN {groups} " + "MERGE u-[:IN]->g"; JsonObject p = new JsonObject().put("userExternalId", externalId).put("groups", groups); transactionHelper.add(query, p); } if (externalId != null) { final String qdfg = "MATCH (:User {externalId : {userExternalId}})-[r:IN|COMMUNIQUE]-(g:Group) " + "WHERE (g:FunctionalGroup OR g:FunctionGroup OR g:HTGroup) AND " + "NOT(g.externalId IN {groups}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; final JsonObject pdfg = new JsonObject().put("userExternalId", externalId) .put("source", currentSource).put("groups", groups); transactionHelper.add(qdfg, pdfg); fosm.mergeIn(fgm); final String deleteOldFoslg = "MATCH (u:User {externalId : {userExternalId}})-[r:TEACHES_FOS]->(f:FieldOfStudy) " + "WHERE NOT(f.externalId IN {fos}) AND (NOT(HAS(r.source)) OR r.source = {source}) " + "DELETE r"; transactionHelper.add(deleteOldFoslg, pdfg.copy().put("fos", new fr.wseduc.webutils.collections.JsonArray(new ArrayList<>(fosm.fieldNames())))); for (String fos : fgm.fieldNames()) { String q2 = "MATCH (u:User {externalId : {userExternalId}}), (f:FieldOfStudy {externalId:{feId}}) " + "MERGE u-[r:TEACHES_FOS]->f " + "SET r.groups = {groups} "; transactionHelper.add(q2, pdfg.copy().put("groups", fgm.getJsonArray(fos)).put("feId", fos)); } } } } }
From source file:org.entcore.feeder.utils.AAFUtil.java
License:Open Source License
private static JsonArray functionsEtabConverter(JsonArray value) { JsonArray res = new fr.wseduc.webutils.collections.JsonArray(); for (Object o : value) { if (!(o instanceof JsonArray)) continue; JsonArray a = (JsonArray) o; final String c = a.getString(0); if (c != null) { final String code = functionCodes.getString(c, c); for (Object s : a.getJsonArray(1)) { res.add("EtabEducNat$" + s + "$" + code); }/*from ww w .j av a2 s. com*/ } } return res; }
From source file:org.entcore.feeder.utils.Validator.java
License:Open Source License
private String[] getParameters(JsonObject object, JsonObject j) { String[] v = null;/*from w w w.j a v a 2s.c o m*/ JsonArray args = j.getJsonArray("args"); if (args != null && args.size() > 0) { v = new String[args.size()]; for (int i = 0; i < args.size(); i++) { v[i] = object.getString(args.getString(i)); } } return v; }
From source file:org.entcore.feeder.utils.Validator.java
License:Open Source License
private String getParameter(JsonObject object, JsonObject j) { String v = null;// w w w. j a v a 2s.c om JsonArray args = j.getJsonArray("args"); if (args != null && args.size() == 1) { v = object.getString(args.getString(0)); } return v; }
From source file:org.entcore.registry.services.impl.DefaultAppRegistryService.java
License:Open Source License
@Override public void listCasConnectors(final Handler<Either<String, JsonArray>> handler) { String query = "MATCH (app:Application) " + "WHERE has(app.casType) and app.casType <> '' " + "RETURN app.casType as service, app.address as address, COLLECT(app.pattern) as patterns"; neo.execute(query, (JsonObject) null, validResultHandler(new Handler<Either<String, JsonArray>>() { public void handle(Either<String, JsonArray> event) { if (event.isLeft()) { handler.handle(event);// w w w. ja va2 s .com return; } JsonArray results = event.right().getValue(); for (Object o : results) { JsonObject app = (JsonObject) o; String address = app.getString("address", ""); JsonArray patterns = app.getJsonArray("patterns", new fr.wseduc.webutils.collections.JsonArray()); if (patterns.size() == 0 || patterns.size() > 0 && patterns.getString(0).isEmpty()) { final URL addressURL = checkCasUrl(address); if (addressURL != null) { String pattern = "^\\Q" + addressURL.getProtocol() + "://" + addressURL.getHost() + (addressURL.getPort() > 0 ? ":" + addressURL.getPort() : "") + "\\E.*"; patterns.add(pattern); } else { log.error("Url for registered service : " + app.getString("service", "") + " is malformed : " + address); } } } handler.handle(new Either.Right<String, JsonArray>(results)); } })); }
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/* w w w. j a va2 s. c om*/ 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.services.impl.DefaultTimelineMailerService.java
License:Open Source License
@Override public void sendImmediateMails(HttpServerRequest request, String notificationName, JsonObject notification, JsonObject templateParameters, JsonArray userList, JsonObject notificationProperties) { final Map<String, Map<String, String>> processedTemplates = new HashMap<>(); templateParameters.put("innerTemplate", notification.getString("template", "")); final Map<String, Map<String, List<Object>>> toByDomainLang = new HashMap<>(); final AtomicInteger userCount = new AtomicInteger(userList.size()); final Handler<Void> templatesHandler = new Handler<Void>() { public void handle(Void v) { if (userCount.decrementAndGet() == 0) { if (toByDomainLang.size() > 0) { //On completion : log final Handler<AsyncResult<Message<JsonObject>>> completionHandler = event -> { if (event.failed() || "error".equals(event.result().body().getString("status", "error"))) { log.error("[Timeline immediate emails] Error while sending mails : ", event.cause()); } else { log.debug("[Timeline immediate emails] Immediate mails sent."); }/*w ww. j a v a2 s . co m*/ }; JsonArray keys = new fr.wseduc.webutils.collections.JsonArray() .add("timeline.immediate.mail.subject.header").add(notificationName.toLowerCase()); for (final String domain : toByDomainLang.keySet()) { for (final String lang : toByDomainLang.get(domain).keySet()) { translateTimeline(keys, domain, lang, new Handler<JsonArray>() { public void handle(JsonArray translations) { //Send mail containing the "immediate" notification emailSender.sendEmail(request, toByDomainLang.get(domain).get(lang), null, null, translations.getString(0) + translations.getString(1), processedTemplates.get(domain).get(lang), null, false, completionHandler); } }); } } } } } }; for (Object userObj : userList) { final JsonObject userPref = ((JsonObject) userObj); final String userDomain = userPref.getString("lastDomain", I18n.DEFAULT_DOMAIN); final String userScheme = userPref.getString("lastScheme", "http"); String mutableLanguage = "fr"; try { mutableLanguage = getOrElse(new JsonObject(getOrElse(userPref.getString("language"), "{}", false)) .getString("default-domain"), "fr", false); } catch (Exception e) { log.error("UserId [" + userPref.getString("userId", "") + "] - Bad language preferences format"); } final String userLanguage = mutableLanguage; if (!processedTemplates.containsKey(userDomain)) processedTemplates.put(userDomain, new HashMap<String, String>()); JsonObject notificationPreference = userPref.getJsonObject("preferences", new JsonObject()) .getJsonObject("config", new JsonObject()).getJsonObject(notificationName, new JsonObject()); // If the frequency is IMMEDIATE // and the restriction is not INTERNAL (timeline only) // and if the user has provided an email if (TimelineNotificationsLoader.Frequencies.IMMEDIATE.name() .equals(notificationPreference.getString("defaultFrequency", notificationProperties.getString("defaultFrequency"))) && !TimelineNotificationsLoader.Restrictions.INTERNAL.name() .equals(notificationPreference.getString("restriction", notificationProperties.getString("restriction"))) && !TimelineNotificationsLoader.Restrictions.HIDDEN.name() .equals(notificationPreference.getString("restriction", notificationProperties.getString("restriction"))) && userPref.getString("userMail") != null && !userPref.getString("userMail").trim().isEmpty()) { if (!toByDomainLang.containsKey(userDomain)) { toByDomainLang.put(userDomain, new HashMap<String, List<Object>>()); } if (!toByDomainLang.get(userDomain).containsKey(userLanguage)) { toByDomainLang.get(userDomain).put(userLanguage, new ArrayList<Object>()); } toByDomainLang.get(userDomain).get(userLanguage).add(userPref.getString("userMail")); } if (!processedTemplates.get(userDomain).containsKey(userLanguage)) { processTimelineTemplate(templateParameters, "", "notifications/immediate-mail.html", userDomain, userScheme, userLanguage, false, new Handler<String>() { public void handle(String processedTemplate) { processedTemplates.get(userDomain).put(userLanguage, processedTemplate); templatesHandler.handle(null); } }); } else { templatesHandler.handle(null); } } }