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;
}
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);
}
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());
}
}
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;
}
Aggregations