Some bugfixes
This commit is contained in:
parent
fc37d158c5
commit
7f22b2dee2
5 changed files with 18 additions and 17 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
<th class="col-md-3">Name</th>
|
<th class="col-md-3">Name</th>
|
||||||
<th class="col-md-1">Version</th>
|
<th class="col-md-1">Version</th>
|
||||||
<th class="col-md-7">Description</th>
|
<th class="col-md-7">Description</th>
|
||||||
<th class="col-md-1 text-right">Actions</th>
|
<th class="col-md-1 text-right">Enable</th>
|
||||||
</thead>
|
</thead>
|
||||||
{{#plugins}}
|
{{#plugins}}
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@ import zutil.net.http.page.HttpRedirectPage;
|
||||||
import zutil.plugin.PluginData;
|
import zutil.plugin.PluginData;
|
||||||
import zutil.plugin.PluginManager;
|
import zutil.plugin.PluginManager;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
@ -42,7 +41,7 @@ public class HalServer {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) {
|
||||||
try {
|
try {
|
||||||
// init logging
|
// init logging
|
||||||
LogUtil.readConfiguration("logging.properties");
|
LogUtil.readConfiguration("logging.properties");
|
||||||
|
|
@ -61,10 +60,10 @@ public class HalServer {
|
||||||
pluginManager = new PluginManager();
|
pluginManager = new PluginManager();
|
||||||
|
|
||||||
// Disable plugins based on settings
|
// Disable plugins based on settings
|
||||||
for (PluginData plugin : getPlugins()) {
|
for (PluginData plugin : getAllPlugins()) {
|
||||||
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, plugin.getName());
|
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, plugin.getName());
|
||||||
|
|
||||||
if (pluginConfig != null && !pluginConfig.isEnabled()) {
|
if (pluginConfig != null && !pluginConfig.isEnabled() && !plugin.getName().equals("Hal-Core")) {
|
||||||
logger.info("Disabling plugin '" + plugin.getName() + "'.");
|
logger.info("Disabling plugin '" + plugin.getName() + "'.");
|
||||||
plugin.setEnabled(false);
|
plugin.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
@ -138,7 +137,10 @@ public class HalServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setPluginEnabled(String name, boolean enabled) throws SQLException {
|
public static void enablePlugin(String name, boolean enabled) throws SQLException {
|
||||||
|
if (name.equals("Hal-Core"))
|
||||||
|
throw new IllegalArgumentException("Hal-Core cannot be disabled as it is critical component of Hal.");
|
||||||
|
|
||||||
DBConnection db = HalContext.getDB();
|
DBConnection db = HalContext.getDB();
|
||||||
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, name);
|
PluginConfig pluginConfig = PluginConfig.getPluginConfig(db, name);
|
||||||
|
|
||||||
|
|
@ -152,10 +154,14 @@ public class HalServer {
|
||||||
pluginConfig.save(db);
|
pluginConfig.save(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PluginData> getPlugins() {
|
public static List<PluginData> getEnabledPlugins() {
|
||||||
return pluginManager.toArray();
|
return pluginManager.toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<PluginData> getAllPlugins() {
|
||||||
|
return pluginManager.toArrayAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void registerDaemon(HalDaemon daemon){
|
public static void registerDaemon(HalDaemon daemon){
|
||||||
daemons.add(daemon);
|
daemons.add(daemon);
|
||||||
|
|
|
||||||
|
|
@ -7,14 +7,9 @@ import se.hal.intf.HalWebPage;
|
||||||
import se.hal.page.HalAlertManager.AlertLevel;
|
import se.hal.page.HalAlertManager.AlertLevel;
|
||||||
import se.hal.page.HalAlertManager.AlertTTL;
|
import se.hal.page.HalAlertManager.AlertTTL;
|
||||||
import se.hal.page.HalAlertManager.HalAlert;
|
import se.hal.page.HalAlertManager.HalAlert;
|
||||||
import se.hal.struct.devicedata.SwitchEventData;
|
|
||||||
import zutil.ObjectUtil;
|
|
||||||
import zutil.db.DBConnection;
|
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
import zutil.plugin.PluginManager;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class PluginConfigWebPage extends HalWebPage {
|
public class PluginConfigWebPage extends HalWebPage {
|
||||||
|
|
@ -35,7 +30,7 @@ public class PluginConfigWebPage extends HalWebPage {
|
||||||
|
|
||||||
if (request.containsKey("action")) {
|
if (request.containsKey("action")) {
|
||||||
String name = request.get("action_id");
|
String name = request.get("action_id");
|
||||||
HalServer.setPluginEnabled(name,
|
HalServer.enablePlugin(name,
|
||||||
(request.containsKey("enabled") && "on".equals(request.get("enabled"))));
|
(request.containsKey("enabled") && "on".equals(request.get("enabled"))));
|
||||||
|
|
||||||
HalAlertManager.getInstance().addAlert(new HalAlert(
|
HalAlertManager.getInstance().addAlert(new HalAlert(
|
||||||
|
|
@ -43,7 +38,7 @@ public class PluginConfigWebPage extends HalWebPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
Templator tmpl = new Templator(FileUtil.find(TEMPLATE));
|
||||||
tmpl.set("plugins", HalServer.getPlugins());
|
tmpl.set("plugins", HalServer.getAllPlugins());
|
||||||
tmpl.set("controllers", ControllerManager.getInstance().getControllers());
|
tmpl.set("controllers", ControllerManager.getInstance().getControllers());
|
||||||
return tmpl;
|
return tmpl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
{
|
{
|
||||||
"version": 1.0,
|
"version": 1.0,
|
||||||
"name": "Hal Core",
|
"name": "Hal-Core",
|
||||||
|
"description": "Plugin contains core logic for running Hal.",
|
||||||
"interfaces": [
|
"interfaces": [
|
||||||
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"},
|
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataAggregatorDaemon"},
|
||||||
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"},
|
{"se.hal.intf.HalDaemon": "se.hal.daemon.SensorDataCleanupDaemon"},
|
||||||
|
|
||||||
|
|
||||||
{"se.hal.intf.HalJsonPage": "se.hal.page.MapJsonPage"},
|
{"se.hal.intf.HalJsonPage": "se.hal.page.MapJsonPage"},
|
||||||
{"se.hal.intf.HalJsonPage": "se.hal.page.SensorJsonPage"},
|
{"se.hal.intf.HalJsonPage": "se.hal.page.SensorJsonPage"},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,6 @@ public class TemperatureSensorData extends HalSensorData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
return temperature+" \u00b0C";
|
return temperature + " C";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue