List of usage examples for io.vertx.core.json JsonObject getJsonArray
public JsonArray getJsonArray(String key, JsonArray def)
From source file:org.entcore.cas.services.EduMediaRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w w w.ja va 2 s.c o m*/ //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(EM_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes.add(createTextElement(EM_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_3", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(EM_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for Edumedia", e); } }
From source file:org.entcore.cas.services.EnglishAttackRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, final String userId, String service, final JsonObject data, final Document doc, final List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); if (log.isDebugEnabled()) { log.debug("START : prepareUserCas20 userId : " + userId); }//w w w . ja v a 2 s. com try { if (log.isDebugEnabled()) { log.debug("DATA : prepareUserCas20 data : " + data); } String query = "MATCH (u:`User` { id : {id}}) return u"; JsonObject params = new JsonObject().put("id", userId); neo.execute(query, params, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> m) { // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(EA_ID, data.getString("externalId"), doc)); } // Structures Element rootStructures = createElement(EA_STRUCTURE + "s", doc); for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; Element rootStructure = createElement(EA_STRUCTURE, doc); if (structure.containsKey("UAI")) { rootStructure.appendChild( createTextElement(EA_STRUCTURE_UAI, structure.getString("UAI"), doc)); } if (structure.containsKey("name")) { rootStructure.appendChild( createTextElement(EA_STRUCTURE_NAME, structure.getString("name"), doc)); } rootStructures.appendChild(rootStructure); } additionnalAttributes.add(rootStructures); // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_1", doc)); addStringArray(EA_CLASSE, "classes", "name", data, doc, additionnalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); // Email if (data.containsKey("email")) { additionnalAttributes.add(createTextElement(EA_EMAIL, data.getString("email"), doc)); } break; case "Teacher": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_3", doc)); addStringArray(EA_CLASSE, "classes", "name", data, doc, additionnalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); //Discipline Either<String, JsonObject> res = validUniqueResult(m); if (res.isRight()) { JsonObject j = res.right().getValue(); if (null != j.getJsonObject("u") && null != j.getJsonObject("u").getJsonObject("data") && null != j.getJsonObject("u").getJsonObject("data") .getJsonArray("functions")) { JsonArray jsonArrayFunctions = j.getJsonObject("u").getJsonObject("data") .getJsonArray("functions"); if (jsonArrayFunctions.size() > 0) { Element rootDisciplines = createElement(EA_DISCIPLINE + "s", doc); List<String> vTempListDiscipline = new ArrayList<>(); for (int i = 0; i < jsonArrayFunctions.size(); i++) { String fonction = jsonArrayFunctions.getString(i); String[] elements = fonction.split("\\$"); if (elements.length > 1) { String discipline = elements[elements.length - 2] + "$" + elements[elements.length - 1]; if (!vTempListDiscipline.contains(discipline)) { vTempListDiscipline.add(discipline); rootDisciplines.appendChild( createTextElement(EA_DISCIPLINE, discipline, doc)); } } else { log.error("Failed to get User functions userID, : " + userId + " fonction : " + fonction); } } additionnalAttributes.add(rootDisciplines); } } else { log.error("Failed to get User functions userID, user empty : " + userId + " j : " + j); } } else { log.error("Failed to get User functions userID : " + userId); } // Email if (data.containsKey("emailAcademy")) { additionnalAttributes .add(createTextElement(EA_EMAIL, data.getString("emailAcademy"), doc)); } else if (data.containsKey("email")) { additionnalAttributes.add(createTextElement(EA_EMAIL, data.getString("email"), doc)); } break; case "Relative": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(EA_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement(EA_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes .add(createTextElement(EA_FIRSTNAME, data.getString("firstName"), doc)); } } }); } catch (Exception e) { log.error("Failed to transform User for EnglishAttack", e); } if (log.isDebugEnabled()) { log.debug("START : prepareUserCas20 userId : " + userId); } }
From source file:org.entcore.cas.services.KneRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from ww w .j a v a 2 s . c om*/ String queryParams = new URI(service).getQuery(); String[] pairs; if (queryParams != null && queryParams.length() > 0 && (pairs = queryParams.split("&")).length > 0) { for (String pair : pairs) { String key = pair.substring(0, pair.indexOf('=')); if ("UAI".equals(key)) { String value = pair.substring(pair.indexOf('=') + 1); additionalAttributes.add(createTextElement("ENTPersonStructRattachUAI", value, doc)); for (Object o : data .getJsonArray("structureNodes", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (value.equals(structure.getString("UAI"))) { if (structure.containsKey("type")) { String type = structure.getString("type"); switch (type) { case "ECOLE DE NIVEAU ELEMENTAIRE": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "1ORD", doc)); break; case "COLLEGE": case "COLLEGE CLIMATIQUE": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "CLG", doc)); break; case "LYCEE D ENSEIGNEMENT GENERAL": case "LYCEE POLYVALENT": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "LYC", doc)); break; case "LYCEE PROFESSIONNEL": additionalAttributes .add(createTextElement("ENTStructureTypeStruct", "LP", doc)); break; default: additionalAttributes .add(createTextElement("ENTStructureTypeStruct", type, doc)); } } break; } } break; } } } Element rootProfiles; String profile = data.getJsonArray("type", new fr.wseduc.webutils.collections.JsonArray()).size() > 0 ? data.getJsonArray("type").getString(0) : ""; switch (profile) { case "Student": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_ELV", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", data.getString("module", ""), doc)); addArray("ENTEleveCodeEnseignement", "fieldOfStudy", data, doc, additionalAttributes, new DefaultMapper<String>()); addArray("ENTEleveClasse", "classes", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTEleveGroupe", "groups", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; case "Teacher": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_ENS", doc)); //rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_TUT", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); addArray("ENTAuxEnsClassesMatiere", "classesFieldOfStudy", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = matPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsGroupe", "groups", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsClasse", "classes", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = classGroupPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); addArray("ENTAuxEnsMEF", "modules", data, doc, additionalAttributes, new Mapper<String, String>() { String map(String input) { Matcher m = mefStatPattern.matcher(input); if (m.matches() && m.groupCount() >= 1) { return m.group(1); } return input; } }); break; case "Relative": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_TUT", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; case "Personnel": rootProfiles = createElement("ENTPersonProfils", doc); rootProfiles.appendChild(createTextElement("ENTPersonProfil", "National_DOC", doc)); additionalAttributes.add(rootProfiles); additionalAttributes.add(createTextElement("ENTEleveMEF", "", doc)); additionalAttributes.add(createTextElement("ENTEleveCodeEnseignements", "", doc)); additionalAttributes.add(createTextElement("ENTEleveClasses", "", doc)); additionalAttributes.add(createTextElement("ENTEleveGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClassesMatieres", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsGroupes", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsClasses", "", doc)); additionalAttributes.add(createTextElement("ENTAuxEnsMEFs", "", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for KNE", e); } }
From source file:org.entcore.cas.services.LabomepRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w ww . j a v a 2s . c o m*/ // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement("uid", data.getString("externalId"), doc)); } // administratives Structures first final List<String> uaiList = new ArrayList<>(); for (Object o : data.getJsonArray("administratives", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject structure = (JsonObject) o; final String uai = structure.getString("UAI"); if (!StringUtils.isEmpty(uai)) { uaiList.add(uai); additionnalAttributes.add(createTextElement("structures", uai, doc)); } } for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject structure = (JsonObject) o; final String uai = structure.getString("UAI"); if (!StringUtils.isEmpty(uai) && !uaiList.contains(uai)) { additionnalAttributes.add(createTextElement("structures", uai, doc)); } } // classes for (Object o : data.getJsonArray("classes", new fr.wseduc.webutils.collections.JsonArray())) { JsonObject classe = (JsonObject) o; additionnalAttributes.add(createTextElement("classes", classe.getString("name"), doc)); } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement("profile", "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement("profile", "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement("profile", "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement("profile", "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement("nom", data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes.add(createTextElement("prenom", data.getString("firstName"), doc)); } // Email if (data.containsKey("email")) { additionnalAttributes.add(createTextElement("email", data.getString("email"), doc)); } } catch (Exception e) { log.error("Failed to extract user's attributes for Labomep", e); } }
From source file:org.entcore.cas.services.LeSiteTvRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from w w w.j a va 2 s . c om*/ Element root = createElement(LSTV_ROOT, doc); // Uid if (data.containsKey("externalId")) { root.appendChild(createTextElement(LSTV_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { root.appendChild(createTextElement(LSTV_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": root.appendChild(createTextElement(LSTV_PROFILES, "National_1", doc)); break; case "Teacher": root.appendChild(createTextElement(LSTV_PROFILES, "National_3", doc)); break; case "Relative": root.appendChild(createTextElement(LSTV_PROFILES, "National_2", doc)); break; case "Personnel": root.appendChild(createTextElement(LSTV_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { root.appendChild(createTextElement(LSTV_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { root.appendChild(createTextElement(LSTV_FIRSTNAME, data.getString("firstName"), doc)); } // Email if (data.containsKey("email")) { root.appendChild(createTextElement(LSTV_EMAIL, data.getString("email"), doc)); } additionnalAttributes.add(root); } catch (Exception e) { log.error("Failed to transform User for LeSite.tv", e); } }
From source file:org.entcore.cas.services.MSELRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { // TODO Auto-generated method stub user.setUser(data.getString(principalAttributeName)); try {// w ww .j a va2s . c om //uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(MSEL_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(MSEL_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(MSEL_PROFILES, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for Mon stage en ligne", e); } }
From source file:org.entcore.cas.services.ProEPSRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/* ww w .j a v a 2s. co m*/ // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(UID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray())) { if (!(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes.add(createTextElement(STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(PROFILE, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(PROFILE, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(PROFILE, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(PROFILE, "National_4", doc)); break; } } catch (Exception e) { log.error("Failed to transform User for ProEPS", e); } }
From source file:org.entcore.cas.services.UniversalisRegisteredService.java
License:Open Source License
@Override protected void prepareUserCas20(User user, String userId, String service, JsonObject data, Document doc, List<Element> additionnalAttributes) { user.setUser(data.getString(principalAttributeName)); try {/*from www .ja v a2s . c o m*/ // Uid if (data.containsKey("externalId")) { additionnalAttributes.add(createTextElement(UNVS_ID, data.getString("externalId"), doc)); } // Structures for (Object o : data.getJsonArray("structures", new fr.wseduc.webutils.collections.JsonArray()) .getList()) { if (o == null || !(o instanceof JsonObject)) continue; JsonObject structure = (JsonObject) o; if (structure.containsKey("UAI")) { additionnalAttributes .add(createTextElement(UNVS_STRUCTURE_UAI, structure.getString("UAI"), doc)); } } // Profile switch (data.getString("type")) { case "Student": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_1", doc)); break; case "Teacher": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_3", doc)); break; case "Relative": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_2", doc)); break; case "Personnel": additionnalAttributes.add(createTextElement(UNVS_PROFILES, "National_4", doc)); break; } // Lastname if (data.containsKey("lastName")) { additionnalAttributes.add(createTextElement(UNVS_LASTNAME, data.getString("lastName"), doc)); } // Firstname if (data.containsKey("firstName")) { additionnalAttributes.add(createTextElement(UNVS_FIRSTNAME, data.getString("firstName"), doc)); } } catch (Exception e) { log.error("Failed to transform User for Universalis", e); } }
From source file:org.entcore.common.neo4j.Neo4jRest.java
License:Open Source License
@Override public void rollbackTransaction(int transactionId, final Handler<JsonObject> handler) { try {/* w w w. ja v a 2s. c om*/ HttpClientRequest req = nodeManager.getClient().delete(basePath + "/transaction/" + transactionId, new Handler<HttpClientResponse>() { @Override public void handle(final HttpClientResponse resp) { resp.bodyHandler(new Handler<Buffer>() { @Override public void handle(Buffer b) { logger.debug(b.toString()); if (resp.statusCode() != 404 && resp.statusCode() != 500) { JsonObject json = new JsonObject(b.toString("UTF-8")); if (json.getJsonArray("errors", new fr.wseduc.webutils.collections.JsonArray()).size() == 0) { json.remove("errors"); handler.handle(json); } else { handler.handle(new JsonObject().put("message", json.getJsonArray("errors", new fr.wseduc.webutils.collections.JsonArray()) .encode())); } } else { handler.handle(new JsonObject().put("message", resp.statusMessage())); } } }); } }); req.headers().add("Accept", "application/json; charset=UTF-8"); req.exceptionHandler(e -> logger.error("Error rollbacking transaction : " + transactionId, e)); req.end(); } catch (Neo4jConnectionException e) { ExceptionUtils.exceptionToJson(e); } }
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 w w .ja v a2 s .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); } }