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

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

Introduction

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

Prototype

public Object getValue(String key) 

Source Link

Document

Get the value with the specified key, as an Object with types respecting the limitations of JSON.

Usage

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

License:Open Source License

public String modifiableValidate(JsonObject object) {
    if (object == null) {
        return "Null object.";
    }/*w  w  w.j  av a  2 s .co m*/
    final Set<String> attributes = new HashSet<>(object.fieldNames());
    JsonObject generatedAttributes = null;
    for (String attr : attributes) {
        JsonObject v = validate.getJsonObject(attr);
        if (v == null || !modifiable.contains(attr)) {
            object.remove(attr);
        } else {
            Object value = object.getValue(attr);
            String validator = v.getString("validator");
            String type = v.getString("type", "");
            String err;
            switch (type) {
            case "string":
                if (!required.contains(attr)
                        && (value == null || (value instanceof String && ((String) value).isEmpty()))) {
                    err = null;
                } else {
                    err = validString(attr, value, validator);
                }
                break;
            case "array-string":
                if (!required.contains(attr)
                        && (value == null || (value instanceof JsonArray && ((JsonArray) value).size() == 0))) {
                    err = null;
                } else {
                    err = validStringArray(attr, value, validator);
                }
                break;
            case "boolean":
                err = validBoolean(attr, value);
                break;
            case "login-alias":
                err = validLoginAlias(attr, value, validator);
                break;
            default:
                err = "Missing type validator: " + type;
            }
            if (err != null) {
                return err;
            }
            if (value != null && generate.containsKey(attr)) {
                JsonObject g = generate.getJsonObject(attr);
                if (g != null && "displayName".equals(g.getString("generator"))) {
                    if (generatedAttributes == null) {
                        generatedAttributes = new JsonObject();
                    }
                    generatedAttributes.put(attr + SEARCH_FIELD, removeAccents(value.toString()).toLowerCase());
                }
            }
        }
    }
    if (generatedAttributes != null) {
        object.mergeIn(generatedAttributes);
    }
    JsonObject g = generate.getJsonObject("modified");
    if (g != null) {
        nowDate("modified", object);
    }
    return (object.size() > 0) ? null : "Empty object.";
}

From source file:org.entcore.infra.Starter.java

License:Open Source License

@Override
public void start() {
    try {//from  w  ww.  jav a 2  s.  co  m
        super.start();
        final LocalMap<Object, Object> serverMap = vertx.sharedData().getLocalMap("server");

        serverMap.put("signKey", config.getString("key", "zbxgKWuzfxaYzbXcHnK3WnWK" + Math.random()));
        CookieHelper.getInstance().init((String) vertx.sharedData().getLocalMap("server").get("signKey"), log);

        JsonObject swift = config.getJsonObject("swift");
        if (swift != null) {
            serverMap.put("swift", swift.encode());
        }
        JsonObject emailConfig = config.getJsonObject("emailConfig");
        if (emailConfig != null) {
            serverMap.put("emailConfig", emailConfig.encode());
        }
        JsonObject filesystem = config.getJsonObject("file-system");
        if (filesystem != null) {
            serverMap.put("file-system", filesystem.encode());
        }
        JsonObject neo4jConfig = config.getJsonObject("neo4jConfig");
        if (neo4jConfig != null) {
            serverMap.put("neo4jConfig", neo4jConfig.encode());
        }
        final String csp = config.getString("content-security-policy");
        if (isNotEmpty(csp)) {
            serverMap.put("contentSecurityPolicy", csp);
        }
        serverMap.put("gridfsAddress", config.getString("gridfs-address", "wse.gridfs.persistor"));
        //initModulesHelpers(node);

        /* sharedConf sub-object */
        JsonObject sharedConf = config.getJsonObject("sharedConf", new JsonObject());
        for (String field : sharedConf.fieldNames()) {
            serverMap.put(field, sharedConf.getValue(field));
        }

        vertx.sharedData().getLocalMap("skins")
                .putAll(config.getJsonObject("skins", new JsonObject()).getMap());

        final MessageConsumer<JsonObject> messageConsumer = vertx.eventBus()
                .localConsumer("app-registry.loaded");
        messageConsumer.handler(message -> {
            //            JsonSchemaValidator validator = JsonSchemaValidator.getInstance();
            //            validator.setEventBus(getEventBus(vertx));
            //            validator.setAddress(node + "json.schema.validator");
            //            validator.loadJsonSchema(getPathPrefix(config), vertx);
            registerGlobalWidgets(
                    config.getString("widgets-path", config.getString("assets-path", ".") + "/assets/widgets"));
            loadInvalidEmails();
            messageConsumer.unregister();
        });
    } catch (Exception ex) {
        log.error(ex.getMessage());
    }
    JsonObject eventConfig = config.getJsonObject("eventConfig", new JsonObject());
    EventStoreService eventStoreService = new MongoDbEventStore();
    EventStoreController eventStoreController = new EventStoreController(eventConfig);
    eventStoreController.setEventStoreService(eventStoreService);
    addController(eventStoreController);
    addController(new MonitoringController());
    addController(new EmbedController());
    if (config.getBoolean("antivirus", false)) {
        ClamAvService antivirusService = new ClamAvService();
        antivirusService.setVertx(vertx);
        antivirusService.setTimeline(new TimelineHelper(vertx, getEventBus(vertx), config));
        antivirusService.setRender(new Renders(vertx, config));
        antivirusService.init();
        AntiVirusController antiVirusController = new AntiVirusController();
        antiVirusController.setAntivirusService(antivirusService);
        addController(antiVirusController);
        vertx.deployVerticle(ExecCommandWorker.class.getName(), new DeploymentOptions().setWorker(true));
    }
}

From source file:org.entcore.timeline.events.DefaultTimelineEventStore.java

License:Open Source License

private JsonObject validAndGet(JsonObject json) {
    if (json != null) {
        JsonObject e = json.copy();
        for (String attr : json.fieldNames()) {
            if (!FIELDS.contains(attr) || e.getValue(attr) == null) {
                e.remove(attr);//from   w  ww  . j a  va  2s .co  m
            }
        }
        if (e.getMap().keySet().containsAll(REQUIRED_FIELDS)) {
            return e;
        }
    }
    return null;
}

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

License:Open Source License

@Override
public void update(String id, JsonObject data, Handler<Either<String, JsonObject>> handler) {
    StringBuilder sb = new StringBuilder();
    JsonArray values = new fr.wseduc.webutils.collections.JsonArray();
    for (String attr : data.fieldNames()) {
        if ("startDate".equals(attr) || "endDate".equals(attr)) {
            sb.append("\"" + attr + "\"").append(" = ?::timestamptz, ");
        } else if ("contents".equals(attr) || "profiles".equals(attr)) {
            sb.append("\"" + attr + "\"").append(" = ?::jsonb, ");
        } else {//from w w  w  .  j a  va2 s .c o m
            sb.append("\"" + attr + "\"").append(" = ?, ");
        }
        values.add(data.getValue(attr));
    }
    String query = "UPDATE " + resourceTable + " SET " + sb.toString() + "modified = NOW() " + "WHERE id = ? ";
    sql.prepared(query, values.add(parseId(id)), validRowsResultHandler(handler));
}

From source file:org.etourdot.vertx.marklogic.model.client.impl.DocumentImpl.java

License:Open Source License

public DocumentImpl(JsonObject jsonObject) {
    this();//from ww w. j  av a 2s .c  om
    requireNonNull(jsonObject);

    ofNullable(jsonObject.getString(URI)).ifPresent(this::uri);
    ofNullable(jsonObject.getValue(CONTENT)).ifPresent(this::contentObject);
    ofNullable(jsonObject.getJsonArray(COLLECTIONS)).ifPresent(this::collections);
    ofNullable(jsonObject.getJsonArray(PERMISSIONS)).ifPresent(this::permissions);
    ofNullable(jsonObject.getInteger(QUALITY)).ifPresent(this::quality);
    ofNullable(jsonObject.getJsonObject(PROPERTIES)).ifPresent(this::properties);
    ofNullable(jsonObject.getString(EXTENSION)).ifPresent(this::extension);
    ofNullable(jsonObject.getString(DIRECTORY)).ifPresent(this::directory);
    ofNullable(jsonObject.getLong(VERSION)).ifPresent(this::version);
    ofNullable(jsonObject.getString(EXTRACT)).ifPresent(this::extract);
    ofNullable(jsonObject.getString(LANG)).ifPresent(this::lang);
    ofNullable(jsonObject.getString(REPAIR)).ifPresent(this::repair);
    ofNullable(jsonObject.getString(FORMAT)).ifPresent(this::format);
    ofNullable(jsonObject.getString(MIME_TYPE)).ifPresent(this::contentType);
    if (!hasContentType()) {
        contentType(jsonObject.getString(CONTENT_TYPE));
    }
    forceFormatOrContentType();
}

From source file:org.etourdot.vertx.marklogic.model.options.RestApiOptions.java

License:Open Source License

public RestApiOptions(JsonObject jsonObject) {
    this();/*from  w w w. j a  v a  2 s. co m*/
    requireNonNull(jsonObject);

    ofNullable(jsonObject.getValue("remove-content")).ifPresent(this::removeContent);
    ofNullable(jsonObject.getValue("remove-modules")).ifPresent(this::removeModules);
    ofNullable(jsonObject.getString("retrieve-instance")).ifPresent(this::retrieveInstance);
    ofNullable(jsonObject.getString("retrieve-database")).ifPresent(this::retrieveDatabase);
    ofNullable(jsonObject.getJsonArray("rest-apis")).ifPresent(this::restApis);
    ofNullable(jsonObject.getJsonObject("rest-api")).ifPresent(this::restApi);
}

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

License:Apache License

private void handlePlaceOrder(RoutingContext routingContext) {
    routingContext.request().bodyHandler(buf -> {
        SpanContext spanCtx = tracer.extract(Format.Builtin.TEXT_MAP,
                new HttpHeadersExtractAdapter(routingContext.request().headers()));

        Span ordersConsumerSpan = tracer.buildSpan("POST").asChildOf(spanCtx).withTag("http.url", "/orders")
                .withTag("service", "OrderManager").withTag("transaction", "Place Order").start();

        JsonObject order = buf.toJsonObject();
        HttpServerResponse response = routingContext.response();

        if (orders.containsKey(order.getValue("id"))) {
            sendError(400, "Order id must not be defined", response, ordersConsumerSpan);
        } else {/*from w w  w.j  a v a  2  s .  com*/
            checkAccount(order, response, ordersConsumerSpan);
        }
    });
}

From source file:org.mkit.microservice.transfer.message.AccountMessageConverter.java

License:Apache License

public static void fromJson(JsonObject json, AccountMessage obj) {
    if (json.getValue("account") instanceof String) {
        obj.setAccount((String) json.getValue("account"));
    }//from   w  w w.j  av a  2s . c o  m
    if (json.getValue("amount") instanceof Number) {
        obj.setAmount(((Number) json.getValue("amount")).doubleValue());
    }
    if (json.getValue("transaction") instanceof String) {
        obj.setTransaction((String) json.getValue("transaction"));
    }
    if (json.getValue("transfer") instanceof String) {
        obj.setTransfer((String) json.getValue("transfer"));
    }
    if (json.getValue("type") instanceof String) {
        obj.setType(org.mkit.microservice.transfer.message.AccountMessage.Type
                .valueOf((String) json.getValue("type")));
    }
}

From source file:org.mkit.microservice.transfer.model.TransferConverter.java

License:Apache License

public static void fromJson(JsonObject json, Transfer obj) {
    if (json.getValue("amount") instanceof Number) {
        obj.setAmount(((Number) json.getValue("amount")).doubleValue());
    }//  ww  w  .j a v a 2s .com
    if (json.getValue("createdAt") instanceof Number) {
        obj.setCreatedAt(((Number) json.getValue("createdAt")).longValue());
    }
    if (json.getValue("fromAccount") instanceof String) {
        obj.setFromAccount((String) json.getValue("fromAccount"));
    }
    if (json.getValue("id") instanceof String) {
        obj.setId((String) json.getValue("id"));
    }
    if (json.getValue("issuer") instanceof String) {
        obj.setIssuer((String) json.getValue("issuer"));
    }
    if (json.getValue("message") instanceof String) {
        obj.setMessage((String) json.getValue("message"));
    }
    if (json.getValue("status") instanceof String) {
        obj.setStatus(
                org.mkit.microservice.transfer.model.Transfer.Status.valueOf((String) json.getValue("status")));
    }
    if (json.getValue("toAccount") instanceof String) {
        obj.setToAccount((String) json.getValue("toAccount"));
    }
    if (json.getValue("transaction") instanceof String) {
        obj.setTransaction((String) json.getValue("transaction"));
    }
}

From source file:org.sfs.util.ConfigHelper.java

License:Apache License

public static String getFieldOrEnv(JsonObject config, String name, String defaultValue) {
    String envVar = formatEnvVariable(name);
    //USED_ENV_VARS.add(envVar);
    if (config.containsKey(name)) {
        Object value = config.getValue(name);
        if (value != null) {
            String valueAsString = value.toString();
            log(name, envVar, name, valueAsString);
            return valueAsString;
        }/*  ww w  .j  av  a2s. c  om*/
    } else {
        String value = System.getenv(envVar);
        if (value != null) {
            log(name, envVar, envVar, value);
            return value;
        }
    }
    log(name, envVar, null, defaultValue);
    return defaultValue;
}