Search in sources :

Example 1 with RestChannel

use of org.openmuc.framework.lib.rest.objects.RestChannel in project OpenMUC by isc-konstanz.

the class FromJson method getRestChannelList.

public List<RestChannel> getRestChannelList() {
    ArrayList<RestChannel> recordList = new ArrayList<>();
    JsonElement jse = jsonObject.get("records");
    JsonArray jsa;
    if (!jse.isJsonNull() && jse.isJsonArray()) {
        jsa = jse.getAsJsonArray();
        Iterator<JsonElement> jseIterator = jsa.iterator();
        while (jseIterator.hasNext()) {
            JsonObject jsoIterated = jseIterator.next().getAsJsonObject();
            RestChannel rc = gson.fromJson(jsoIterated, RestChannel.class);
            recordList.add(rc);
        }
    }
    if (recordList.isEmpty()) {
        return null;
    }
    return recordList;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) RestChannel(org.openmuc.framework.lib.rest.objects.RestChannel)

Example 2 with RestChannel

use of org.openmuc.framework.lib.rest.objects.RestChannel in project OpenMUC by isc-konstanz.

the class ToJson method addDevice.

private void addDevice(RestDeviceWrapper device, JsonObject jso) {
    JsonObject jsco = gson.toJsonTree(device.getConfig(), RestDeviceConfig.class).getAsJsonObject();
    jsco.remove(Const.ID);
    jso.addProperty(Const.ID, device.getId());
    jso.add(Const.CONFIGS, jsco);
    jso.add(Const.DRIVER, gson.toJsonTree(device.getDriver(), RestDriverInfo.class).getAsJsonObject());
    jso.addProperty(Const.STATE, device.getState().name());
    JsonArray channels = new JsonArray();
    for (RestChannel channel : device.getChannels()) {
        channels.add(gson.toJsonTree(channel, RestChannel.class).getAsJsonObject());
    }
    jso.add(Const.RECORDS, channels);
}
Also used : JsonArray(com.google.gson.JsonArray) RestDeviceConfig(org.openmuc.framework.lib.rest.objects.RestDeviceConfig) JsonObject(com.google.gson.JsonObject) RestChannel(org.openmuc.framework.lib.rest.objects.RestChannel)

Example 3 with RestChannel

use of org.openmuc.framework.lib.rest.objects.RestChannel in project OpenMUC by isc-konstanz.

the class RestChannelScanner method scan.

@Override
public void scan(List<ChannelScanInfo> channelScanInfos) throws ArgumentSyntaxException, ScanException, ConnectionException {
    try (RestConnection connection = new RestConnection((RestConfigs) getContext())) {
        FromJson json = new FromJson(connection.get(""));
        List<RestChannel> channels = json.getRestChannelList();
        for (RestChannel channel : channels) {
            // TODO: get channel config list with valueTypeLength, description, ...
            ChannelScanInfo channelScanInfo = new ChannelScanInfo(channel.getId(), "", channel.getValueType(), 0);
            channelScanInfos.add(channelScanInfo);
        }
    } catch (IOException e) {
        throw new ConnectionException(e.getMessage());
    }
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) FromJson(org.openmuc.framework.lib.rest.FromJson) RestChannel(org.openmuc.framework.lib.rest.objects.RestChannel) IOException(java.io.IOException) ConnectionException(org.openmuc.framework.driver.spi.ConnectionException)

Example 4 with RestChannel

use of org.openmuc.framework.lib.rest.objects.RestChannel in project OpenMUC by isc-konstanz.

the class JsonWrapper method tochannelScanInfos.

public List<ChannelScanInfo> tochannelScanInfos(InputStream stream) throws IOException {
    String jsonString = getStringFromInputStream(stream);
    FromJson fromJson = new FromJson(jsonString);
    List<RestChannel> channelList = fromJson.getRestChannelList();
    ArrayList<ChannelScanInfo> channelScanInfos = new ArrayList<>();
    for (RestChannel restChannel : channelList) {
        // TODO: get channel config list with valueTypeLength, description, ...
        ChannelScanInfo channelScanInfo = new ChannelScanInfo(restChannel.getId(), "", restChannel.getValueType(), 0);
        channelScanInfos.add(channelScanInfo);
    }
    return channelScanInfos;
}
Also used : ChannelScanInfo(org.openmuc.framework.config.ChannelScanInfo) FromJson(org.openmuc.framework.lib.rest.FromJson) ArrayList(java.util.ArrayList) RestChannel(org.openmuc.framework.lib.rest.objects.RestChannel)

Aggregations

RestChannel (org.openmuc.framework.lib.rest.objects.RestChannel)4 JsonArray (com.google.gson.JsonArray)2 JsonObject (com.google.gson.JsonObject)2 ArrayList (java.util.ArrayList)2 ChannelScanInfo (org.openmuc.framework.config.ChannelScanInfo)2 FromJson (org.openmuc.framework.lib.rest.FromJson)2 JsonElement (com.google.gson.JsonElement)1 IOException (java.io.IOException)1 ConnectionException (org.openmuc.framework.driver.spi.ConnectionException)1 RestDeviceConfig (org.openmuc.framework.lib.rest.objects.RestDeviceConfig)1