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

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

Introduction

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

Prototype

public JsonArray() 

Source Link

Document

Create an empty instance

Usage

From source file:org.sfs.vo.ServiceDef.java

License:Apache License

public JsonObject toJsonObject() {
    JsonObject jsonObject = new JsonObject().put("id", id).put("update_ts", toDateTimeString(getLastUpdate()))
            .put("master_node", master).put("data_node", dataNode).put("document_count", documentCount)
            .put("available_processors", availableProcessors).put("free_memory", freeMemory)
            .put("max_memory", maxMemory).put("total_memory", totalMemory);

    if (fileSystem != null) {
        JsonObject jsonFileSystem = fileSystem.toJsonObject();
        jsonObject = jsonObject.put("file_system", jsonFileSystem);
    }/*from w w  w .j  a v  a  2 s.co m*/

    JsonArray jsonListeners = new JsonArray();
    for (HostAndPort publishAddress : publishAddresses) {
        jsonListeners.add(publishAddress.toString());
    }
    jsonObject.put("publish_addresses", jsonListeners);

    JsonArray jsonVolumes = new JsonArray();
    for (XVolume<? extends XVolume> xVolume : volumes) {
        jsonVolumes.add(xVolume.toJsonObject());
    }
    jsonObject.put("volumes", jsonVolumes);
    return jsonObject;
}

From source file:org.sfs.vo.XObject.java

License:Apache License

public JsonObject toJsonObject() {
    JsonObject document = new JsonObject();

    checkState(parent != null, "container cannot be null");
    checkState(parent.getParent() != null, "account cannot be null");

    document.put("account_id", parent.getParent().getId());
    document.put("container_id", parent.getId());
    document.put("node_id", nodeId);
    document.put("owner_guid", ownerGuid);

    JsonArray versionsJsonArray = new JsonArray();
    for (TransientVersion transientVersion : versions) {
        versionsJsonArray.add(transientVersion.toJsonObject());
    }/* w  ww. jav a 2  s. c  o m*/
    document.put("versions", versionsJsonArray);
    document.put("version_count", versions.size());
    Optional<TransientVersion> oOldestVersion = getOldestVersion();
    if (oOldestVersion.isPresent()) {
        document.put("oldest_version_ts", toDateTimeString(oOldestVersion.get().getCreateTs()));
    } else {
        document.put("oldest_version_ts", (String) null);
    }

    document.put("create_ts", toDateTimeString(getCreateTs()));
    document.put("update_ts", toDateTimeString(getUpdateTs()));

    return document;
}

From source file:org.sfs.vo.XVersion.java

License:Apache License

public T merge(JsonObject document) {
    setDeleted(document.getBoolean("deleted"));
    setDeleteMarker(document.getBoolean("delete_marker"));

    setContentDisposition(document.getString("content_disposition"));
    setContentType(document.getString("content_type"));
    setContentEncoding(document.getString("content_encoding"));
    setContentLength(document.getLong("content_length"));
    setEtag(document.getBinary("etag"));
    setContentMd5(document.getBinary("content_md5"));
    setContentSha512(document.getBinary("content_sha512"));
    setDeleteAt(document.getLong("delete_at"));
    setServerSideEncryption(document.getBoolean("server_side_encryption"));
    setObjectManifest(document.getString("object_manifest"));
    setStaticLargeObject(document.getBoolean("static_large_object"));

    JsonArray metadataJsonObject = document.getJsonArray("metadata", new JsonArray());
    metadata.withJsonObject(metadataJsonObject);

    this.segments.clear();
    JsonArray jsonSegments = document.getJsonArray("segments", new JsonArray());
    for (Object o : jsonSegments) {
        JsonObject segmentDocument = (JsonObject) o;
        Long segmentId = segmentDocument.getLong("id");
        checkNotNull(segmentId, "Segment id cannot be null");
        TransientSegment transientSegment = new TransientSegment(this, segmentId).merge(segmentDocument);
        segments.add(transientSegment);//from  w w w .  ja va2 s  . c  o  m
    }

    String createTimestamp = document.getString("create_ts");
    String updateTimestamp = document.getString("update_ts");

    if (createTimestamp != null) {
        setCreateTs(fromDateTimeString(createTimestamp));
    }
    if (updateTimestamp != null) {
        setUpdateTs(fromDateTimeString(updateTimestamp));
    }
    return (T) this;
}

From source file:org.sfs.vo.XVersion.java

License:Apache License

public JsonObject toJsonObject() {
    JsonObject document = new JsonObject();
    document.put("id", id);
    document.put("deleted", deleted);
    document.put("verified", size(readableSegments()) == segments.size());
    document.put("delete_marker", deleteMarker);

    document.put("etag", etag);
    document.put("content_md5", contentMd5);
    document.put("content_sha512", contentSha512);
    document.put("content_type", contentType);
    document.put("content_encoding", contentEncoding);
    document.put("content_disposition", contentDisposition);
    document.put("content_length", contentLength);
    document.put("server_side_encryption", useServerSideEncryption());
    document.put("object_manifest", objectManifest);
    document.put("static_large_object", staticLargeObject);
    document.put("delete_at", deleteAt);

    JsonArray jsonSegments = new JsonArray();
    for (TransientSegment segment : segments) {
        JsonObject segmentDocument = segment.toJsonObject();
        jsonSegments.add(segmentDocument);
    }//w  ww.  j  av  a2s . c om
    document.put("segments", jsonSegments);

    document.put("metadata", getMetadata().toJsonObject());

    document.put("create_ts", toDateTimeString(getCreateTs()));

    document.put("update_ts", toDateTimeString(getUpdateTs()));

    return document;
}

From source file:org.sub.bug.entity.BugConverter.java

License:Apache License

public static void toJson(Bug obj, JsonObject json) {
    if (obj.getBugDateClosed() != null) {
        json.put("bugDateClosed", obj.getBugDateClosed());
    }//w  ww .j a  v  a 2s .  c  o m
    if (obj.getBugDateReported() != null) {
        json.put("bugDateReported", obj.getBugDateReported());
    }
    if (obj.getBugDescription() != null) {
        json.put("bugDescription", obj.getBugDescription());
    }
    if (obj.getBugDeveloper() != null) {
        json.put("bugDeveloper", obj.getBugDeveloper().toJson());
    }
    if (obj.getBugId() != null) {
        json.put("bugId", obj.getBugId());
    }
    if (obj.getBugReporter() != null) {
        json.put("bugReporter", obj.getBugReporter());
    }
    if (obj.getModule() != null) {
        json.put("module", obj.getModule());
    }
    if (obj.getModuleName() != null) {
        json.put("moduleName", obj.getModuleName());
    }
    if (obj.getProblemLogs() != null) {
        JsonArray array = new JsonArray();
        obj.getProblemLogs().forEach(item -> array.add(item.toJson()));
        json.put("problemLogs", array);
    }
}

From source file:pt.davidafsilva.ushortx.persistence.DatabaseVerticle.java

License:Open Source License

/**
 * Queries the database for an url entry with the identifier specified in the message
 *
 * @param message the message from where to extract the identifier and to reply from
 *//*from   w  w  w  .ja  v  a  2s .c o  m*/
private void findById(final Message<JsonObject> message) {
    LOGGER.info("incoming find request: " + message.body());
    connect(connection -> {
        // validate the identifier
        final Optional<Long> id = Optional.ofNullable(message.body().getLong("id"));
        if (!id.isPresent()) {
            connection.close();
            message.fail(2, "invalid identifier");
            return;
        }

        // create the query parameters
        final JsonArray queryParams = new JsonArray().add(id.get());

        // execute the query
        connection.queryWithParams(FIND_BY_ID_QUERY, queryParams,
                FIND_QUERY_RESULT_HANDLER.apply(message, connection));
    }, Optional.of(cause -> message.fail(1, "unavailable resources")));
}

From source file:pt.davidafsilva.ushortx.persistence.DatabaseVerticle.java

License:Open Source License

/**
 * Saves at the database the url specified in the message, if non-existent. Otherwise the same
 * entry is used./*from w  w w . j  a  va2 s. c om*/
 *
 * @param message the message from where to extract the url data and to reply from
 */
private void saveUrl(final Message<JsonObject> message) {
    LOGGER.info("incoming save request: " + message.body());
    connect(connection -> {
        // validate the url
        final Optional<String> url = Optional.ofNullable(message.body().getString("url"));
        if (!url.isPresent()) {
            connection.close();
            message.fail(2, "invalid url");
            return;
        }

        // create the update parameters
        final JsonArray updateParams = new JsonArray().add(url.get());

        // execute the update
        connection.updateWithParams(INSERT_URL_STATEMENT, updateParams,
                INSERT_URL_RESULT_HANDLER.apply(message, connection));
    }, Optional.of(cause -> message.fail(1, "unavailable resources")));
}

From source file:se.liquidbytes.jel.owfs.DeviceDatabase.java

License:Apache License

/**
 * Create lookup table of supported device types. Should only be needed to run once.
 *
 * @return/*ww  w  .  j  a v a2s .  c  o  m*/
 */
private static Map<String, JsonObject> createDatabase() {
    Map<String, JsonObject> db = new ConcurrentHashMap<>();

    //--- TEMPERATURE DEVICES ---------------------------------------------------------------------
    JsonObject type = new JsonObject().put("typeId", "DS18S20").put("familyId", "10").put("name", "DS18S20")
            .put("description",
                    "High-Precision 1-Wire Digital Thermometer. It has an operating temperature range of -55C to +125C and is accurate to 0.5C over the range of -10C to +85C.")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS18S20.pdf"))
            .put("valueType", "number").put("maxValue", "125").put("minValue", "-55")
            .put("minSampleDelay", "1000").put("temperatureSensor", true).put("valueReadPath", "/latesttemp");
    db.put("DS18S20", type);

    type = new JsonObject().put("typeId", "DS18B20").put("familyId", "28").put("name", "DS18B20").put(
            "description",
            "High-Precision 1-Wire Digital Thermometer. It has an operating temperature range of -55C to +125C and is accurate to 0.5C over the range of -10C to +85C.")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS18B20.pdf"))
            .put("valueType", "number").put("maxValue", "125").put("minValue", "-55")
            .put("minSampleDelay", "1000").put("temperatureSensor", true).put("valueReadPath", "/latesttemp");
    db.put(type.getString("typeId"), type);

    type = new JsonObject().put("typeId", "DS1825").put("familyId", "3B").put("name", "DS1825").put(
            "description",
            "High-Precision 1-Wire Digital Thermometer. It has an operating temperature range of -55C to +125C and is accurate to 0.5C over the range of -10C to +85C.")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS1825.pdf"))
            .put("valueType", "number").put("maxValue", "125").put("minValue", "-55")
            .put("minSampleDelay", "1000").put("temperatureSensor", true).put("valueReadPath", "/latesttemp");
    db.put(type.getString("typeId"), type);

    type = new JsonObject().put("typeId", "DS1920").put("familyId", "10").put("name", "DS1920")
            .put("description", "iButton 1-Wire Digital Thermometer.")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS1920.pdf"))
            .put("valueType", "number").put("maxValue", "100").put("minValue", "-55")
            .put("minSampleDelay", "300").put("temperatureSensor", true).put("valueReadPath", "/latesttemp");
    db.put(type.getString("typeId"), type);

    type = new JsonObject().put("typeId", "DS1822").put("familyId", "22").put("name", "DS1822")
            .put("description", "1-Wire Digital Thermometer.")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS1822.pdf"))
            .put("valueType", "number").put("maxValue", "100").put("minValue", "-55")
            .put("minSampleDelay", "300").put("temperatureSensor", true).put("valueReadPath", "/latesttemp");
    db.put(type.getString("typeId"), type);

    //--- SWITCH DEVICES ---------------------------------------------------------------------
    type = new JsonObject().put("typeId", "DS2408").put("familyId", "29").put("name", "DS2408")
            .put("description", "1-Wire 8 channel addressable switch")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS2408.pdf"))
            .put("valueType", "number").put("minSampleDelay", "100").put("valueReadPath", "/sensed.ALL")
            .put("valueWritePath", "/PIO.ALL")
            .put("alarmingMask", SwitchAlarmingDeviceListener.ALARMING_MASK_8_SWITCHES)
            .put("initCommands", new JsonArray().add(new JsonObject().put("path", "/strobe") //TODO: This should accually only be run when using this device as an output.
                    .put("value", "1")))
            .put("childDevices",
                    new JsonArray()
                            .add(new JsonObject().put("idSuffix", "1").put("name", "port 1")
                                    .put("valueReadPath", "/sensed.0").put("valueWritePath", "/PIO.0"))
                            .add(new JsonObject().put("idSuffix", "2").put("name", "port 2")
                                    .put("valueReadPath", "/sensed.1").put("valueWritePath", "/PIO.1"))
                            .add(new JsonObject().put("idSuffix", "3").put("name", "port 3")
                                    .put("valueReadPath", "/sensed.2").put("valueWritePath", "/PIO.2"))
                            .add(new JsonObject().put("idSuffix", "4").put("name", "port 4")
                                    .put("valueReadPath", "/sensed.3").put("valueWritePath", "/PIO.3"))
                            .add(new JsonObject().put("idSuffix", "5").put("name", "port 5")
                                    .put("valueReadPath", "/sensed.4").put("valueWritePath", "/PIO.4"))
                            .add(new JsonObject().put("idSuffix", "6").put("name", "port 6")
                                    .put("valueReadPath", "/sensed.5").put("valueWritePath", "/PIO.5"))
                            .add(new JsonObject().put("idSuffix", "7").put("name", "port 7")
                                    .put("valueReadPath", "/sensed.6").put("valueWritePath", "/PIO.6"))
                            .add(new JsonObject().put("idSuffix", "8").put("name", "port 8")
                                    .put("valueReadPath", "/sensed.7").put("valueWritePath", "/PIO.7")));
    db.put(type.getString("typeId"), type);

    type = new JsonObject().put("typeId", "DS2406").put("familyId", "12").put("name", "DS2406")
            .put("description", "1-Wire dual-channel adressable switch with 1kbit Memory")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS2406.pdf"))
            .put("valueType", "number").put("minSampleDelay", "100").put("valueReadPath", "/sensed.ALL")
            .put("valueWritePath", "/PIO.ALL")
            .put("alarmingMask", SwitchAlarmingDeviceListener.ALARMING_MASK_2_SWITCHES).put("childDevices",
                    new JsonArray()
                            .add(new JsonObject().put("idSuffix", "1").put("name", "port A")
                                    .put("valueReadPath", "/sensed.A").put("valueWritePath", "/PIO.A"))
                            .add(new JsonObject().put("idSuffix", "2").put("name", "port B")
                                    .put("valueReadPath", "/sensed.B").put("valueWritePath", "/PIO.B")));
    db.put(type.getString("typeId"), type);

    type = new JsonObject().put("typeId", "DS2413").put("familyId", "3A").put("name", "DS2413")
            .put("description", "1-Wire dual-channel adressable switch")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS2413.pdf"))
            .put("valueType", "number").put("minSampleDelay", "100").put("valueReadPath", "/sensed.ALL")
            .put("valueWritePath", "/PIO.ALL")
            .put("alarmingMask", SwitchAlarmingDeviceListener.ALARMING_MASK_2_SWITCHES).put("childDevices",
                    new JsonArray()
                            .add(new JsonObject().put("idSuffix", "1").put("name", "port A")
                                    .put("valueReadPath", "/sensed.A").put("valueWritePath", "/PIO.A"))
                            .add(new JsonObject().put("idSuffix", "2").put("name", "port B")
                                    .put("valueReadPath", "/sensed.B").put("valueWritePath", "/PIO.B")));
    db.put(type.getString("typeId"), type);

    //--- VOLTAGE DEVICES ---------------------------------------------------------------------
    type = new JsonObject().put("typeId", "DS2450").put("familyId", "20").put("name", "DS2450")
            .put("description", "1-Wire Quad A/D Converter")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS2450.pdf"))
            .put("valueType", "number").put("minSampleDelay", "100").put("valueReadPath", "/volt.ALL")
            .put("childDevices",
                    new JsonArray()
                            .add(new JsonObject().put("idSuffix", "1").put("name", "voltage input A")
                                    .put("valueReadPath", "/volt.A"))
                            .add(new JsonObject().put("idSuffix", "2").put("name", "voltage input B")
                                    .put("valueReadPath", "/volt.B"))
                            .add(new JsonObject().put("idSuffix", "3").put("name", "voltage input C")
                                    .put("valueReadPath", "/volt.C"))
                            .add(new JsonObject().put("idSuffix", "4").put("name", "voltage input D")
                                    .put("valueReadPath", "/volt.D")));
    db.put(type.getString("typeId"), type);
    //--- COUNTER DEVICES ---------------------------------------------------------------------
    type = new JsonObject().put("typeId", "DS2423").put("familyId", "1D").put("name", "DS2423")
            .put("description", "4kbit 1-Wire RAM with Counter")
            .put("manufacturer",
                    new JsonObject().put("name", "maxim integrated")
                            .put("homepage", "https://www.maximintegrated.com")
                            .put("datasheets", "https://datasheets.maximintegrated.com/en/ds/DS2423.pdf"))
            .put("valueType", "number").put("minSampleDelay", "100").put("valueReadPath", "/counters.ALL")
            .put("childDevices",
                    new JsonArray()
                            .add(new JsonObject().put("idSuffix", "1").put("name", "counter input A")
                                    .put("valueReadPath", "/counters.A"))
                            .add(new JsonObject().put("idSuffix", "2").put("name", "counter input B")
                                    .put("valueReadPath", "/counters.B")));
    db.put(type.getString("typeId"), type);

    return db;
}

From source file:se.liquidbytes.jel.owfs.OwfsAdapter.java

License:Apache License

/**
 * Returns a list of all supported devices by this adapter.
 *
 * @param message eventbus message.//from www  . j  a  va  2 s .c om
 */
private void getSupportedDevices(Message message) {

    JsonArray result = new JsonArray();

    for (JsonObject device : DeviceDatabase.getSuportedDeviceTypes()) {
        result.add(new JsonObject().put("typeId", device.getString("typeId"))
                .put("name", device.getString("name")).put("description", device.getString("description"))
                .put("manufacturer", device.getJsonObject("manufacturer")));
    }

    message.reply(constructReply(result));
}

From source file:se.liquidbytes.jel.owfs.OwfsAdapter.java

License:Apache License

/**
 * Returns a list of all available devices on 1-wire bus.
 *
 * @return list of devices.//from   w ww.  ja v a2 s.  c  om
 */
private JsonArray getAvailableDevices() {
    JsonArray result = new JsonArray();

    List<JsonObject> deviceList = deviceLookup.values().stream()
            .sorted(comparing((JsonObject d) -> d.getString("type"))
                    .thenComparing((JsonObject d) -> d.getString("name")))
            .collect(Collectors.toList());
    for (JsonObject device : deviceList) {
        result.add(new JsonObject().put("hwId", device.getString("hwId")).put("type", device.getString("type"))
                .put("name", device.getString("name")));
    }

    return result;
}