List of usage examples for io.vertx.core.json JsonArray getValue
public Object getValue(int pos)
From source file:org.entcore.conversation.service.impl.DefaultConversationService.java
License:Open Source License
private void sendWithoutAttachments(final String parentMessageId, String messageId, UserInfos user, final Handler<Either<String, JsonObject>> result) { String usersQuery;// w w w . ja v a 2 s . c o m JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId) .put("draft", State.DRAFT.name()).put("outbox", "OUTBOX").put("inbox", "INBOX") .put("sent", State.SENT.name()).put("true", true); if (parentMessageId != null && !parentMessageId.trim().isEmpty()) { // reply usersQuery = "MATCH (m:ConversationMessage { id : {parentMessageId}}) " + "WITH (COLLECT(visibles.id) + coalesce(m.to, '') + coalesce(m.cc, '') + coalesce(m.from, '')) as vis " + "MATCH (v:Visible) " + "WHERE v.id IN vis " + "WITH DISTINCT v "; params.put("parentMessageId", parentMessageId); } else { usersQuery = "WITH visibles as v "; } String query = usersQuery + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage) " + "WHERE (v: User or v:Group) " + "AND message.id = {messageId} AND message.state = {draft} AND message.from = {userId} AND " + "(v.id IN message.to OR v.id IN message.cc) " + "WITH DISTINCT u, message, (v.id + '$' + coalesce(v.displayName, ' ') + '$' + " + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' ')) as dNames " + "MATCH u-[:HAS_CONVERSATION]->(c:Conversation {active:{true}})" + "-[:HAS_CONVERSATION_FOLDER]->(f:ConversationSystemFolder {name:{inbox}}) " + "CREATE UNIQUE f-[:HAS_CONVERSATION_MESSAGE { unread: {true} }]->message " + "WITH COLLECT(c.userId) as sentIds, COLLECT(u) as users, message, " + "COLLECT(distinct dNames) as displayNames " + "MATCH (s:User {id : {userId}})-[:HAS_CONVERSATION]->(:Conversation)" + "-[:HAS_CONVERSATION_FOLDER]->(fOut:ConversationSystemFolder {name : {outbox}}), " + "message<-[r:HAS_CONVERSATION_MESSAGE]-(fDraft:ConversationSystemFolder {name : {draft}}) " + "SET message.state = {sent}, " + "message.displayNames = displayNames + (s.id + '$' + coalesce(s.displayName, ' ') + '$ $ ') " + "CREATE UNIQUE fOut-[:HAS_CONVERSATION_MESSAGE { insideFolder: r.insideFolder }]->message " + "DELETE r " + "RETURN EXTRACT(u IN FIlTER(x IN users WHERE NOT(x.id IN sentIds)) | u.displayName) as undelivered, " + "EXTRACT(u IN FIlTER(x IN users WHERE x.id IN sentIds AND NOT(x.activationCode IS NULL)) " + "| u.displayName) as inactive, LENGTH(sentIds) as sent, " + "sentIds, message.id as id, message.subject as subject"; findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() { @Override public void handle(JsonArray event) { if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) { result.handle(new Either.Right<String, JsonObject>(event.getJsonObject(0))); } else { result.handle(new Either.Left<String, JsonObject>("conversation.send.error")); } } }); }
From source file:org.entcore.conversation.service.impl.DefaultConversationService.java
License:Open Source License
private void sendWithAttachments(final String parentMessageId, final String messageId, JsonArray attachments, final UserInfos user, final Handler<Either<String, JsonObject>> result) { long totalAttachmentsSize = 0l; for (Object o : attachments) { totalAttachmentsSize = totalAttachmentsSize + ((JsonObject) o).getLong("size", 0l); }//from w ww.j a v a 2s .com final String usersQuery; JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId) .put("draft", State.DRAFT.name()).put("outbox", "OUTBOX").put("inbox", "INBOX") .put("sent", State.SENT.name()).put("attachmentsSize", totalAttachmentsSize).put("true", true); if (parentMessageId != null && !parentMessageId.trim().isEmpty()) { // reply usersQuery = "MATCH (m:ConversationMessage { id : {parentMessageId}}) " + "WITH (COLLECT(visibles.id) + coalesce(m.to, '') + coalesce(m.cc, '') + coalesce(m.from, '')) as vis " + "MATCH (v:Visible) " + "WHERE v.id IN vis " + "WITH DISTINCT v "; params.put("parentMessageId", parentMessageId); } else { usersQuery = "WITH visibles as v "; } String query = usersQuery + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage)-[:HAS_ATTACHMENT]->(attachment: MessageAttachment) " + "WHERE (v: User or v:Group) " + "AND message.id = {messageId} AND message.state = {draft} AND message.from = {userId} AND " + "(v.id IN message.to OR v.id IN message.cc) " + "WITH DISTINCT u, message, (v.id + '$' + coalesce(v.displayName, ' ') + '$' + " + "coalesce(v.name, ' ') + '$' + coalesce(v.groupDisplayName, ' ')) as dNames, COLLECT(distinct attachment.id) as attachments " + "MATCH (ub: UserBook)<-[:USERBOOK]-(u)-[:HAS_CONVERSATION]->(c:Conversation {active:{true}})" + "-[:HAS_CONVERSATION_FOLDER]->(f:ConversationSystemFolder {name:{inbox}}) " + "WHERE (ub.quota - ub.storage) >= {attachmentsSize} " + "CREATE UNIQUE f-[:HAS_CONVERSATION_MESSAGE { unread: {true}, attachments: attachments }]->message " + "SET ub.storage = ub.storage + {attachmentsSize} " + "WITH message, COLLECT(c.userId) as sentIds, COLLECT(distinct u) as users, " + "COLLECT(distinct dNames) as displayNames " + "MATCH (s:User {id : {userId}})-[:HAS_CONVERSATION]->(:Conversation)" + "-[:HAS_CONVERSATION_FOLDER]->(fOut:ConversationSystemFolder {name : {outbox}}), " + "message<-[r:HAS_CONVERSATION_MESSAGE]-(fDraft:ConversationSystemFolder {name : {draft}}) " + "SET message.state = {sent}, " + "message.displayNames = displayNames + (s.id + '$' + coalesce(s.displayName, ' ') + '$ $ ') " + "CREATE UNIQUE fOut-[:HAS_CONVERSATION_MESSAGE { insideFolder: r.insideFolder, attachments: r.attachments }]->message " + "DELETE r " + "RETURN sentIds, message.id as id"; findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() { @Override public void handle(JsonArray event) { if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) { JsonObject resultObj = event.getJsonObject(0); JsonArray sentIds = resultObj.getJsonArray("sentIds"); String messageId = resultObj.getString("id"); String query = usersQuery + "MATCH v<-[:IN*0..1]-(u:User), (message:ConversationMessage) " + "WHERE (v: User or v:Group) " + "AND message.id = {messageId} AND message.from = {userId} AND " + "(v.id IN message.to OR v.id IN message.cc) " + "RETURN EXTRACT(user IN FIlTER(x IN COLLECT(u) WHERE NOT(x.id IN {sentIds}))|user.displayName) as undelivered, {sentIds} as sentIds, [] as inactive, " + "{sentIdsLength} as sent, message.id as id, message.subject as subject"; JsonObject params = new JsonObject().put("userId", user.getUserId()).put("messageId", messageId) .put("sentIds", sentIds).put("sentIdsLength", sentIds.size()); if (parentMessageId != null && !parentMessageId.trim().isEmpty()) { params.put("parentMessageId", parentMessageId); } findVisibles(eb, user.getUserId(), query, params, true, true, false, new Handler<JsonArray>() { @Override public void handle(JsonArray event) { if (event != null && event.size() == 1 && (event.getValue(0) instanceof JsonObject)) { result.handle(new Either.Right<String, JsonObject>(event.getJsonObject(0))); } else { result.handle(new Either.Left<String, JsonObject>("conversation.send.error")); } } }); } else { result.handle(new Either.Left<String, JsonObject>("conversation.send.error")); } } }); }
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 w w w .ja v a 2 s.co 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.perfcake.reporting.destination.c3chart.C3ChartData.java
License:Apache License
/** * Checks whether all values in the field are null (except for the first index column). * * @param a//from www .j av a2 s . c o m * The array to be checked. * @return True if and only if all values in the field are null. */ private static boolean isAllNull(final JsonArray a) { int i = 1; while (i < a.size()) { if (a.getValue(i) != null) { return false; } i++; } return true; }