Search in sources :

Example 6 with ArrayValue

use of org.openremote.model.value.ArrayValue in project openremote by openremote.

the class MapService method getMapSettings.

public ObjectValue getMapSettings(String realm, UriBuilder baseUriBuilder) {
    ObjectValue mapSettings;
    // Mix settings from file with database metadata, and some hardcoded magic
    try {
        String mapSettingsJson = new String(Files.readAllBytes(mapSettingsPath), "utf-8");
        mapSettings = Values.<ObjectValue>parse(mapSettingsJson).orElseThrow(() -> new RuntimeException("Error parsing map settings: " + mapSettingsPath.toAbsolutePath()));
    } catch (Exception ex) {
        throw new RuntimeException("Error parsing map settings: " + mapSettingsPath.toAbsolutePath(), ex);
    }
    ObjectValue style = mapSettings.getObject("style").orElseThrow(() -> new RuntimeException("Missing 'style' field in map settings style: " + mapSettingsPath.toAbsolutePath()));
    style.put("version", 8);
    if (style.hasKey("sprite")) {
        // Rewrite path to sprite file to our external host
        String spritePath = style.getString("sprite").orElseThrow(() -> new RuntimeException("Missing 'sprite' field in map settings style: " + mapSettingsPath.toAbsolutePath()));
        String spriteUri = baseUriBuilder.clone().replacePath(ManagerWebService.MANAGER_PATH).path(spritePath).build().toString();
        style.put("sprite", spriteUri);
    }
    String glyphsUri = baseUriBuilder.clone().replacePath(ManagerWebService.MANAGER_PATH).path("/fonts/").build().toString() + "{fontstack}/{range}.pbf";
    style.put("glyphs", glyphsUri);
    ObjectValue sources = Values.createObject();
    style.put("sources", sources);
    ObjectValue vectorTiles = Values.createObject();
    sources.put("vector_tiles", vectorTiles);
    vectorTiles.put("type", "vector");
    ArrayValue tilesArray = Values.createArray();
    String tileUrl = baseUriBuilder.clone().replacePath(realm).path("map/tile").build().toString() + "/{z}/{x}/{y}";
    tilesArray.set(0, tileUrl);
    vectorTiles.put("tiles", tilesArray);
    PreparedStatement query = null;
    ResultSet result = null;
    try {
        query = connection.prepareStatement("select NAME, VALUE from METADATA");
        result = query.executeQuery();
        Map<String, String> resultMap = new HashMap<>();
        while (result.next()) {
            resultMap.put(result.getString(1), result.getString(2));
        }
        if (resultMap.size() == 0) {
            throw new RuntimeException("Missing JSON metadata in map database");
        }
        ObjectValue metadataJson = Values.<ObjectValue>parse(resultMap.get("json")).orElseThrow(() -> new RuntimeException("Error parsing JSON metadata from map database"));
        ArrayValue vectorLayers = metadataJson.getArray("vector_layers").orElseThrow(() -> new RuntimeException("Missing 'vector_layers' field in metadata from map database"));
        vectorTiles.put("vector_layers", vectorLayers);
        vectorTiles.put("maxzoom", Integer.valueOf(resultMap.get("maxzoom")));
        vectorTiles.put("minzoom", Integer.valueOf(resultMap.get("minzoom")));
        vectorTiles.put("attribution", resultMap.get("attribution"));
    } catch (Exception ex) {
        throw new RuntimeException("Error opening database: " + this, ex);
    } finally {
        closeQuietly(query, result);
    }
    return mapSettings;
}
Also used : ObjectValue(org.openremote.model.value.ObjectValue) HashMap(java.util.HashMap) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MapAccess.getString(org.openremote.container.util.MapAccess.getString) ArrayValue(org.openremote.model.value.ArrayValue)

Example 7 with ArrayValue

use of org.openremote.model.value.ArrayValue in project openremote by openremote.

the class AttributeRef method toArrayValue.

public ArrayValue toArrayValue() {
    ArrayValue arrayValue = Values.createArray();
    arrayValue.set(0, Values.create(getEntityId()));
    arrayValue.set(1, Values.create(getAttributeName()));
    return arrayValue;
}
Also used : ArrayValue(org.openremote.model.value.ArrayValue)

Example 8 with ArrayValue

use of org.openremote.model.value.ArrayValue in project openremote by openremote.

the class GeoJSON method setFeatures.

public GeoJSON setFeatures(GeoJSONFeature... features) {
    if (features != null) {
        for (int i = 0; i < features.length; i++) {
            GeoJSONFeature feature = features[i];
            ArrayValue array = Values.createArray();
            array.set(i, feature.getObjectValue());
            objectValue.put("features", array);
        }
    } else {
        return setEmptyFeatures();
    }
    return this;
}
Also used : ArrayValue(org.openremote.model.value.ArrayValue)

Aggregations

ArrayValue (org.openremote.model.value.ArrayValue)8 ObjectValue (org.openremote.model.value.ObjectValue)3 AbstractValueHolder (org.openremote.model.AbstractValueHolder)2 Lists (com.google.common.collect.Lists)1 HttpHandler (io.undertow.server.HttpHandler)1 Servlets (io.undertow.servlet.Servlets)1 DeploymentInfo (io.undertow.servlet.api.DeploymentInfo)1 DeploymentManager (io.undertow.servlet.api.DeploymentManager)1 ServletInfo (io.undertow.servlet.api.ServletInfo)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Pattern (java.util.regex.Pattern)1 ServletException (javax.servlet.ServletException)1 HttpMethod (javax.ws.rs.HttpMethod)1 Application (javax.ws.rs.core.Application)1