Fixed issue where API always returned all devices
This commit is contained in:
parent
b80ca96a73
commit
253208b6f9
3 changed files with 18 additions and 10 deletions
|
|
@ -18,7 +18,7 @@ subprojects {
|
||||||
apply plugin: 'java-library'
|
apply plugin: 'java-library'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation 'se.koc:zutil:1.0.310'
|
implementation 'se.koc:zutil:1.0.311'
|
||||||
//implementation 'se.koc:zutil:1.0.0-SNAPSHOT'
|
//implementation 'se.koc:zutil:1.0.0-SNAPSHOT'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
package se.hal.page.api;
|
package se.hal.page.api;
|
||||||
|
|
||||||
import se.hal.HalContext;
|
import se.hal.HalContext;
|
||||||
import se.hal.daemon.SensorDataAggregatorDaemon;
|
|
||||||
import se.hal.intf.HalJsonPage;
|
import se.hal.intf.HalJsonPage;
|
||||||
import se.hal.struct.Event;
|
import se.hal.struct.Event;
|
||||||
import zutil.ArrayUtil;
|
import zutil.ArrayUtil;
|
||||||
|
|
@ -40,7 +39,7 @@ public class EventJsonPage extends HalJsonPage {
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
DataNode root = new DataNode(DataNode.DataType.List);
|
DataNode root = new DataNode(DataNode.DataType.List);
|
||||||
|
|
||||||
// Get sensors
|
// Get Events
|
||||||
|
|
||||||
String[] req_ids = new String[0];
|
String[] req_ids = new String[0];
|
||||||
if (request.get("id") != null)
|
if (request.get("id") != null)
|
||||||
|
|
@ -49,21 +48,25 @@ public class EventJsonPage extends HalJsonPage {
|
||||||
|
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
for (Event event : Event.getLocalEvents(db)) {
|
for (Event event : Event.getLocalEvents(db)) {
|
||||||
|
|
||||||
if (ArrayUtil.contains(req_ids, "" + event.getId())) { // id filtering
|
if (ArrayUtil.contains(req_ids, "" + event.getId())) { // id filtering
|
||||||
events.add(event);
|
events.add(event);
|
||||||
} else if (!ObjectUtil.isEmpty(req_type) &&
|
}
|
||||||
|
|
||||||
|
if (!ObjectUtil.isEmpty(req_type) &&
|
||||||
event.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering
|
event.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering
|
||||||
events.add(event);
|
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);
|
events.add(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate DataNode
|
// Generate DataNode
|
||||||
|
|
||||||
for (Event sensor : events) {
|
for (Event event : events) {
|
||||||
DataNode deviceNode = sensor.getDataNode();
|
DataNode deviceNode = event.getDataNode();
|
||||||
root.add(deviceNode);
|
root.add(deviceNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,15 @@ public class SensorJsonPage extends HalJsonPage {
|
||||||
for (Sensor sensor : Sensor.getSensors(db)) {
|
for (Sensor sensor : Sensor.getSensors(db)) {
|
||||||
if (ArrayUtil.contains(req_ids, "" + sensor.getId())) { // id filtering
|
if (ArrayUtil.contains(req_ids, "" + sensor.getId())) { // id filtering
|
||||||
sensors.add(sensor);
|
sensors.add(sensor);
|
||||||
} else if (!ObjectUtil.isEmpty(req_type) &&
|
}
|
||||||
|
|
||||||
|
if (!ObjectUtil.isEmpty(req_type) &&
|
||||||
sensor.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering
|
sensor.getDeviceConfig().getDeviceDataClass().getSimpleName().contains(req_type)) { // device type filtering
|
||||||
sensors.add(sensor);
|
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);
|
sensors.add(sensor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue