diff --git a/build.gradle b/build.gradle index 9d1c1970..b0b32bde 100644 --- a/build.gradle +++ b/build.gradle @@ -18,7 +18,7 @@ subprojects { apply plugin: 'java-library' dependencies { - implementation 'se.koc:zutil:1.0.310' + implementation 'se.koc:zutil:1.0.311' //implementation 'se.koc:zutil:1.0.0-SNAPSHOT' testImplementation 'junit:junit:4.12' diff --git a/hal-core/src/se/hal/page/api/EventJsonPage.java b/hal-core/src/se/hal/page/api/EventJsonPage.java index deeb1678..a10b01e8 100644 --- a/hal-core/src/se/hal/page/api/EventJsonPage.java +++ b/hal-core/src/se/hal/page/api/EventJsonPage.java @@ -1,7 +1,6 @@ package se.hal.page.api; import se.hal.HalContext; -import se.hal.daemon.SensorDataAggregatorDaemon; import se.hal.intf.HalJsonPage; import se.hal.struct.Event; import zutil.ArrayUtil; @@ -40,7 +39,7 @@ public class EventJsonPage extends HalJsonPage { DBConnection db = HalContext.getDB(); DataNode root = new DataNode(DataNode.DataType.List); - // Get sensors + // Get Events String[] req_ids = new String[0]; if (request.get("id") != null) @@ -49,21 +48,25 @@ public class EventJsonPage extends HalJsonPage { List events = new ArrayList<>(); for (Event event : Event.getLocalEvents(db)) { - if (ArrayUtil.contains(req_ids, "" + event.getId())) { // id filtering events.add(event); - } else if (!ObjectUtil.isEmpty(req_type) && + } + + if (!ObjectUtil.isEmpty(req_type) && event.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering events.add(event); - } else { // no options defined, then add all sensors + } + + // no options defined, then add all events + if (ObjectUtil.isEmpty(req_ids, req_type)) { events.add(event); } } // Generate DataNode - for (Event sensor : events) { - DataNode deviceNode = sensor.getDataNode(); + for (Event event : events) { + DataNode deviceNode = event.getDataNode(); root.add(deviceNode); } diff --git a/hal-core/src/se/hal/page/api/SensorJsonPage.java b/hal-core/src/se/hal/page/api/SensorJsonPage.java index 87e219af..65903d23 100644 --- a/hal-core/src/se/hal/page/api/SensorJsonPage.java +++ b/hal-core/src/se/hal/page/api/SensorJsonPage.java @@ -55,10 +55,15 @@ public class SensorJsonPage extends HalJsonPage { for (Sensor sensor : Sensor.getSensors(db)) { if (ArrayUtil.contains(req_ids, "" + sensor.getId())) { // id filtering sensors.add(sensor); - } else if (!ObjectUtil.isEmpty(req_type) && + } + + if (!ObjectUtil.isEmpty(req_type) && sensor.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering sensors.add(sensor); - } else { // no options defined, then add all sensors + } + + // no options defined, then add all sensors + if (ObjectUtil.isEmpty(req_ids, req_type)) { sensors.add(sensor); } }