List of usage examples for io.vertx.core.json JsonArray copy
@Override
public JsonArray copy()
From source file:org.entcore.common.notification.ConversationNotification.java
License:Open Source License
public void notify(final HttpServerRequest request, String from, JsonArray to, JsonArray cc, String subject, String message, final Handler<Either<String, JsonObject>> result) { if (cc == null) { cc = new fr.wseduc.webutils.collections.JsonArray(); }/*from w w w .j av a2s. c o m*/ if (subject == null || message == null || to == null || from == null) { result.handle(new Either.Left<String, JsonObject>("Conversation notification : invalid parameters")); log.warn("Conversation notification : invalid parameters"); return; } JsonArray dest = to.copy(); for (Object o : cc) { dest.add(o); } String language = I18n.acceptLanguage(request); if (language == null || language.trim().isEmpty()) { language = "fr"; } else { String[] langs = language.split(","); language = langs[0]; } String displayName = i18n.translate("no-reply", Renders.getHost(request), language); final JsonObject m = new JsonObject() .put("message", new JsonObject().put("to", to).put("cc", cc).put("subject", subject).put("body", message)) .put("action", "send").put("userId", "no-reply-" + language).put("username", displayName) .put("request", new JsonObject().put("path", request.path()).put("headers", new JsonObject().put("Accept-Language", I18n.acceptLanguage(request)))); String query = "MATCH (u:User { id : {noReplyId}}) " + "WITH count(*) as exists " + "WHERE exists = 0 " + "CREATE (u:User:Visible {id : {noReplyId}, displayName : {noReplyName}})"; JsonObject params = new JsonObject().put("noReplyName", displayName) .put("noReplyId", "no-reply-" + language).put("dest", dest); StatementsBuilder sb = new StatementsBuilder().add(query, params); sb.add("MATCH (dest:User), (u:User {id : {noReplyId}}) " + "WHERE dest.id IN {dest} " + "CREATE UNIQUE u-[:COMMUNIQUE_DIRECT]->dest ", params); neo.executeTransaction(sb.build(), null, true, new Handler<Message<JsonObject>>() { @Override public void handle(Message<JsonObject> message) { if ("ok".equals(message.body().getString("status"))) { eb.send(CONVERSATION_ADDRESS, m, handlerToAsyncHandler(Neo4jResult.validUniqueResultHandler(result))); } else { result.handle(new Either.Left<String, JsonObject>(message.body().getString("message"))); } } }); }