Bug fix where there is no local user and some zutil updates

This commit is contained in:
Ziver Koc 2016-02-14 17:06:03 +01:00
parent 20c1f7df50
commit 3a97a60965
4 changed files with 14 additions and 1 deletions

View file

@ -291,6 +291,7 @@ public class ControllerManager implements HalSensorReportListener,
controllerMap.put(c, controller); controllerMap.put(c, controller);
} catch (Exception e){ } catch (Exception e){
logger.log(Level.SEVERE, "Unable to instantiate controller: "+c.getName(), e); logger.log(Level.SEVERE, "Unable to instantiate controller: "+c.getName(), e);
controller = null;
} }
} }
return (T)controller; return (T)controller;

View file

@ -1,5 +1,6 @@
package se.hal; package se.hal;
import se.hal.struct.User;
import zutil.db.DBConnection; import zutil.db.DBConnection;
import zutil.db.DBUpgradeHandler; import zutil.db.DBUpgradeHandler;
import zutil.db.SQLResultHandler; import zutil.db.SQLResultHandler;
@ -141,6 +142,14 @@ public class HalContext {
return null; return null;
} }
}); });
// Check if there is a local user
User localUser = User.getLocalUser(db);
if (localUser == null){
logger.info("Creating local user.");
localUser = new User();
localUser.setExternal(true);
localUser.save(db);
}
logger.info("DB upgrade done"); logger.info("DB upgrade done");
dbConf.setProperty(PROPERTY_DB_VERSION, defaultDBConf.getProperty(PROPERTY_DB_VERSION)); dbConf.setProperty(PROPERTY_DB_VERSION, defaultDBConf.getProperty(PROPERTY_DB_VERSION));

View file

@ -51,7 +51,6 @@ public class HalServer {
// init DB and other configurations // init DB and other configurations
DBBean.enableBeanGBC(false); // we don't need gbc for our beans as we would loose the device data
DBConnection db = HalContext.getDB(); DBConnection db = HalContext.getDB();
// Init sensors,events and controllers // Init sensors,events and controllers

View file

@ -34,6 +34,10 @@ public class UserConfigHttpPage extends HalHttpPage {
switch(request.get("action")) { switch(request.get("action")) {
// Local User // Local User
case "modify_local_user": case "modify_local_user":
if (localUser == null) {
localUser = new User();
localUser.setExternal(true);
}
localUser.setUsername(request.get("username")); localUser.setUsername(request.get("username"));
localUser.setAddress(request.get("address")); localUser.setAddress(request.get("address"));
localUser.save(db); localUser.save(db);