List of usage examples for io.vertx.core.json JsonObject copy
@Override
public JsonObject copy()
From source file:org.entcore.auth.adapter.UserInfoAdapterV2_0Json.java
License:Open Source License
@Override public JsonObject getInfo(JsonObject info, String clientId) { JsonObject s = info.copy(); s.remove("cache"); return s;// w ww .j av a 2s . com }
From source file:org.entcore.auth.adapter.UserInfoAdapterV2_1Json.java
License:Open Source License
@Override public JsonObject getInfo(JsonObject info, String clientId) { return info.copy(); }
From source file:org.entcore.auth.controllers.SamlController.java
License:Open Source License
@Get("/saml/authn/:providerId") public void auth(final HttpServerRequest request) { final JsonObject item = samlWayfParams.getJsonObject(request.params().get("providerId")); if (item == null) { forbidden(request, "invalid.provider"); return;// w w w . ja va 2 s. c o m } final JsonObject event = item.copy().put("action", "generate-authn-request"); vertx.eventBus().send("saml", event, handlerToAsyncHandler(new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> event) { if (log.isDebugEnabled()) { log.debug("authn request : " + event.body().encodePrettily()); } final String authnRequest = event.body().getString("authn-request"); if (isNotEmpty(authnRequest)) { CookieHelper.getInstance().setSigned("relaystate", event.body().getString("relay-state"), 900, request); final String callBack = request.params().get("callBack"); if (isNotEmpty(callBack)) { CookieHelper.getInstance().setSigned("callback", callBack, 900, request); } redirect(request, authnRequest, ""); } else { badRequest(request, "empty.authn.request"); } } })); }
From source file:org.entcore.communication.services.impl.DefaultCommunicationService.java
License:Open Source License
private void initDefaultRules(JsonArray structureIds, String attr, JsonObject defaultRules, final StatementsBuilder existingGroups, final StatementsBuilder newGroups) { final String[] a = attr.split("\\-"); final String c = "Class".equals(a[0]) ? "*2" : ""; String relativeStudent = defaultRules.getString("Relative-Student"); // TODO check type in enum if (relativeStudent != null && "Relative".equals(a[1])) { String query = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup) " + "WHERE s.id IN {structures} AND NOT(HAS(cg.communiqueWith)) " + "AND cg.name =~ {profile} " + "SET cg.relativeCommuniqueStudent = {direction} "; JsonObject params = new JsonObject().put("structures", structureIds).put("direction", relativeStudent) .put("profile", "^.*?" + a[1] + "$"); newGroups.add(query, params);/*from w ww .ja v a2s. c o m*/ } String users = defaultRules.getString("users"); // TODO check type in enum if (users != null) { String query = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup) " + "WHERE s.id IN {structures} AND NOT(HAS(cg.communiqueWith)) " + "AND cg.name =~ {profile} " + "SET cg.users = {direction} "; JsonObject params = new JsonObject().put("structures", structureIds).put("direction", users) .put("profile", "^.*?" + a[1] + "$"); newGroups.add(query, params); } JsonArray communiqueWith = defaultRules.getJsonArray("communiqueWith", new fr.wseduc.webutils.collections.JsonArray()); Set<String> classes = new HashSet<>(); Set<String> structures = new HashSet<>(); StringBuilder groupLabelSB = new StringBuilder("g:ProfileGroup"); for (Object o : communiqueWith) { if (!(o instanceof String)) continue; String[] s = ((String) o).split("\\-"); if ("Class".equals(s[0]) && "Structure".equals(a[0])) { log.warn("Invalid default configuration " + attr + "->" + o.toString()); } else if ("Class".equals(s[0])) { if ("HeadTeacher".equals(s[1])) { groupLabelSB.append(" OR g:HTGroup"); } classes.add(s[1]); } else { if ("Func".equals(s[1]) || "Discipline".equals(s[1])) { groupLabelSB.append(" OR g:FunctionGroup"); } else if ("HeadTeacher".equals(s[1])) { groupLabelSB.append(" OR g:HTGroup"); } structures.add(s[1]); } } final String groupLabel = groupLabelSB.toString(); JsonObject params = new JsonObject().put("structures", structureIds).put("profile", "^.*?" + a[1] + "$"); if (!classes.isEmpty()) { String query = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup)-[:DEPENDS]->(c:Class) " + "WHERE s.id IN {structures} AND HAS(cg.communiqueWith) AND cg.name =~ {profile} " + "WITH cg, c " + "MATCH c<-[:DEPENDS]-(g) " + "WHERE (" + groupLabel + ") AND NOT(HAS(g.communiqueWith)) AND g.name =~ {otherProfile} " + "SET cg.communiqueWith = FILTER(gId IN cg.communiqueWith WHERE gId <> g.id) + g.id "; String query2 = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup)-[:DEPENDS]->(c:Class) " + "WHERE s.id IN {structures} AND NOT(HAS(cg.communiqueWith)) AND cg.name =~ {profile} " + "WITH cg, c, s " + "MATCH c<-[:DEPENDS]-(g) " + "WHERE (" + groupLabel + ") AND g.name =~ {otherProfile} " + "SET cg.communiqueWith = coalesce(cg.communiqueWith, []) + g.id "; if (!structures.isEmpty()) { query2 += "WITH DISTINCT s, cg " + "MATCH s<-[:DEPENDS]-(sg:ProfileGroup) " + "WHERE sg.name =~ {structureProfile} " + "SET cg.communiqueWith = coalesce(cg.communiqueWith, []) + sg.id "; } JsonObject p = params.copy(); p.put("otherProfile", "^.*?(" + Joiner.on("|").join(classes) + ")$"); p.put("structureProfile", "^.*?(" + Joiner.on("|").join(structures) + ")$"); existingGroups.add(query, p); newGroups.add(query2, p); } if (!structures.isEmpty() && "Structure".equals(a[0])) { String query = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup), s<-[:DEPENDS]-(g) " + "WHERE s.id IN {structures} AND HAS(cg.communiqueWith) AND cg.name =~ {profile} " + "AND (" + groupLabel + ") AND NOT(HAS(g.communiqueWith)) AND g.name =~ {otherProfile} " + "SET cg.communiqueWith = FILTER(gId IN cg.communiqueWith WHERE gId <> g.id) + g.id "; String query2 = "MATCH (s:Structure)<-[:DEPENDS" + c + "]-(cg:ProfileGroup), s<-[:DEPENDS]-(g) " + "WHERE s.id IN {structures} AND NOT(HAS(cg.communiqueWith)) AND cg.name =~ {profile} " + "AND (" + groupLabel + ") AND g.name =~ {otherProfile} " + "SET cg.communiqueWith = coalesce(cg.communiqueWith, []) + g.id "; params.put("otherProfile", "^.*?(" + Joiner.on("|").join(structures) + ")$"); existingGroups.add(query, params); newGroups.add(query2, params); } }
From source file:org.entcore.directory.controllers.UserBookController.java
License:Open Source License
@BusAddress("activation.ack") public void initUserBookNode(final Message<JsonObject> message) { JsonObject params = new JsonObject(); params.put("userId", message.body().getString("userId")); params.put("avatar", userBookData.getString("default-avatar")); params.put("theme", userBookData.getString("default-theme", "")); JsonArray queries = new fr.wseduc.webutils.collections.JsonArray(); String query = "MERGE (m:UserBook { userid : {userId}}) " + "SET m.type = 'USERBOOK', m.picture = {avatar}, m.motto = '', " + "m.health = '', m.mood = 'default', m.theme = {theme} " + "WITH m " + "MATCH (n:User {id : {userId}}) " + "CREATE UNIQUE n-[:USERBOOK]->m"; queries.add(Neo.toJsonObject(query, params)); String query2 = "MATCH (n:User)-[:USERBOOK]->m " + "WHERE n.id = {userId} " + "CREATE m-[:PUBLIC]->(c:Hobby {category: {category}, values: {values}})"; if (isNotEmpty(message.body().getString("theme"))) { String query3 = "MATCH (u:User {id:{userId}}) " + "MERGE (u)-[:PREFERS]->(uac:UserAppConf) " + "SET uac.theme = {theme} "; JsonObject paramsTheme = new JsonObject().put("userId", message.body().getString("userId")).put("theme", message.body().getString("theme")); queries.add(Neo.toJsonObject(query3, paramsTheme)); }//from w w w .jav a 2 s.c o m for (Object hobby : userBookData.getJsonArray("hobbies")) { JsonObject j = params.copy(); j.put("category", (String) hobby); j.put("values", ""); queries.add(Neo.toJsonObject(query2, j)); } neo.sendBatch(queries, (Handler<Message<JsonObject>>) null); welcomeMessage(message); }
From source file:org.entcore.directory.security.AdmlOfTwoUsers.java
License:Open Source License
@Override public void authorizeAdml(HttpServerRequest resourceRequest, Binding binding, UserInfos user, UserInfos.Function adminLocal, Handler<Boolean> handler) { String userId1 = resourceRequest.params().get("userId1"); String userId2 = resourceRequest.params().get("userId2"); String query = "MATCH (u:User {id: {userId}})-[:IN]->(:Group)-[:DEPENDS]->(s:Structure) " + "WHERE s.id IN {structures} " + "RETURN count(*) > 0 as exists "; JsonObject params = new JsonObject().put("structures", new fr.wseduc.webutils.collections.JsonArray(adminLocal.getScope())); StatementsBuilder statements = new StatementsBuilder().add(query, params.copy().put("userId", userId1)) .add(query, params.copy().put("userId", userId2)); validateQueries(resourceRequest, handler, statements); }
From source file:org.entcore.directory.services.impl.DefaultTimetableService.java
License:Open Source License
@Override public void listCourses(String structureId, long lastDate, Handler<Either<String, JsonArray>> handler) { if (Utils.validationParamsNull(handler, structureId)) return;/* w w w. j a v a 2s . c o m*/ final JsonObject query = new JsonObject().put("structureId", structureId); final JsonObject sort = new JsonObject().put("startDate", 1); final JsonObject keys = KEYS.copy(); if (lastDate > 0) { query.put("$or", new fr.wseduc.webutils.collections.JsonArray() .add(new JsonObject().put("modified", new JsonObject().put("$gte", lastDate))) .add(new JsonObject().put("deleted", new JsonObject().put("$gte", lastDate)))); keys.put("deleted", 1); } else { query.put("deleted", new JsonObject().put("$exists", false)).put("modified", new JsonObject().put("$exists", true)); } MongoDb.getInstance().find(COURSES, query, sort, keys, validResultsHandler(handler)); }
From source file:org.entcore.directory.services.impl.DefaultTimetableService.java
License:Open Source License
@Override public void updateClassesMapping(final String structureId, final JsonObject mapping, final Handler<Either<String, JsonObject>> handler) { classesMapping(structureId, new Handler<Either<String, JsonObject>>() { @Override//from w ww .jav a 2s .c o m public void handle(Either<String, JsonObject> event) { if (event.isRight()) { final JsonObject cm = event.right().getValue(); if (cm == null || cm.getJsonArray("unknownClasses") == null) { handler.handle(new Either.Left<String, JsonObject>("missing.classes.mapping")); return; } final JsonArray uc = cm.getJsonArray("unknownClasses"); final JsonObject m = mapping.getJsonObject("mapping"); for (String attr : m.copy().fieldNames()) { if (!uc.contains(attr)) { m.remove(attr); } } mapping.put("mapping", m.encode()); final String query = "MATCH (:Structure {id:{id}})<-[:MAPPING]-(cm:ClassesMapping) " + "SET cm.mapping = {mapping} "; neo4j.execute(query, mapping.put("id", structureId), validEmptyHandler(handler)); } else { handler.handle(event); } } }); }
From source file:org.entcore.feeder.csv.ColumnsMapper.java
License:Open Source License
public ColumnsMapper(JsonObject additionnalsMappings) { JsonObject mappings = new JsonObject().put("id", "externalId").put("externalid", "externalId") .put("idexterno", "externalId").put("nom", "lastName").put("apellido", "lastName") .put("lastname", "lastName").put("sobrenome", "lastName").put("nomeleve", "lastName") .put("nomresponsable", "lastName").put("nomdusageeleve", "username") .put("nomusageresponsable", "username").put("nomusage", "username").put("nomdusage", "username") .put("prenom", "firstName").put("nombre", "firstName").put("firstname", "firstName") .put("nome", "firstName").put("prenomeleve", "firstName").put("prenomresponsable", "firstName") .put("classe", "classes").put("clase", "classes").put("class", "classes").put("turma", "classes") .put("libelleclasse", "classes").put("classeouregroupement", "classes") .put("idenfant", "childExternalId").put("datedenaissance", "birthDate") .put("datenaissance", "birthDate").put("birthdate", "birthDate") .put("fechadenacimiento", "birthDate").put("datadenascimento", "birthDate") .put("neele", "birthDate").put("ne(e)le", "birthDate").put("childid", "childExternalId") .put("childexternalid", "childExternalId").put("idexternohijo", "childExternalId") .put("idexternofilho", "childExternalId").put("nomenfant", "childLastName") .put("prenomenfant", "childFirstName").put("classeenfant", "childClasses") .put("nomdusageenfant", "childUsername").put("nomdefamilleenfant", "childLastName") .put("nomdefamilleeleve", "childLastName").put("classesenfants", "childClasses") .put("classeseleves", "childClasses").put("presencedevanteleves", "teaches") .put("fonction", "functions").put("funcion", "functions").put("function", "functions") .put("funcao", "functions").put("niveau", "level").put("regime", "accommodation") .put("filiere", "sector").put("cycle", "sector").put("mef", "module") .put("libellemef", "moduleName").put("boursier", "scholarshipHolder").put("transport", "transport") .put("statut", "status").put("codematiere", "fieldOfStudy").put("matiere", "fieldOfStudyLabels") .put("persreleleve", "relative").put("civilite", "title").put("civiliteresponsable", "title") .put("telephone", "homePhone").put("telefono", "homePhone").put("phone", "homePhone") .put("telefone", "homePhone").put("telephonedomicile", "homePhone") .put("telephonetravail", "workPhone").put("telefonotrabajo", "workPhone") .put("phonework", "workPhone").put("telefonetrabalho", "workPhone") .put("telephoneportable", "mobile").put("adresse", "address").put("adresse1", "address") .put("adresseresponsable", "address").put("direccion", "address").put("address", "address") .put("endereco", "address").put("adresse2", "address2").put("cp", "zipCode") .put("cpresponsable", "zipCode").put("codigopostal", "zipCode").put("postcode", "zipCode") .put("cp1", "zipCode").put("cp2", "zipCode2").put("ville", "city").put("communeresponsable", "city") .put("commune", "city").put("commune1", "city").put("commune2", "city2").put("ciudad", "city") .put("city", "city").put("cidade", "city").put("pays", "country").put("pais", "country") .put("country", "country").put("pays1", "country").put("pays2", "country2") .put("discipline", "classCategories").put("materia", "classCategories") .put("matiereenseignee", "subjectTaught").put("email", "email").put("correoelectronico", "email") .put("courriel", "email").put("professeurprincipal", "headTeacher").put("sexe", "gender") .put("attestationfournie", "ignore").put("autorisationsassociations", "ignore") .put("autorisationassociations", "ignore").put("autorisationsphotos", "ignore") .put("autorisationphoto", "ignore").put("decisiondepassage", "ignore").put("directeur", "ignore") .put("ine", "ine").put("identifiantclasse", "ignore").put("dateinscription", "ignore") .put("deuxiemeprenom", "ignore").put("troisiemeprenom", "ignore").put("communenaissance", "ignore") .put("deptnaissance", "ignore").put("paysnaissance", "ignore").put("etat", "ignore") .put("intervenant", "ignore").put("regroupement(s)", "ignore").put("dispositif(s)", "ignore") .put("", "ignore"); mappings.mergeIn(additionnalsMappings); namesMapping = mappings.getMap();/*from w w w. j av a 2 s .c om*/ relativeMapping = mappings.copy().put("prenomeleve", "childFirstName") .put("nomdusageeleve", "childUsername").getMap(); }
From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java
License:Open Source License
private void sendMergedEvent(String keepedUserId, String deletedUserId) { JsonObject body = new JsonObject().put("keepedUserId", keepedUserId).put("deletedUserId", deletedUserId); eb.publish(Feeder.USER_REPOSITORY, body.copy().put("action", "merge-users")); eventStore.createAndStoreEvent(Feeder.FeederEvent.MERGE_USER.name(), (UserInfos) null, body); }