Example usage for io.vertx.core.json JsonArray add

List of usage examples for io.vertx.core.json JsonArray add

Introduction

In this page you can find the example usage for io.vertx.core.json JsonArray add.

Prototype

public JsonArray add(Object value) 

Source Link

Document

Add an Object to the JSON array.

Usage

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addFailedUser(String filename, String key, JsonObject props, String... errors) {
    final String file = "error." + filename;
    JsonArray f = result.getJsonObject("errors").getJsonArray(file);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        result.getJsonObject("errors").put(file, f);
    }/*  ww  w  . j av  a  2s . c  om*/
    String error = i18n.translate(key, I18n.DEFAULT_DOMAIN, acceptLanguage, errors);
    props.put("error", error);
    f.add(props);
    log.error(error + " :\n" + Arrays.asList(props));
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addErrorByFile(String filename, String key, String... errors) {
    final String file = "error." + filename;
    JsonArray f = result.getJsonObject("errors").getJsonArray(file);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        result.getJsonObject("errors").put(file, f);
    }//from  www .j  a v  a  2s.c  o  m
    String error = i18n.translate(key, I18n.DEFAULT_DOMAIN, acceptLanguage, errors);
    f.add(error);
    log.error(error);
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addSoftErrorByFile(String file, String key, String... errors) {
    JsonObject softErrors = result.getJsonObject("softErrors");
    if (softErrors == null) {
        softErrors = new JsonObject();
        result.put("softErrors", softErrors);
    }//from   w  ww  .  j av  a 2s.  c o m
    JsonArray f = softErrors.getJsonArray(file);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        softErrors.put(file, f);
    }
    String error = i18n.translate(key, I18n.DEFAULT_DOMAIN, acceptLanguage, errors);
    f.add(error);
    log.error(error);
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addUser(String file, JsonObject props) {
    JsonArray f = result.getJsonObject("files").getJsonArray(file);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        result.getJsonObject("files").put(file, f);
    }//from  w  ww  .  j a v a 2  s.  c  o  m
    f.add(props);
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addProfile(String profile) {
    JsonArray f = result.getJsonArray(PROFILES);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        result.put(PROFILES, f);//from   w ww .  j  a va 2 s  . c o  m
    }
    f.add(profile);
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public void addIgnored(String file, String reason, JsonObject object) {
    JsonArray f = result.getJsonObject("ignored").getJsonArray(file);
    if (f == null) {
        f = new fr.wseduc.webutils.collections.JsonArray();
        result.getJsonObject("ignored").put(file, f);
    }// w w  w  . j  av a2 s.  com
    f.add(new JsonObject().put("reason", reason).put("object", object));
}

From source file:org.entcore.feeder.utils.Report.java

License:Open Source License

public JsonArray getUsersExternalId() {
    final JsonArray res = new fr.wseduc.webutils.collections.JsonArray();
    for (String f : result.getJsonObject("files").fieldNames()) {
        JsonArray a = result.getJsonObject("files").getJsonArray(f);
        if (a != null) {
            for (Object o : a) {
                if (!(o instanceof JsonObject))
                    continue;
                final String externalId = ((JsonObject) o).getString("externalId");
                if (externalId != null) {
                    res.add(externalId);
                }/*from w  w  w  .j a va 2  s  .  c  o  m*/
            }
        }
    }
    return res;
}

From source file:org.entcore.feeder.utils.Validator.java

License:Open Source License

protected static void initLogins(Neo4j neo4j, final long startInit, final boolean remove) {
    String query = "MATCH (u:User) RETURN COLLECT(DISTINCT u.login) as logins, COLLECT(DISTINCT u.loginAlias) as loginAliases";
    neo4j.execute(query, new JsonObject(), new Handler<Message<JsonObject>>() {
        @Override// w w w . j  ava2  s.c  om
        public void handle(Message<JsonObject> message) {
            JsonArray r = message.body().getJsonArray("result");
            if ("ok".equals(message.body().getString("status")) && r != null && r.size() == 1) {
                JsonArray l = (r.getJsonObject(0)).getJsonArray("logins");
                JsonArray aliases = (r.getJsonObject(0)).getJsonArray("loginAliases");

                for (Object alias : aliases) {
                    l.add(alias);
                }

                if (l != null) {
                    final Set<Object> tmp = new HashSet<>(l.getList());
                    if (remove) {
                        for (Object key : logins.keySet()) {
                            if (!tmp.contains(key)) {
                                logins.remove(key);
                            } else {
                                tmp.remove(key);
                            }
                        }
                        putLogin(tmp);
                    } else {
                        putLogin(tmp);
                    }
                }
            }
        }

        protected void putLogin(Set<Object> tmp) {
            for (Object o : tmp) {
                logins.putIfAbsent(o, "");
            }
            log.info("Init delay : " + (System.currentTimeMillis() - startInit));
        }
    });
}

From source file:org.entcore.infra.controllers.MonitoringController.java

License:Open Source License

@Get("/monitoring/versions")
@SecuredAction(value = "", type = ActionType.RESOURCE)
@ResourceFilter(AdminFilter.class)
public void checkVersions(final HttpServerRequest request) {
    final JsonArray versions = new fr.wseduc.webutils.collections.JsonArray();
    LocalMap<String, String> versionMap = vertx.sharedData().getLocalMap("versions");
    for (Map.Entry<String, String> entry : versionMap.entrySet()) {
        versions.add(new JsonObject().put(entry.getKey(), entry.getValue()));
    }/* w w  w .j a  v  a 2  s.  c om*/
    Renders.renderJson(request, versions);
}

From source file:org.entcore.portal.controllers.PortalController.java

License:Open Source License

@Override
public void init(final Vertx vertx, JsonObject config, RouteMatcher rm,
        Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) {
    super.init(vertx, config, rm, securedActions);
    this.staticRessources = vertx.sharedData().getLocalMap("staticRessources");
    dev = "dev".equals(config.getString("mode"));
    assetsPath = config.getString("assets-path", ".");
    JsonObject skins = new JsonObject(vertx.sharedData().<String, Object>getLocalMap("skins"));
    defaultSkin = config.getString("skin", "raw");
    themes = new HashMap<>();
    themesDetails = new HashMap<>();
    this.hostSkin = new HashMap<>();
    for (final String domain : skins.fieldNames()) {
        final String skin = skins.getString(domain);
        this.hostSkin.put(domain, skin);
        ThemeUtils.availableThemes(vertx, assetsPath + "/assets/themes/" + skin + "/skins", false,
                new Handler<List<String>>() {
                    @Override// www .j  a  va 2s. c  o m
                    public void handle(List<String> event) {
                        themes.put(skin, event);
                        JsonArray a = new fr.wseduc.webutils.collections.JsonArray();
                        for (final String s : event) {
                            String path = assetsPath + "/assets/themes/" + skin + "/skins/" + s + "/";
                            final JsonObject j = new JsonObject().put("_id", s).put("path",
                                    path.substring(assetsPath.length()));
                            if ("default".equals(s)) {
                                vertx.fileSystem().readFile(path + "/details.json",
                                        new Handler<AsyncResult<Buffer>>() {
                                            @Override
                                            public void handle(AsyncResult<Buffer> event) {
                                                if (event.succeeded()) {
                                                    JsonObject d = new JsonObject(event.result().toString());
                                                    j.put("displayName", d.getString("displayName"));
                                                } else {
                                                    j.put("displayName", s);
                                                }
                                            }
                                        });
                            } else {
                                j.put("displayName", s);
                            }
                            a.add(j);
                        }
                        themesDetails.put(skin, a);
                    }
                });
    }
    eventStore = EventStoreFactory.getFactory().getEventStore(Portal.class.getSimpleName());
    adminConsoleEventStore = EventStoreFactory.getFactory().getEventStore(ADMIN_CONSOLE_MODULE);
    vertx.sharedData().getLocalMap("server").put("assetPath", assetsPath);
}