small refactoring
This commit is contained in:
parent
08754d7adb
commit
4a9f08cbb7
3 changed files with 3 additions and 10 deletions
|
|
@ -67,7 +67,6 @@ public class HalContext {
|
||||||
//Read DB conf
|
//Read DB conf
|
||||||
if(firstTime){
|
if(firstTime){
|
||||||
dbConf = new Properties();
|
dbConf = new Properties();
|
||||||
dbConf.put(PROPERTY_DB_VERSION, 0);
|
|
||||||
}else{
|
}else{
|
||||||
dbConf = db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
dbConf = db.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
}
|
}
|
||||||
|
|
@ -77,11 +76,11 @@ public class HalContext {
|
||||||
Properties defaultDBConf =
|
Properties defaultDBConf =
|
||||||
referenceDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
referenceDB.exec("SELECT * FROM conf", new PropertiesSQLResult());
|
||||||
// Check DB version
|
// Check DB version
|
||||||
logger.info("DB version: "+ dbConf.getProperty(PROPERTY_DB_VERSION));
|
|
||||||
final int defaultDBVersion = Integer.parseInt(defaultDBConf.getProperty(PROPERTY_DB_VERSION));
|
final int defaultDBVersion = Integer.parseInt(defaultDBConf.getProperty(PROPERTY_DB_VERSION));
|
||||||
final int dbVersion = (dbConf.getProperty(PROPERTY_DB_VERSION) != null ?
|
final int dbVersion = (dbConf.getProperty(PROPERTY_DB_VERSION) != null ?
|
||||||
Integer.parseInt(dbConf.getProperty(PROPERTY_DB_VERSION)) :
|
Integer.parseInt(dbConf.getProperty(PROPERTY_DB_VERSION)) :
|
||||||
-1);
|
-1);
|
||||||
|
logger.info("DB version: "+ dbVersion);
|
||||||
if(defaultDBVersion > dbVersion ) {
|
if(defaultDBVersion > dbVersion ) {
|
||||||
logger.info("Starting DB upgrade...");
|
logger.info("Starting DB upgrade...");
|
||||||
if(!firstTime){
|
if(!firstTime){
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ public class EventConfigHttpPage extends HalHttpPage {
|
||||||
if(request.containsKey("action")){
|
if(request.containsKey("action")){
|
||||||
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
||||||
Event event;
|
Event event;
|
||||||
Configurator<HalEventData> configurator;
|
|
||||||
switch(request.get("action")) {
|
switch(request.get("action")) {
|
||||||
// Local events
|
// Local events
|
||||||
case "create_local_event":
|
case "create_local_event":
|
||||||
|
|
@ -61,9 +60,7 @@ public class EventConfigHttpPage extends HalHttpPage {
|
||||||
event.setName(request.get("name"));
|
event.setName(request.get("name"));
|
||||||
event.setType(request.get("type"));
|
event.setType(request.get("type"));
|
||||||
event.setUser(localUser);
|
event.setUser(localUser);
|
||||||
configurator = event.getDeviceConfig();
|
event.getDeviceConfig().setValues(request).applyConfiguration();
|
||||||
configurator.setValues(request);
|
|
||||||
configurator.applyConfiguration();
|
|
||||||
event.save(db);
|
event.save(db);
|
||||||
ControllerManager.getInstance().register(event);
|
ControllerManager.getInstance().register(event);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -54,7 +54,6 @@ public class SensorConfigHttpPage extends HalHttpPage {
|
||||||
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
int id = (request.containsKey("id") ? Integer.parseInt(request.get("id")) : -1);
|
||||||
Sensor sensor;
|
Sensor sensor;
|
||||||
User user;
|
User user;
|
||||||
Configurator<HalSensorData> configurator;
|
|
||||||
switch(request.get("action")) {
|
switch(request.get("action")) {
|
||||||
// Local Sensors
|
// Local Sensors
|
||||||
case "create_local_sensor":
|
case "create_local_sensor":
|
||||||
|
|
@ -63,9 +62,7 @@ public class SensorConfigHttpPage extends HalHttpPage {
|
||||||
sensor.setType(request.get("type"));
|
sensor.setType(request.get("type"));
|
||||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||||
sensor.setUser(localUser);
|
sensor.setUser(localUser);
|
||||||
configurator = sensor.getDeviceConfig();
|
sensor.getDeviceConfig().setValues(request).applyConfiguration();
|
||||||
configurator.setValues(request);
|
|
||||||
configurator.applyConfiguration();
|
|
||||||
sensor.save(db);
|
sensor.save(db);
|
||||||
ControllerManager.getInstance().register(sensor);
|
ControllerManager.getInstance().register(sensor);
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue