List of usage examples for io.vertx.core.json JsonObject getString
public String getString(String key, String def)
From source file:org.entcore.common.notification.ConversationNotification.java
License:Open Source License
public ConversationNotification(Vertx vertx, EventBus eb, JsonObject config) { this.render = new Renders(vertx, config); this.neo = new Neo(vertx, eb, log); this.eb = eb; this.host = config.getString("host", "http://localhost:8009"); }
From source file:org.entcore.common.notification.TimelineHelper.java
License:Open Source License
public void notifyTimeline(final HttpServerRequest req, final String notificationName, UserInfos sender, final List<String> recipients, String resource, String subResource, final JsonObject params, final boolean disableAntiFlood) { notificationsLoader.getNotification(notificationName, notification -> { JsonArray r = new fr.wseduc.webutils.collections.JsonArray(); for (String userId : recipients) { r.add(new JsonObject().put("userId", userId).put("unread", 1)); }// w w w .j ava2 s . c om final JsonObject event = new JsonObject().put("action", "add") .put("type", notification.getString("type")) .put("event-type", notification.getString("event-type")).put("recipients", r) .put("recipientsIds", new fr.wseduc.webutils.collections.JsonArray(recipients)); if (resource != null) { event.put("resource", resource); } if (sender != null) { event.put("sender", sender.getUserId()); } if (subResource != null && !subResource.trim().isEmpty()) { event.put("sub-resource", subResource); } if (disableAntiFlood || params.getBoolean("disableAntiFlood", false)) { event.put("disableAntiFlood", true); } Long date = params.getLong("timeline-publish-date"); if (date != null) { event.put("date", new JsonObject().put("$date", date)); params.remove("timeline-publish-date"); } event.put("pushNotif", params.remove("pushNotif")); HttpServerRequest request; if (req == null) { request = new JsonHttpServerRequest(new JsonObject()); } else { request = req; } event.put("params", params).put("notificationName", notificationName).put("notification", notification) .put("request", new JsonObject().put("headers", new JsonObject().put("Host", Renders.getHost(request)) .put("X-Forwarded-Proto", Renders.getScheme(request)) .put("Accept-Language", request.headers().get("Accept-Language")))); eb.send(TIMELINE_ADDRESS, event, handlerToAsyncHandler(new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> event) { JsonObject result = event.body(); if ("error".equals(result.getString("status", "error"))) { log.error("Error in timeline notification : " + result.getString("message")); } } })); }); }
From source file:org.entcore.common.notification.TimelineNotificationsLoader.java
License:Open Source License
private void processNotification(final String path, final String type) { final File pathFile = new File(path); final String notificationName = pathFile.getName().substring(0, pathFile.getName().lastIndexOf('.')); final String propsFilePath = path.substring(0, path.lastIndexOf(".")) + ".json"; //final String templatePath = pathFile.getAbsolutePath().substring(pathFile.getAbsolutePath().indexOf("notify/")); vertx.fileSystem().readFile(path, new Handler<AsyncResult<Buffer>>() { public void handle(AsyncResult<Buffer> templateAsync) { if (templateAsync.failed()) { log.error("Cannot read template at path : " + path); return; }/*from w w w . ja va2s. co m*/ final String fullName = (type + "." + notificationName).toLowerCase(); //Default values final JsonObject notificationJson = new JsonObject().put("type", type.toUpperCase()) .put("event-type", notificationName.toUpperCase()) .put("app-name", Config.getConf().getString("app-name")) .put("app-address", Config.getConf().getString("app-address", "/")) .put("template", templateAsync.result().toString()) .put("defaultFrequency", Frequencies.defaultFrequency()) .put("restriction", Restrictions.defaultRestriction()).put("push-notif", false); vertx.fileSystem().exists(propsFilePath, new Handler<AsyncResult<Boolean>>() { public void handle(AsyncResult<Boolean> ar) { if (ar.succeeded()) { if (ar.result()) { vertx.fileSystem().readFile(propsFilePath, new Handler<AsyncResult<Buffer>>() { public void handle(AsyncResult<Buffer> ar) { if (ar.succeeded()) { JsonObject props = new JsonObject(ar.result().toString("UTF-8")); // Overrides registerNotification(fullName, notificationJson .put("defaultFrequency", props.getString("default-frequency", notificationJson .getString("defaultFrequency"))) .put("restriction", props.getString("restrict", notificationJson .getString("restriction"))) .put("push-notif", props.getBoolean("push-notif", false))); } else { registerNotification(fullName, notificationJson); } } }); } else { registerNotification(fullName, notificationJson); } } } }); } }); }
From source file:org.entcore.common.notification.ws.OssFcm.java
License:Open Source License
public void sendNotifications(final JsonObject message) throws Exception { getAccessToken(new Handler<String>() { @Override//from w w w . j a v a 2 s. c o m public void handle(String token) { if (token == null) { log.error("[OssFcm] Error get token"); return; } Map<String, String> headers = new HashMap<>(); headers.put("Content-type", "application/json"); headers.put("Accept-Language", message.getString("language", "fr")); client.postProtectedResource(url, token, headers, message.encode(), new Handler<HttpClientResponse>() { @Override public void handle(HttpClientResponse response) { if (response.statusCode() != 200) { log.error("[OssFcm.sendNotifications] request failed : " + response.statusMessage()); } } }); } }); }
From source file:org.entcore.common.storage.FileInfos.java
License:Open Source License
public JsonObject toJsonExcludeEmpty(JsonObject mapping) { if (mapping == null) { mapping = new JsonObject(); }/*w w w . j av a 2s .c o m*/ final JsonObject j = new JsonObject(); if (isNotEmpty(id)) { j.put(mapping.getString("id", "id"), id); } if (isNotEmpty(name)) { j.put(mapping.getString("name", "name"), name); } if (isNotEmpty(application)) { j.put(mapping.getString("application", "application"), application); } if (isNotEmpty(owner)) { j.put(mapping.getString("owner", "owner"), owner); } if (isNotEmpty(contentType)) { j.put(mapping.getString("contentType", "contentType"), contentType); } if (size != null) { j.put(mapping.getString("size", "size"), size); } return j; }
From source file:org.entcore.common.storage.impl.FileStorage.java
License:Open Source License
@Override public void writeToFileSystem(String[] ids, String destinationPath, JsonObject alias, final Handler<JsonObject> handler) { final AtomicInteger count = new AtomicInteger(ids.length); final JsonArray errors = new fr.wseduc.webutils.collections.JsonArray(); for (final String id : ids) { if (id == null || id.isEmpty()) { decrementWriteToFS(count, errors, handler); continue; }/*w w w . ja v a 2 s . c o m*/ final String d = destinationPath + File.separator + alias.getString(id, id); try { copyFile(getPath(id), d, new Handler<JsonObject>() { @Override public void handle(JsonObject event) { if (!"ok".equals(event.getString("status"))) { errors.add(event); } decrementWriteToFS(count, errors, handler); } }); } catch (FileNotFoundException e) { errors.add(new JsonObject().put("status", "error").put("message", "invalid.path")); decrementWriteToFS(count, errors, handler); log.warn(e.getMessage(), e); } } }
From source file:org.entcore.common.storage.impl.SwiftStorage.java
License:Open Source License
@Override public void writeToFileSystem(String[] ids, String destinationPath, JsonObject alias, final Handler<JsonObject> handler) { final AtomicInteger count = new AtomicInteger(ids.length); final JsonArray errors = new fr.wseduc.webutils.collections.JsonArray(); for (final String id : ids) { if (id == null || id.isEmpty()) { count.decrementAndGet();/* w w w .jav a 2 s . com*/ continue; } String d = destinationPath + File.separator + alias.getString(id, id); swiftClient.writeToFileSystem(id, d, new Handler<AsyncResult<String>>() { @Override public void handle(AsyncResult<String> event) { if (event.failed()) { errors.add(new JsonObject().put("id", id).put("message", event.cause().getMessage())); } if (count.decrementAndGet() <= 0) { JsonObject j = new JsonObject(); if (errors.size() == 0) { handler.handle(j.put("status", "ok")); } else { handler.handle( j.put("status", "error").put("errors", errors).put("message", errors.encode())); } } } }); } }
From source file:org.entcore.common.validation.ExtensionValidator.java
License:Open Source License
@Override protected void validate(JsonObject metadata, JsonObject context, Handler<AsyncResult<Void>> handler) { final String filename = metadata.getString("filename", ""); final int idx = filename.lastIndexOf('.'); if (idx > 0 && idx < (filename.length() - 1) && blockedExtension.contains(filename.substring(idx + 1).toLowerCase())) { handler.handle(new DefaultAsyncResult<Void>(new ValidationException("blocked.extension"))); } else {/*from w w w . ja va 2 s. co m*/ handler.handle(new DefaultAsyncResult<>((Void) null)); } }
From source file:org.entcore.conversation.controllers.ConversationController.java
License:Open Source License
@Override public void init(Vertx vertx, JsonObject config, RouteMatcher rm, Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) { super.init(vertx, config, rm, securedActions); /*/*from w w w . j a va 2 s . co m*/ this.conversationService = new DefaultConversationService(vertx, config.getString("app-name", Conversation.class.getSimpleName())); */ this.conversationService = new SqlConversationService(vertx, config.getString("db-schema", "conversation")); this.neoConversationService = new Neo4jConversationService(); notification = new TimelineHelper(vertx, eb, config); eventStore = EventStoreFactory.getFactory().getEventStore(Conversation.class.getSimpleName()); this.threshold = config.getInteger("alertStorage", 80); }
From source file:org.entcore.conversation.service.impl.ConversationRepositoryEvents.java
License:Open Source License
@Override public void deleteGroups(JsonArray groups) { SqlStatementsBuilder builder = new SqlStatementsBuilder(); String setTO = "UPDATE conversation.messages " + "SET " + "\"to\" = \"to\" - ?, " + "\"toName\" = COALESCE(\"toName\", '[]')::jsonb || (?)::jsonb, " + "\"displayNames\" = \"displayNames\" - (? || '$ $' || ? || '$ ') - (? || '$ $' || ? || '$' || ?) " + "WHERE \"to\" @> (?)::jsonb"; String setCC = "UPDATE conversation.messages " + "SET " + "\"cc\" = \"cc\" - ?, " + "\"ccName\" = COALESCE(\"ccName\", '[]')::jsonb || (?)::jsonb, " + "\"displayNames\" = \"displayNames\" - (? || '$ $' || ? || '$ ') - (? || '$ $' || ? || '$' || ?) " + "WHERE \"cc\" @> (?)::jsonb"; for (Object o : groups) { if (!(o instanceof JsonObject)) continue; JsonObject group = (JsonObject) o; JsonArray params = new fr.wseduc.webutils.collections.JsonArray(); params.add(group.getString("group", "")); params.add(new fr.wseduc.webutils.collections.JsonArray().add(group.getString("groupName", "")) .toString());/*from www. j a va 2s . c om*/ params.add(group.getString("group", "")); params.add(group.getString("groupName", "")); params.add(group.getString("group", "")); params.add(group.getString("groupName", "")); params.add(group.getString("groupName", "")); params.add(new fr.wseduc.webutils.collections.JsonArray().add(group.getString("group", "")).toString()); builder.prepared(setTO, params); builder.prepared(setCC, params); } sql.transaction(builder.build(), new Handler<Message<JsonObject>>() { public void handle(Message<JsonObject> event) { if (!"ok".equals(event.body().getString("status"))) { log.error("Error updating delete groups in conversation : " + event.body().encode()); } } }); }