Example usage for io.vertx.core.json JsonObject getBoolean

List of usage examples for io.vertx.core.json JsonObject getBoolean

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getBoolean.

Prototype

public Boolean getBoolean(String key, Boolean def) 

Source Link

Document

Like #getBoolean(String) but specifying a default value to return if there is no entry.

Usage

From source file:org.entcore.directory.services.impl.DefaultProfileService.java

License:Open Source License

@Override
public void blockProfiles(JsonObject profiles, Handler<Either<String, JsonObject>> handler) {
    final String query = "MATCH (p:Profile {name : {name}}) set p.blocked = {blocked}";
    final StatementsBuilder sb = new StatementsBuilder();
    for (String profile : profiles.fieldNames()) {
        sb.add(query, new JsonObject().put("name", profile).put("blocked",
                (profiles.getBoolean(profile, false) ? true : null)));
    }//from w ww  . ja va  2s.c  om
    neo4j.executeTransaction(sb.build(), null, true, validEmptyHandler(handler));
}

From source file:org.entcore.feeder.aaf.AAFHandler.java

License:Open Source License

private void addValueInAttribute(String s) throws SAXException {
    if (s == null || (s.isEmpty() && !"ENTAuxEnsClassesPrincipal".equals(currentAttribute)
            && !"mobile".equals(currentAttribute) && !"ENTPersonMobileSMS".equals(currentAttribute))) {
        return;/*from   w  ww  .j  av  a 2 s . c  o m*/
    }
    JsonObject j = mapping.getJsonObject(currentAttribute);
    if (j == null) {
        throw new SAXException("Unknown attribute " + currentAttribute);
    }
    if (currentStructure == null) {
        throw new SAXException("Value is found but structure isn't defined.");
    }
    String type = j.getString("type");
    String attribute = j.getString("attribute");
    final boolean prefix = j.getBoolean("prefix", false);
    if ("birthDate".equals(attribute) && !s.isEmpty()) {
        s = convertDate(s);
    }
    if (type != null && type.contains("array")) {
        JsonArray a = currentStructure.getJsonArray(attribute);
        if (a == null) {
            a = new fr.wseduc.webutils.collections.JsonArray();
            currentStructure.put(attribute, a);
        }
        if (!s.isEmpty()) {
            a.add(JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null)));
        }
    } else {
        Object v = JsonUtil.convert(s, type, (prefix ? processing.getAcademyPrefix() : null));
        if (!(v instanceof JsonUtil.None)) {
            currentStructure.put(attribute, v);
        }
    }
}

From source file:org.entcore.feeder.csv.CsvImportsLauncher.java

License:Open Source License

public CsvImportsLauncher(Vertx vertx, String path, JsonObject config, PostImport postImport) {
    this.vertx = vertx;
    this.path = path;
    this.profiles = config.getJsonObject("profiles");
    this.namePattern = Pattern.compile(config.getString("namePattern"));
    this.postImport = postImport;
    this.preDelete = config.getBoolean("preDelete", false);
}

From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java

License:Open Source License

public void mergeDuplicate(final Message<JsonObject> message, final TransactionHelper tx) {
    String userId1 = message.body().getString("userId1");
    String userId2 = message.body().getString("userId2");
    if (userId1 == null || userId2 == null || userId1.trim().isEmpty() || userId2.trim().isEmpty()) {
        message.reply(new JsonObject().put("status", "error").put("message", "invalid.id"));
        return;//from   w w  w.  j av a2  s  .c om
    }
    String query = "MATCH (u1:User {id: {userId1}})-[r:DUPLICATE]-(u2:User {id: {userId2}}) "
            + "RETURN DISTINCT u1.id as userId1, u1.source as source1, NOT(HAS(u1.activationCode)) as activatedU1, "
            + "u1.disappearanceDate as disappearanceDate1, u1.deleteDate as deleteDate1, "
            + "u2.id as userId2, u2.source as source2, NOT(HAS(u2.activationCode)) as activatedU2, "
            + "u2.disappearanceDate as disappearanceDate2, u2.deleteDate as deleteDate2";
    JsonObject params = new JsonObject().put("userId1", userId1).put("userId2", userId2);
    TransactionManager.getNeo4jHelper().execute(query, params, new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> event) {
            JsonArray res = event.body().getJsonArray("result");
            JsonObject error = new JsonObject().put("status", "error");
            if ("ok".equals(event.body().getString("status")) && res != null && res.size() == 1) {
                JsonObject r = res.getJsonObject(0);
                if (r.getBoolean("activatedU1", true) && r.getBoolean("activatedU2", true)) {
                    message.reply(error.put("message", "two.users.activated"));
                } else {
                    mergeDuplicate(r, message, tx);
                }
            } else if ("ok".equals(event.body().getString("status"))) {
                message.reply(error.put("message", "not.found.duplicate"));
            } else {
                message.reply(event.body());
            }
        }
    });
}

From source file:org.entcore.feeder.dictionary.structures.DuplicateUsers.java

License:Open Source License

private void mergeDuplicate(final JsonObject r, final Message<JsonObject> message, final TransactionHelper tx) {
    final String source1 = r.getString("source1");
    final String source2 = r.getString("source2");
    final boolean activatedU1 = r.getBoolean("activatedU1", false);
    final boolean activatedU2 = r.getBoolean("activatedU2", false);
    final String userId1 = r.getString("userId1");
    final String userId2 = r.getString("userId2");
    final boolean missing1 = r.getLong("disappearanceDate1") != null || r.getLong("deleteDate1") != null;
    final boolean missing2 = r.getLong("disappearanceDate2") != null || r.getLong("deleteDate2") != null;
    final JsonObject error = new JsonObject().put("status", "error");
    if (source1 != null && source1.equals(source2) && notDeduplicateSource.contains(source1) && !missing1
            && !missing2) {//w w  w. ja v a 2 s .c o  m
        message.reply(error.put("message", "two.users.in.same.source"));
        return;
    }
    String query;
    JsonObject params = new JsonObject();
    if ((activatedU1 && prioritySource(source1) >= prioritySource(source2))
            || (activatedU2 && prioritySource(source1) <= prioritySource(source2))
            || (!activatedU1 && !activatedU2)) {
        query = SIMPLE_MERGE_QUERY;
        if (prioritySource(source1) == prioritySource(source2) && notDeduplicateSource.contains(source1)) {
            if (!missing1 && activatedU1) {
                params.put("userId1", userId1).put("userId2", userId2);
            } else if (!missing2 && activatedU2) {
                params.put("userId1", userId2).put("userId2", userId1);
            } else {
                query = SWITCH_MERGE_QUERY;
                if (activatedU1) {
                    params.put("userId1", userId1).put("userId2", userId2);
                } else {
                    params.put("userId1", userId2).put("userId2", userId1);
                }
            }
        } else {
            if (activatedU1) {
                params.put("userId1", userId1).put("userId2", userId2);
            } else if (activatedU2) {
                params.put("userId1", userId2).put("userId2", userId1);
            } else {
                if (prioritySource(source1) > prioritySource(source2)) {
                    params.put("userId1", userId1).put("userId2", userId2);
                } else {
                    params.put("userId1", userId2).put("userId2", userId1);
                }
            }
        }
    } else if ((activatedU1 && prioritySource(source1) < prioritySource(source2))
            || (activatedU2 && prioritySource(source1) > prioritySource(source2))) {
        query = SWITCH_MERGE_QUERY;
        if (activatedU1) {
            params.put("userId1", userId1).put("userId2", userId2);
        } else {
            params.put("userId1", userId2).put("userId2", userId1);
        }
    } else {
        message.reply(error.put("message", "invalid.merge.case"));
        return;
    }
    if (tx != null) {
        tx.add(INCREMENT_RELATIVE_SCORE, params);
        tx.add(query, params);
        sendMergedEvent(params.getString("userId1"), params.getString("userId2"));
        message.reply(new JsonObject().put("status", "ok"));
    } else {
        try {
            TransactionHelper txl = TransactionManager.getTransaction();
            txl.add(INCREMENT_RELATIVE_SCORE, params);
            txl.add(query, params);
            txl.commit(new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> event) {
                    if ("ok".equals(event.body().getString("status"))) {
                        log.info("Merge duplicates : " + r.encode());
                        if (updateCourses) {
                            AbstractTimetableImporter.updateMergedUsers(event.body().getJsonArray("results"));
                        }
                        sendMergedEvent(params.getString("userId1"), params.getString("userId2"));
                    }
                    message.reply(event.body());
                }
            });
        } catch (TransactionException e) {
            message.reply(error.put("message", "invalid.transaction"));
        }
    }
}

From source file:org.entcore.feeder.Feeder.java

License:Open Source License

@Override
public void start() {
    super.start();
    String node = (String) vertx.sharedData().getLocalMap("server").get("node");
    if (node == null) {
        node = "";
    }/*from w  w  w.  ja v  a  2  s . c om*/
    String neo4jConfig = (String) vertx.sharedData().getLocalMap("server").get("neo4jConfig");
    if (neo4jConfig != null) {
        neo4j = Neo4j.getInstance();
        neo4j.init(vertx, new JsonObject(neo4jConfig));
    }
    MongoDb.getInstance().init(vertx.eventBus(), node + "wse.mongodb.persistor");
    TransactionManager.getInstance().setNeo4j(neo4j);
    EventStoreFactory.getFactory().setVertx(vertx);
    defaultFeed = config.getString("feeder", "AAF");
    feeds.put("AAF", new AafFeeder(vertx, getFilesDirectory("AAF")));
    feeds.put("AAF1D", new Aaf1dFeeder(vertx, getFilesDirectory("AAF1D")));
    feeds.put("CSV", new CsvFeeder(vertx, config.getJsonObject("csvMappings", new JsonObject())));
    final long deleteUserDelay = config.getLong("delete-user-delay", 90 * 24 * 3600 * 1000l);
    final long preDeleteUserDelay = config.getLong("pre-delete-user-delay", 90 * 24 * 3600 * 1000l);
    final String deleteCron = config.getString("delete-cron", "0 0 2 * * ? *");
    final String preDeleteCron = config.getString("pre-delete-cron", "0 0 3 * * ? *");
    final String importCron = config.getString("import-cron");
    final JsonObject imports = config.getJsonObject("imports");
    final JsonObject preDelete = config.getJsonObject("pre-delete");
    final TimelineHelper timeline = new TimelineHelper(vertx, eb, config);
    try {
        new CronTrigger(vertx, deleteCron).schedule(new User.DeleteTask(deleteUserDelay, eb, vertx));
        if (preDelete != null) {
            if (preDelete.size() == ManualFeeder.profiles.size()
                    && ManualFeeder.profiles.keySet().containsAll(preDelete.fieldNames())) {
                for (String profile : preDelete.fieldNames()) {
                    final JsonObject profilePreDelete = preDelete.getJsonObject(profile);
                    if (profilePreDelete == null || profilePreDelete.getString("cron") == null
                            || profilePreDelete.getLong("delay") == null)
                        continue;
                    new CronTrigger(vertx, profilePreDelete.getString("cron")).schedule(
                            new User.PreDeleteTask(profilePreDelete.getLong("delay"), profile, timeline));
                }
            }
        } else {
            new CronTrigger(vertx, preDeleteCron)
                    .schedule(new User.PreDeleteTask(preDeleteUserDelay, timeline));
        }
        if (imports != null) {
            if (feeds.keySet().containsAll(imports.fieldNames())) {
                for (String f : imports.fieldNames()) {
                    final JsonObject i = imports.getJsonObject(f);
                    if (i != null && i.getString("cron") != null) {
                        new CronTrigger(vertx, i.getString("cron"))
                                .schedule(new ImporterTask(vertx, f, i.getBoolean("auto-export", false),
                                        config.getLong("auto-export-delay", 1800000l)));
                    }
                }
            } else {
                logger.error("Invalid imports configuration.");
            }
        } else if (importCron != null && !importCron.trim().isEmpty()) {
            new CronTrigger(vertx, importCron).schedule(new ImporterTask(vertx, defaultFeed,
                    config.getBoolean("auto-export", false), config.getLong("auto-export-delay", 1800000l)));
        }
    } catch (ParseException e) {
        logger.fatal(e.getMessage(), e);
        vertx.close();
        return;
    }
    Validator.initLogin(neo4j, vertx);
    manual = new ManualFeeder(neo4j);
    duplicateUsers = new DuplicateUsers(config.getBoolean("timetable", true),
            config.getBoolean("autoMergeOnlyInSameStructure", true), vertx.eventBus());
    postImport = new PostImport(vertx, duplicateUsers, config);
    vertx.eventBus().localConsumer(config.getString("address", FEEDER_ADDRESS), this);
    switch (config.getString("exporter", "")) {
    case "ELIOT":
        exporter = new EliotExporter(config.getString("export-path", "/tmp"),
                config.getString("export-destination"), config.getBoolean("concat-export", false),
                config.getBoolean("delete-export", true), vertx);
        break;
    }
    final JsonObject edt = config.getJsonObject("edt");
    if (edt != null) {
        final String pronotePrivateKey = edt.getString("pronote-private-key");
        if (isNotEmpty(pronotePrivateKey)) {
            edtUtils = new EDTUtils(vertx, pronotePrivateKey,
                    config.getString("pronote-partner-name", "NEO-Open"));
            final String edtPath = edt.getString("path");
            final String edtCron = edt.getString("cron");
            if (isNotEmpty(edtPath) && isNotEmpty(edtCron)) {
                try {
                    new CronTrigger(vertx, edtCron).schedule(new ImportsLauncher(vertx, edtPath, postImport,
                            edtUtils, config.getBoolean("udt-user-creation", true)));
                } catch (ParseException e) {
                    logger.error("Error in cron edt", e);
                }
            }
        }
    }
    final JsonObject udt = config.getJsonObject("udt");
    if (udt != null) {
        final String udtPath = udt.getString("path");
        final String udtCron = udt.getString("cron");
        if (isNotEmpty(udtPath) && isNotEmpty(udtCron)) {
            try {
                new CronTrigger(vertx, udtCron).schedule(new ImportsLauncher(vertx, udtPath, postImport,
                        edtUtils, config.getBoolean("udt-user-creation", true)));
            } catch (ParseException e) {
                logger.error("Error in cron udt", e);
            }
        }
    }
    final JsonObject csv = config.getJsonObject("csv");
    if (csv != null) {
        final String csvPath = csv.getString("path");
        final String csvCron = csv.getString("cron");
        final JsonObject csvConfig = csv.getJsonObject("config");
        if (isNotEmpty(csvPath) && isNotEmpty(csvCron) && csvConfig != null) {
            try {
                new CronTrigger(vertx, csvCron)
                        .schedule(new CsvImportsLauncher(vertx, csvPath, csvConfig, postImport));
            } catch (ParseException e) {
                logger.error("Error in cron csv", e);
            }
        }
    }
    I18n.getInstance().init(vertx);
}

From source file:org.entcore.infra.controllers.MonitoringController.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);
    dbCheckTimeout = config.getLong("dbCheckTimeout", 5000l);
    postgresql = config.getBoolean("sql", true);
}

From source file:org.entcore.timeline.controllers.TimelineController.java

License:Open Source License

public void init(Vertx vertx, JsonObject config, RouteMatcher rm,
        Map<String, fr.wseduc.webutils.security.SecuredAction> securedActions) {
    super.init(vertx, config, rm, securedActions);
    store = new DefaultTimelineEventStore();
    timelineHelper = new TimelineHelper(vertx, eb, config);
    antiFlood = new TTLSet<>(config.getLong("antiFloodDelay", 3000l), vertx,
            config.getLong("antiFloodClear", 3600 * 1000l));
    refreshTypesCache = config.getBoolean("refreshTypesCache", false);
}

From source file:org.entcore.timeline.controllers.TimelineController.java

License:Open Source License

@BusAddress("wse.timeline")
public void busApi(final Message<JsonObject> message) {
    if (message == null) {
        return;//from   w  w w  . j  a va2s  .co  m
    }
    final JsonObject json = message.body();
    if (json == null) {
        message.reply(new JsonObject().put("status", "error").put("message", "Invalid body."));
        return;
    }

    final Handler<JsonObject> handler = new Handler<JsonObject>() {
        public void handle(JsonObject event) {
            message.reply(event);
        }
    };

    String action = json.getString("action");
    if (action == null) {
        log.warn("Invalid action.");
        message.reply(new JsonObject().put("status", "error").put("message", "Invalid action."));
        return;
    }

    switch (action) {
    case "add":
        final String sender = json.getString("sender");
        if (sender == null || sender.startsWith("no-reply") || json.getBoolean("disableAntiFlood", false)
                || antiFlood.add(sender)) {
            store.add(json, new Handler<JsonObject>() {
                public void handle(JsonObject result) {
                    notificationHelper.sendImmediateNotifications(
                            new JsonHttpServerRequest(json.getJsonObject("request")), json);
                    handler.handle(result);
                }
            });
            if (refreshTypesCache && eventTypes != null && !eventTypes.contains(json.getString("type"))) {
                eventTypes = null;
            }
        } else {
            message.reply(new JsonObject().put("status", "error").put("message", "flood"));
        }
        break;
    case "get":
        UserInfos u = new UserInfos();
        u.setUserId(json.getString("recipient"));
        u.setExternalId(json.getString("externalId"));
        store.get(u, null, json.getInteger("offset", 0), json.getInteger("limit", 25), null, false, handler);
        break;
    case "delete":
        store.delete(json.getString("resource"), handler);
        break;
    case "deleteSubResource":
        store.deleteSubResource(json.getString("sub-resource"), handler);
    case "list-types":
        store.listTypes(new Handler<JsonArray>() {
            @Override
            public void handle(JsonArray types) {
                message.reply(new JsonObject().put("status", "ok").put("types", types));
            }
        });
        break;
    default:
        message.reply(new JsonObject().put("status", "error").put("message", "Invalid action."));
    }
}

From source file:org.entcore.timeline.services.impl.DefaultPushNotifService.java

License:Open Source License

private void sendUsers(final String notificationName, final JsonObject notification, final JsonArray userList,
        final JsonObject notificationProperties, boolean typeNotification, boolean typeData) {

    for (Object userObj : userList) {
        final JsonObject userPref = ((JsonObject) userObj);

        JsonObject notificationPreference = userPref.getJsonObject("preferences", new JsonObject())
                .getJsonObject("config", new JsonObject()).getJsonObject(notificationName, new JsonObject());

        if (notificationPreference.getBoolean("push-notif", notificationProperties.getBoolean("push-notif"))
                && !TimelineNotificationsLoader.Restrictions.INTERNAL.name()
                        .equals(notificationPreference.getString("restriction",
                                notificationProperties.getString("restriction")))
                && !TimelineNotificationsLoader.Restrictions.HIDDEN.name()
                        .equals(notificationPreference.getString("restriction",
                                notificationProperties.getString("restriction")))
                && userPref.getJsonArray("tokens") != null && userPref.getJsonArray("tokens").size() > 0) {
            for (Object token : userPref.getJsonArray("tokens")) {
                processMessage(notification, "fr", typeNotification, typeData, new Handler<JsonObject>() {
                    @Override/*from ww  w . j a v  a  2 s. c om*/
                    public void handle(final JsonObject message) {
                        try {
                            ossFcm.sendNotifications(
                                    new JsonObject().put("message", message.put("token", (String) token)));
                        } catch (Exception e) {
                            log.error("[sendNotificationToUsers] Issue while sending notification ("
                                    + notificationName + ").", e);

                        }
                    }
                });
            }

        }
    }
}