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

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

Introduction

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

Prototype

public Integer getInteger(String key, Integer def) 

Source Link

Document

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

Usage

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   ww  w . jav a2s.  c o  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.feeder.export.eliot.EtabEducNatExportProcessing.java

License:Open Source License

@Override
protected void count(final Handler<Integer> handler) {
    TransactionManager.executeTransaction(new Function<TransactionHelper, Message<JsonObject>>() {
        @Override/*from w w  w .  ja  v a 2  s  . c o  m*/
        public void apply(TransactionHelper value) {
            Structure.count(EliotExporter.ELIOT, value);
        }

        @Override
        public void handle(Message<JsonObject> result) {
            JsonArray r = result.body().getJsonArray("results");
            if ("ok".equals(result.body().getString("status")) && r != null && r.size() == 1) {
                JsonArray rs = r.getJsonArray(0);
                if (rs != null && rs.size() == 1) {
                    JsonObject row = rs.getJsonObject(0);
                    handler.handle(row.getInteger("nb", 0));
                    return;
                }
            }
            handler.handle(null);
        }
    });
}

From source file:org.entcore.feeder.export.eliot.PorteurENTExportProcessing.java

License:Open Source License

@Override
protected void count(final Handler<Integer> handler) {
    TransactionManager.executeTransaction(new Function<TransactionHelper, Message<JsonObject>>() {
        @Override//from   w  w w .  ja v  a2  s. c  om
        public void apply(TransactionHelper value) {
            Tenant.count(value);
        }

        @Override
        public void handle(Message<JsonObject> result) {
            JsonArray r = result.body().getJsonArray("results");
            if ("ok".equals(result.body().getString("status")) && r != null && r.size() == 1) {
                JsonArray rs = r.getJsonArray(0);
                if (rs != null && rs.size() == 1) {
                    JsonObject row = rs.getJsonObject(0);
                    handler.handle(row.getInteger("nb", 0));
                    return;
                }
            }
            handler.handle(null);
        }
    });
}

From source file:org.entcore.feeder.export.eliot.UserExportProcessing.java

License:Open Source License

@Override
protected void count(final Handler<Integer> handler) {
    TransactionManager.executeTransaction(new Function<TransactionHelper, Message<JsonObject>>() {
        @Override/*  w  w w . ja  v  a 2s  .  co  m*/
        public void apply(TransactionHelper value) {
            User.count(EliotExporter.ELIOT, profiles, value);
        }

        @Override
        public void handle(Message<JsonObject> result) {
            JsonArray r = result.body().getJsonArray("results");
            if ("ok".equals(result.body().getString("status")) && r != null && r.size() == 1) {
                JsonArray rs = r.getJsonArray(0);
                if (rs != null && rs.size() == 1) {
                    JsonObject row = rs.getJsonObject(0);
                    handler.handle(row.getInteger("nb", 0));
                    return;
                }
            }
            handler.handle(null);
        }
    });
}

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

License:Open Source License

public void deleteUser(final Message<JsonObject> message) {
    final JsonArray users = message.body().getJsonArray("users");
    if (users == null || users.size() == 0) {
        sendError(message, "Missing users.");
        return;//from w w w. java  2 s. c  o  m
    }
    String query = "MATCH (u:User)"
            + "WHERE u.id IN {users} AND (u.source IN ['MANUAL', 'CSV', 'CLASS_PARAM', 'BE1D'] OR HAS(u.disappearanceDate)) "
            + "return count(*) as count ";
    neo4j.execute(query, new JsonObject().put("users", users), new Handler<Message<JsonObject>>() {
        @Override
        public void handle(Message<JsonObject> event) {
            JsonArray res = event.body().getJsonArray("result");
            if ("ok".equals(event.body().getString("status")) && res != null && res.size() == 1) {
                JsonObject j = res.getJsonObject(0);
                if (users.size() == j.getInteger("count", 0)) {
                    executeTransaction(message, new VoidFunction<TransactionHelper>() {
                        @Override
                        public void apply(TransactionHelper tx) {
                            for (Object o : users) {
                                User.backupRelationship(o.toString(), tx);
                                User.preDelete(o.toString(), tx);
                            }
                        }
                    });
                } else {
                    sendError(message, "unauthorized.user");
                }
            } else {
                message.reply(event.body());
            }
        }
    });
}

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  ww .java2s . c  om*/
    }
    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.DefaultTimelineMailerService.java

License:Open Source License

public DefaultTimelineMailerService(Vertx vertx, JsonObject config) {
    super(vertx, config);
    eb = Server.getEventBus(vertx);/*from   w  w w.ja va2 s  .co  m*/
    EmailFactory emailFactory = new EmailFactory(this.vertx, config);
    emailSender = emailFactory.getSender();
    USERS_LIMIT = config.getInteger("users-loop-limit", 25);
}

From source file:org.entcore.timeline.Timeline.java

License:Open Source License

@Override
public void start() throws Exception {
    super.start();

    final Map<String, String> registeredNotifications = MapFactory.getSyncClusterMap("notificationsMap", vertx);
    final LocalMap<String, String> eventsI18n = vertx.sharedData().getLocalMap("timelineEventsI18n");
    final HashMap<String, JsonObject> lazyEventsI18n = new HashMap<>();

    final DefaultTimelineConfigService configService = new DefaultTimelineConfigService("timeline.config");
    configService.setRegisteredNotifications(registeredNotifications);
    final DefaultTimelineMailerService mailerService = new DefaultTimelineMailerService(vertx, config);
    mailerService.setConfigService(configService);
    mailerService.setRegisteredNotifications(registeredNotifications);
    mailerService.setEventsI18n(eventsI18n);
    mailerService.setLazyEventsI18n(lazyEventsI18n);

    final NotificationHelper notificationHelper = new NotificationHelper(vertx, configService);
    notificationHelper.setMailerService(mailerService);

    JsonObject pushNotif = config.getJsonObject("push-notif");

    final TimelineController timelineController = new TimelineController();
    timelineController.setConfigService(configService);
    timelineController.setMailerService(mailerService);
    timelineController.setRegisteredNotifications(registeredNotifications);
    timelineController.setEventsI18n(eventsI18n);
    timelineController.setLazyEventsI18n(lazyEventsI18n);

    if (pushNotif != null) {

        OAuth2Client googleOAuth2SSO = new OAuth2Client(URI.create(pushNotif.getString("uri")), null, null,
                null, pushNotif.getString("tokenUrn"), null, vertx, pushNotif.getInteger("poolSize", 16), true);
        OssFcm oss = new OssFcm(googleOAuth2SSO, pushNotif.getString("client_mail"),
                pushNotif.getString("scope"), pushNotif.getString("aud"), pushNotif.getString("url"),
                pushNotif.getString("key"));

        final DefaultPushNotifService pushNotifService = new DefaultPushNotifService(vertx, config, oss);
        pushNotifService.setEventsI18n(eventsI18n);
        pushNotifService.setConfigService(configService);
        timelineController.setPushNotifService(pushNotifService);
        notificationHelper.setPushNotifService(pushNotifService);
    }/*  w  ww .  j  a  v a  2 s .c  om*/

    timelineController.setNotificationHelper(notificationHelper);

    addController(new FlashMsgController());

    setRepositoryEvents(new FlashMsgRepositoryEventsSql());

    addController(timelineController);

    final String dailyMailingCron = config.getString("daily-mailing-cron", "0 0 2 * * ?");
    final String weeklyMailingCron = config.getString("weekly-mailing-cron", "0 0 5 ? * MON");
    final int dailyDayDelta = config.getInteger("daily-day-delta", -1);
    final int weeklyDayDelta = config.getInteger("weekly-day-delta", -1);

    try {
        new CronTrigger(vertx, dailyMailingCron)
                .schedule(new DailyMailingCronTask(mailerService, dailyDayDelta));
        new CronTrigger(vertx, weeklyMailingCron)
                .schedule(new WeeklyMailingCronTask(mailerService, weeklyDayDelta));
    } catch (ParseException e) {
        log.error("Failed to start mailing crons.");
    }
}

From source file:org.entcore.workspace.service.WorkspaceService.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);
    mongo = MongoDb.getInstance();/*from  w  w w.  j a  v  a 2s  .  c  om*/
    String node = (String) vertx.sharedData().getLocalMap("server").get("node");
    if (node == null) {
        node = "";
    }
    imageResizerAddress = node + config.getString("image-resizer-address", "wse.image.resizer");
    documentDao = new DocumentDao(mongo);
    notification = new TimelineHelper(vertx, eb, config);
    this.shareService = new MongoDbShareService(eb, mongo, "documents", securedActions, null);
    this.folderService = new DefaultFolderService(mongo, storage);
    this.threshold = config.getInteger("alertStorage", 80);
    eventStore = EventStoreFactory.getFactory().getEventStore(Workspace.class.getSimpleName());
    post("/documents/copy/:ids", "copyDocuments");
    put("/documents/move/:ids", "moveDocuments");
}

From source file:org.hawkular.apm.examples.vertx.opentracing.ordermanager.PlaceOrderHandler.java

License:Apache License

private void checkStock(RoutingContext routingContext, JsonObject order, HttpServerResponse response,
        Span parentSpan) {//from  w  w  w  .j  a va 2  s .co m
    Span getItemSpan = tracer.buildSpan("GetItem").asChildOf(parentSpan).start();
    tracer.inject(getItemSpan.context(), Format.Builtin.TEXT_MAP, new VertxMessageInjectAdapter(order));

    // Check stock
    routingContext.vertx().eventBus().send("InventoryManager.getItem", order, invresp -> {
        logger.fine("Getting inventory item");

        getItemSpan.finish();
        if (invresp.succeeded()) {
            logger.finest("Inventory response succeeded");
            JsonObject item = (JsonObject) invresp.result().body();
            if (order.getInteger("quantity", 1) <= item.getInteger("quantity", 1)) {
                logger.fine("Will put order");

                // Remove internal headers - necessary because we have had
                // to piggyback the APM state as a top level field in the
                // order JSON document - which now needs to be removed before
                // returning it to the end user.
                VertxMessageInjectAdapter.cleanup(order);

                // Assign id
                order.put("id", UUID.randomUUID().toString());
                orders.put(order.getString("id"), order);
                response.putHeader("content-type", "application/json").setStatusCode(202)
                        .end(order.encodePrettily());

                parentSpan.setTag("orderId", order.getString("id"));
                parentSpan.setTag("itemId", order.getString("itemId"));
                parentSpan.setTag("accountId", order.getString("accountId"));

                parentSpan.finish();

                orderConfirmed(routingContext, order, parentSpan);
            } else {
                logger.info("Out of stock");
                sendError(500, "Out of stock", response, parentSpan);
            }
        } else {
            logger.warning("Application failed");
            sendError(500, invresp.cause().getMessage(), response, parentSpan);
        }
    });
}