Updated with new Configurator changes and cleaned up imports
This commit is contained in:
parent
6109f66ea0
commit
e1618604c9
66 changed files with 297 additions and 198 deletions
|
|
@ -6,13 +6,13 @@ import se.hal.util.HalDeviceUtil;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,13 @@ import zutil.log.LogUtil;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
package se.hal;
|
||||
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.page.*;
|
||||
import se.hal.intf.HalAbstractControllerManager;
|
||||
import se.hal.intf.HalDaemon;
|
||||
import se.hal.intf.HalJsonPage;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import se.hal.page.HalAlertManager;
|
||||
import se.hal.struct.PluginConfig;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
|
|
@ -14,7 +17,9 @@ import zutil.plugin.PluginData;
|
|||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.logging.Level;
|
||||
|
|
|
|||
|
|
@ -6,13 +6,12 @@ import se.hal.util.HalDeviceUtil;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import se.hal.HalContext;
|
|||
import se.hal.intf.HalAction;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.util.ConfigEventValueProvider;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
|
@ -18,8 +19,8 @@ import java.util.logging.Logger;
|
|||
public class SendEventAction implements HalAction {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
@Configurator.Configurable("Event Device ID")
|
||||
private int eventId;
|
||||
@Configurator.Configurable(value = "Event Device", valueProvider = ConfigEventValueProvider.class)
|
||||
private Event event;
|
||||
@Configurator.Configurable("Data to Send")
|
||||
private double data;
|
||||
|
||||
|
|
@ -28,7 +29,6 @@ public class SendEventAction implements HalAction {
|
|||
public void execute() {
|
||||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
Event event = Event.getEvent(db, eventId);
|
||||
if (event != null) {
|
||||
HalEventData dataObj = (HalEventData) event.getDeviceConfig().getDeviceDataClass().newInstance();
|
||||
dataObj.setData(data);
|
||||
|
|
@ -37,7 +37,7 @@ public class SendEventAction implements HalAction {
|
|||
EventControllerManager.getInstance().send(event);
|
||||
}
|
||||
else
|
||||
logger.warning("Unable to find event with id: "+ eventId);
|
||||
logger.warning("Unable to find event with id: "+ event.getId());
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, null, e);
|
||||
}
|
||||
|
|
@ -45,11 +45,8 @@ public class SendEventAction implements HalAction {
|
|||
|
||||
|
||||
public String toString(){
|
||||
DBConnection db = HalContext.getDB();
|
||||
Event event = null;
|
||||
try{ event = Event.getEvent(db, eventId); } catch (Exception e){} //ignore exception
|
||||
return "Send event: "+ eventId +
|
||||
return "Send event: " + event.getId() +
|
||||
" (" + (event!=null ? event.getName() : null) + ")" +
|
||||
" with data: "+ data;
|
||||
" with data: " + data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ import zutil.db.SQLResultHandler;
|
|||
import zutil.db.handler.SimpleSQLResult;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.ui.UserMessageManager;
|
||||
import zutil.ui.UserMessageManager.*;
|
||||
import zutil.ui.UserMessageManager.MessageTTL;
|
||||
import zutil.ui.UserMessageManager.UserMessage;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ import zutil.ClassUtil;
|
|||
import zutil.log.LogUtil;
|
||||
import zutil.plugin.PluginManager;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import zutil.db.bean.DBBean;
|
|||
import zutil.log.LogUtil;
|
||||
import zutil.parser.json.JSONParser;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.LinkedList;
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import zutil.net.http.HttpHeader;
|
|||
import zutil.net.http.HttpPage;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.parser.json.JSONWriter;
|
||||
import zutil.ui.Navigation;
|
||||
|
||||
import java.io.IOException;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,9 @@ import zutil.db.DBConnection;
|
|||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.UserMessageManager.*;
|
||||
import zutil.ui.UserMessageManager.MessageLevel;
|
||||
import zutil.ui.UserMessageManager.MessageTTL;
|
||||
import zutil.ui.UserMessageManager.UserMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ import zutil.ui.UserMessageManager;
|
|||
import zutil.ui.UserMessageManager.UserMessage;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
package se.hal.page;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalJsonPage;
|
||||
import se.hal.intf.HalAbstractDevice;
|
||||
import se.hal.intf.HalJsonPage;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.Sensor;
|
||||
import zutil.db.DBConnection;
|
||||
|
|
|
|||
|
|
@ -2,11 +2,10 @@ package se.hal.page;
|
|||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.intf.HalWebPage;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.io.file.FileUtil;
|
||||
import zutil.parser.Templator;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map;
|
||||
|
||||
public class PropertyConfigWebPage extends HalWebPage {
|
||||
private static final String TEMPLATE = HalContext.RESOURCE_WEB_ROOT + "/property_config.tmpl";
|
||||
|
|
|
|||
|
|
@ -9,8 +9,6 @@ import se.hal.util.UTCTimeUtility;
|
|||
import zutil.ArrayUtil;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.net.http.HttpHeader;
|
||||
import zutil.net.http.HttpPrintStream;
|
||||
import zutil.parser.DataNode;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import zutil.io.file.FileUtil;
|
|||
import zutil.parser.Templator;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ import zutil.db.DBConnection;
|
|||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.UserMessageManager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import zutil.db.DBConnection;
|
|||
import zutil.io.file.FileUtil;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.parser.Templator;
|
||||
import zutil.ui.UserMessageManager;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
|
|
|
|||
|
|
@ -1,16 +1,11 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import se.hal.intf.HalAction;
|
||||
import se.hal.intf.HalTrigger;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanObjectDSO;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines a action that will be executed
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.ConfigurationParam;
|
||||
import zutil.ui.conf.Configurator;
|
||||
import zutil.ui.conf.Configurator.ConfigurationParam;
|
||||
|
||||
/**
|
||||
* A Data class used by the dynamic class configuration pages
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package se.hal.struct;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.intf.HalAbstractDevice;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalEventController;
|
||||
import se.hal.intf.HalEventData;
|
||||
import se.hal.util.DeviceDataSqlResult;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
|
|
|
|||
|
|
@ -4,12 +4,8 @@ import se.hal.intf.HalTrigger;
|
|||
import zutil.db.DBConnection;
|
||||
import zutil.db.bean.DBBean;
|
||||
import zutil.db.bean.DBBeanObjectDSO;
|
||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A class that declares a trigger/condition that
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ package se.hal.trigger;
|
|||
|
||||
import se.hal.intf.HalTrigger;
|
||||
import zutil.CronTimer;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
|
||||
public class DateTimeTrigger implements HalTrigger,Configurator.PostConfigurationActionListener {
|
||||
|
||||
@Configurator.Configurable("Minute (Cron format)")
|
||||
|
|
|
|||
|
|
@ -1,14 +1,10 @@
|
|||
package se.hal.trigger;
|
||||
|
||||
import se.hal.TriggerManager;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import se.hal.intf.HalDeviceReportListener;
|
||||
import se.hal.intf.HalTrigger;
|
||||
import se.hal.intf.HalAbstractDevice;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.Configurator.PreConfigurationActionListener;
|
||||
import se.hal.intf.*;
|
||||
import zutil.ui.conf.Configurator;
|
||||
import zutil.ui.conf.Configurator.PostConfigurationActionListener;
|
||||
import zutil.ui.conf.Configurator.PreConfigurationActionListener;
|
||||
|
||||
/**
|
||||
* An abstract class that implements generic device data logic
|
||||
|
|
@ -18,8 +14,6 @@ public abstract class DeviceTrigger implements HalTrigger,
|
|||
PostConfigurationActionListener,
|
||||
HalDeviceReportListener<HalDeviceConfig,HalDeviceData> {
|
||||
|
||||
@Configurator.Configurable("Device ID")
|
||||
protected int deviceId = -1;
|
||||
@Configurator.Configurable("Trigger only on change")
|
||||
protected boolean triggerOnChange = true;
|
||||
@Configurator.Configurable("Data to compare to")
|
||||
|
|
@ -31,14 +25,14 @@ public abstract class DeviceTrigger implements HalTrigger,
|
|||
|
||||
@Override
|
||||
public void preConfigurationAction(Configurator configurator, Object obj) {
|
||||
HalAbstractDevice device = getDevice(deviceId);
|
||||
HalAbstractDevice device = getDevice();
|
||||
if (device != null)
|
||||
device.removeReportListener(this);
|
||||
reset();
|
||||
}
|
||||
@Override
|
||||
public void postConfigurationAction(Configurator configurator, Object obj) {
|
||||
HalAbstractDevice device = getDevice(deviceId);
|
||||
HalAbstractDevice device = getDevice();
|
||||
if (device != null)
|
||||
device.addReportListener(this);
|
||||
}
|
||||
|
|
@ -67,5 +61,5 @@ public abstract class DeviceTrigger implements HalTrigger,
|
|||
|
||||
|
||||
|
||||
protected abstract HalAbstractDevice getDevice(long id);
|
||||
protected abstract HalAbstractDevice getDevice();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
package se.hal.trigger;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.util.ConfigEventValueProvider;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class EventTrigger extends DeviceTrigger{
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
@Configurator.Configurable(value = "Event", valueProvider = ConfigEventValueProvider.class)
|
||||
protected Event device;
|
||||
|
||||
|
||||
@Override
|
||||
protected Event getDevice(long id) {
|
||||
try {
|
||||
if (id >= 0)
|
||||
return Event.getEvent(HalContext.getDB(), id);
|
||||
} catch (SQLException e){ logger.log(Level.SEVERE, null, e);}
|
||||
return null;
|
||||
protected Event getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
Event event = getDevice(deviceId);
|
||||
Event event = getDevice();
|
||||
return "Trigger " + (triggerOnChange ? "on" : "when") +
|
||||
" event: "+ deviceId +" ("+(event != null ? event.getName() : null) + ")" +
|
||||
" == "+ expectedData;
|
||||
" event: " + device.getId() + " (" + (event != null ? event.getName() : null) + ")" +
|
||||
" == " + expectedData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,32 +1,30 @@
|
|||
package se.hal.trigger;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.struct.Event;
|
||||
import se.hal.struct.Sensor;
|
||||
import se.hal.util.ConfigSensorValueProvider;
|
||||
import zutil.log.LogUtil;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class SensorTrigger extends DeviceTrigger{
|
||||
public class SensorTrigger extends DeviceTrigger {
|
||||
private static final Logger logger = LogUtil.getLogger();
|
||||
|
||||
@Configurator.Configurable(value = "Sensor", valueProvider = ConfigSensorValueProvider.class)
|
||||
protected Sensor device;
|
||||
|
||||
|
||||
@Override
|
||||
protected Sensor getDevice(long id) {
|
||||
try {
|
||||
if (id >= 0)
|
||||
return Sensor.getSensor(HalContext.getDB(), id);
|
||||
} catch (SQLException e){ logger.log(Level.SEVERE, null, e);}
|
||||
return null;
|
||||
protected Sensor getDevice() {
|
||||
return device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
Sensor sensor = getDevice(deviceId);
|
||||
Sensor sensor = getDevice();
|
||||
return "Trigger " + (triggerOnChange ? "on" : "when") +
|
||||
" sensor: "+ deviceId +" ("+(sensor != null ? sensor.getName() : null) + ")" +
|
||||
" == "+ expectedData;
|
||||
" sensor: " + sensor.getId() +" (" + (sensor != null ? sensor.getName() : null) + ")" +
|
||||
" == " + expectedData;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package se.hal.trigger;
|
|||
|
||||
import se.hal.intf.HalTrigger;
|
||||
import zutil.Timer;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
public class TimerTrigger implements HalTrigger {
|
||||
|
||||
|
|
|
|||
55
hal-core/src/se/hal/util/ConfigEventValueProvider.java
Normal file
55
hal-core/src/se/hal/util/ConfigEventValueProvider.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package se.hal.util;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.struct.Event;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A value provider that will give all Enum values
|
||||
*/
|
||||
public class ConfigEventValueProvider implements Configurator.ConfigValueProvider<Event> {
|
||||
private Event currentValue;
|
||||
private Map<String, Event> events = new HashMap<>();
|
||||
|
||||
|
||||
public ConfigEventValueProvider(Class<Enum> fieldType, Object fieldValue) {
|
||||
this.currentValue = (Event) fieldValue;
|
||||
|
||||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
|
||||
for (Event event : Event.getLocalEvents(db)) {
|
||||
events.put(getValue(event), event);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Unable to collect Event objects.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getValue(Event event) {
|
||||
return event.getName() + " (id: " + event.getId() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentValue() {
|
||||
return getValue(currentValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPossibleValues() {
|
||||
return new ArrayList<String>(events.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Event getObject(String value) {
|
||||
return events.get(value);
|
||||
}
|
||||
}
|
||||
55
hal-core/src/se/hal/util/ConfigSensorValueProvider.java
Normal file
55
hal-core/src/se/hal/util/ConfigSensorValueProvider.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package se.hal.util;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.struct.Sensor;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A value provider that will give all Enum values
|
||||
*/
|
||||
public class ConfigSensorValueProvider implements Configurator.ConfigValueProvider<Sensor> {
|
||||
private Sensor currentValue;
|
||||
private Map<String, Sensor> sensors = new HashMap<>();
|
||||
|
||||
|
||||
public ConfigSensorValueProvider(Class<Enum> fieldType, Object fieldValue) {
|
||||
this.currentValue = (Sensor) fieldValue;
|
||||
|
||||
try {
|
||||
DBConnection db = HalContext.getDB();
|
||||
|
||||
for (Sensor sensor : Sensor.getLocalSensors(db)) {
|
||||
sensors.put(getValue(sensor), sensor);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException("Unable to collect Event objects.", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getValue(Sensor sensor) {
|
||||
return sensor.getName() + " (id: " + sensor.getId() + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCurrentValue() {
|
||||
return getValue(currentValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getPossibleValues() {
|
||||
return new ArrayList<String>(sensors.keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Sensor getObject(String value) {
|
||||
return sensors.get(value);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
package se.hal.util;
|
||||
|
||||
import se.hal.intf.HalDeviceData;
|
||||
import zutil.ClassUtil;
|
||||
import zutil.db.SQLResultHandler;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import se.hal.HalServer;
|
|||
import se.hal.intf.HalAbstractControllerManager;
|
||||
import se.hal.intf.HalAbstractDevice;
|
||||
import se.hal.intf.HalDeviceConfig;
|
||||
import zutil.ui.Configurator;
|
||||
import zutil.ui.conf.Configurator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ import se.hal.struct.devicedata.TemperatureSensorData;
|
|||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
|
||||
public class SensorControllerManagerTest {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ import se.hal.struct.TriggerFlow;
|
|||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,16 +1,15 @@
|
|||
package se.hal.daemon;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import se.hal.HalContext;
|
||||
import se.hal.util.UTCTimeUtility;
|
||||
import zutil.db.DBConnection;
|
||||
import zutil.db.DBUpgradeHandler;
|
||||
import zutil.log.LogUtil;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class SensorDataAggregationDaemonTest {
|
||||
private static final String DEFAULT_DB_FILE = "resource/resource/hal-default.db";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
package se.hal.test;
|
||||
|
||||
import se.hal.intf.*;
|
||||
import se.hal.intf.HalEventConfig;
|
||||
import se.hal.intf.HalSensorConfig;
|
||||
import se.hal.intf.HalSensorController;
|
||||
import se.hal.intf.HalSensorData;
|
||||
import se.hal.struct.devicedata.TemperatureSensorData;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import se.hal.daemon.SensorDataAggregatorDaemon.AggregationPeriodLength;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
import se.hal.daemon.SensorDataAggregatorDaemon.AggregationPeriodLength;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
|
@ -18,8 +17,8 @@ import static org.junit.Assert.assertTrue;
|
|||
@RunWith(Parameterized.class)
|
||||
public class TimeUtilityTest {
|
||||
private final long currentTime_UTC;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param timestamp
|
||||
|
|
@ -27,7 +26,7 @@ public class TimeUtilityTest {
|
|||
public TimeUtilityTest(long timestamp){
|
||||
this.currentTime_UTC = timestamp;
|
||||
}
|
||||
|
||||
|
||||
@Parameters
|
||||
public static Collection<Object[]> data(){
|
||||
return Arrays.asList(new Object[][] {
|
||||
|
|
@ -50,15 +49,15 @@ public class TimeUtilityTest {
|
|||
{Long.MAX_VALUE-(60*UTCTimeUtility.WEEK_IN_MS)}, //max time - 60w
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes year
|
||||
@Test
|
||||
public void testYear_UTC(){
|
||||
public void testYear_UTC(){
|
||||
System.out.println("Testing year with timestamp " + currentTime_UTC + " " + UTCTimeUtility.getDateString(currentTime_UTC));
|
||||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.YEAR, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.YEAR, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" year start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("perdiod start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -80,18 +79,18 @@ public class TimeUtilityTest {
|
|||
assertEquals("period end day is wrong", 31, UTCTimeUtility.getDayOfMonthFromTimestamp(thisPeriodEndedAt));
|
||||
assertEquals("period end month is wrong", Calendar.DECEMBER, UTCTimeUtility.getMonthOfYearFromTimestamp(thisPeriodEndedAt));
|
||||
assertEquals("period end year is wrong", UTCTimeUtility.getYearFromTimestamp(currentTime_UTC), UTCTimeUtility.getYearFromTimestamp(thisPeriodEndedAt));
|
||||
|
||||
|
||||
//verify that start and end values are reasonable
|
||||
assertTrue("start is zero", thisPeriodStartedAt != 0);
|
||||
assertTrue("end is zero", thisPeriodEndedAt != 0);
|
||||
assertTrue("start is not before end", thisPeriodStartedAt < thisPeriodEndedAt );
|
||||
assertTrue("start and end are equal", thisPeriodStartedAt != thisPeriodEndedAt );
|
||||
|
||||
|
||||
//verify that the period start and end is in the same period
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.YEAR, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.YEAR, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes month
|
||||
@Test
|
||||
public void testMonth_UTC(){
|
||||
|
|
@ -101,7 +100,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.MONTH, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.MONTH, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" month start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("perdiod start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -129,12 +128,12 @@ public class TimeUtilityTest {
|
|||
assertTrue("end is zero", thisPeriodEndedAt != 0);
|
||||
assertTrue("start is not before end", thisPeriodStartedAt < thisPeriodEndedAt );
|
||||
assertTrue("start and end are equal", thisPeriodStartedAt != thisPeriodEndedAt );
|
||||
|
||||
|
||||
//verify that the period start and end is in the same period
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.MONTH, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.MONTH, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes week
|
||||
@Test
|
||||
public void testWeek_UTC(){
|
||||
|
|
@ -142,7 +141,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.WEEK, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.WEEK, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" week start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -175,8 +174,8 @@ public class TimeUtilityTest {
|
|||
//verify that the period start and end is in the same period
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.WEEK, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.WEEK, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes day
|
||||
@Test
|
||||
public void testDay_UTC(){
|
||||
|
|
@ -184,7 +183,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.DAY, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.DAY, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" day start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -218,7 +217,7 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.DAY, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.DAY, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes hour
|
||||
@Test
|
||||
public void testHour_UTC(){
|
||||
|
|
@ -226,7 +225,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.HOUR, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.HOUR, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" hour start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -260,7 +259,7 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.HOUR, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.HOUR, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes 15-minute period
|
||||
@Test
|
||||
public void testFifteenMinute_UTC(){
|
||||
|
|
@ -268,7 +267,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.FIFTEEN_MINUTES, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.FIFTEEN_MINUTES, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" 15-min start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -305,15 +304,15 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.FIFTEEN_MINUTES, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.FIFTEEN_MINUTES, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes 5-minute period
|
||||
@Test
|
||||
public void testFiveMinute_UTC(){
|
||||
System.out.println("Testing 5-min with timestamp " + currentTime_UTC + " " + UTCTimeUtility.getDateString(currentTime_UTC));
|
||||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.FIVE_MINUTES, currentTime_UTC);
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.FIVE_MINUTES, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.FIVE_MINUTES, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" 5-min start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -350,7 +349,7 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.FIVE_MINUTES, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.FIVE_MINUTES, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes minute
|
||||
@Test
|
||||
public void testMinute_UTC(){
|
||||
|
|
@ -358,7 +357,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.MINUTE, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.MINUTE, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" minute start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -391,7 +390,7 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.MINUTE, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.MINUTE, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test flooring & ceiling UTC time to the closes second
|
||||
@Test
|
||||
public void testSecond_UTC(){
|
||||
|
|
@ -399,7 +398,7 @@ public class TimeUtilityTest {
|
|||
|
||||
long thisPeriodStartedAt = UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.SECOND, currentTime_UTC);
|
||||
long thisPeriodEndedAt = UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.SECOND, currentTime_UTC);
|
||||
|
||||
|
||||
//verify period start is correct
|
||||
System.out.println(" second start timestamp = " + thisPeriodStartedAt + " " + UTCTimeUtility.getDateString(thisPeriodStartedAt));
|
||||
assertTrue("period start is not before current time", thisPeriodStartedAt <= currentTime_UTC);
|
||||
|
|
@ -432,9 +431,9 @@ public class TimeUtilityTest {
|
|||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodStartedAt, UTCTimeUtility.getTimestampPeriodStart(AggregationPeriodLength.SECOND, thisPeriodEndedAt));
|
||||
assertEquals("start and/or end timestamp is not in the same period", thisPeriodEndedAt, UTCTimeUtility.getTimestampPeriodEnd(AggregationPeriodLength.SECOND, thisPeriodStartedAt));
|
||||
}
|
||||
|
||||
|
||||
// Test printing converting milliseconds to text
|
||||
@Test
|
||||
@Test
|
||||
public void testMsToString(){
|
||||
//low values
|
||||
assertEquals("00:00:00.000", UTCTimeUtility.timeInMsToString(0));
|
||||
|
|
@ -452,23 +451,23 @@ public class TimeUtilityTest {
|
|||
assertEquals("00:59:00.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.MINUTE_IN_MS*59));
|
||||
assertEquals("23:00:00.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.HOUR_IN_MS*23));
|
||||
assertEquals("52w+5d+00:00:00.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.DAY_IN_MS*369));
|
||||
|
||||
|
||||
//high overflow values
|
||||
assertEquals("00:00:01.999", UTCTimeUtility.timeInMsToString(1999));
|
||||
assertEquals("00:02:39.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.SECOND_IN_MS*159));
|
||||
assertEquals("02:39:00.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.MINUTE_IN_MS*159));
|
||||
assertEquals("5d+03:00:00.000", UTCTimeUtility.timeInMsToString(UTCTimeUtility.HOUR_IN_MS*123));
|
||||
|
||||
|
||||
//combinations
|
||||
assertEquals("142w+5d+23:59:59.999", UTCTimeUtility.timeInMsToString((UTCTimeUtility.WEEK_IN_MS*142) + (UTCTimeUtility.DAY_IN_MS*5) + (UTCTimeUtility.HOUR_IN_MS*23) + (UTCTimeUtility.MINUTE_IN_MS*59) + (UTCTimeUtility.SECOND_IN_MS*59) + 999));
|
||||
assertEquals("6d+23:59:59.999", UTCTimeUtility.timeInMsToString(UTCTimeUtility.WEEK_IN_MS-1));
|
||||
}
|
||||
|
||||
|
||||
// Test printing converting milliseconds to text for a negative time
|
||||
@Test(expected=NumberFormatException.class)
|
||||
public void testMsToStringForNegativeArgument(){
|
||||
//low values
|
||||
UTCTimeUtility.timeInMsToString(-1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue