Implemented instantiatiation of triggers and actions. issue 6
This commit is contained in:
parent
9fa687081a
commit
36f2509d94
8 changed files with 100 additions and 56 deletions
|
|
@ -94,7 +94,7 @@
|
||||||
|
|
||||||
<target name="build-dependencies">
|
<target name="build-dependencies">
|
||||||
<mkdir dir="${buildDir}" />
|
<mkdir dir="${buildDir}" />
|
||||||
<get src="http://ci.koc.se/jenkins/job/Zutil/131/artifact/build/release/Zutil.jar"
|
<get src="http://ci.koc.se/jenkins/job/Zutil/136/artifact/build/release/Zutil.jar"
|
||||||
dest="${libDir}" verbose="true" usetimestamp="true"/>
|
dest="${libDir}" verbose="true" usetimestamp="true"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
<th class="col-md-5 text-center">
|
<th class="col-md-5 text-center">
|
||||||
Triggers
|
Triggers
|
||||||
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
||||||
data-target="#triggerModal">
|
data-target="#triggerModal" data-action="create_trigger" data-flow-id="{{.getId()}}">
|
||||||
<span class="glyphicon glyphicon-plus"></span>
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -28,7 +28,7 @@
|
||||||
<th class="col-md-6 text-center">
|
<th class="col-md-6 text-center">
|
||||||
Actions
|
Actions
|
||||||
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
<button class="btn btn-default btn-xs pull-right" data-toggle="modal"
|
||||||
data-target="#actionModal">
|
data-target="#actionModal" data-action="create_action" data-flow-id="{{.getId()}}">
|
||||||
<span class="glyphicon glyphicon-plus"></span>
|
<span class="glyphicon glyphicon-plus"></span>
|
||||||
</button>
|
</button>
|
||||||
</th>
|
</th>
|
||||||
|
|
@ -38,24 +38,14 @@
|
||||||
<td>
|
<td>
|
||||||
<!-- TRIGGERS -->
|
<!-- TRIGGERS -->
|
||||||
<table class="table table-hover table-condensed table-borderless">
|
<table class="table table-hover table-condensed table-borderless">
|
||||||
|
{{#.getTriggers()}}
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
||||||
<span class="glyphicon glyphicon-time"></span>
|
<span class="glyphicon glyphicon-time"></span>
|
||||||
test trigger
|
{{.}}
|
||||||
</div></div>
|
|
||||||
</td></tr>
|
|
||||||
<tr><td>
|
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
|
||||||
<span class="glyphicon glyphicon-time"></span>
|
|
||||||
test trigger
|
|
||||||
</div></div>
|
|
||||||
</td></tr>
|
|
||||||
<tr><td>
|
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
|
||||||
<span class="glyphicon glyphicon-time"></span>
|
|
||||||
test trigger
|
|
||||||
</div></div>
|
</div></div>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
{{/.getTriggers()}}
|
||||||
</table>
|
</table>
|
||||||
<!-- /TRIGGERS -->
|
<!-- /TRIGGERS -->
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -66,24 +56,14 @@
|
||||||
<td>
|
<td>
|
||||||
<!-- ACTIONS -->
|
<!-- ACTIONS -->
|
||||||
<table class="table table-hover table-condensed table-borderless">
|
<table class="table table-hover table-condensed table-borderless">
|
||||||
|
{{#.getActions()}}
|
||||||
<tr><td>
|
<tr><td>
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
||||||
<span class="glyphicon glyphicon-play-circle"></span>
|
<span class="glyphicon glyphicon-play-circle"></span>
|
||||||
test action
|
{{.}}
|
||||||
</div></div>
|
|
||||||
</td></tr>
|
|
||||||
<tr><td>
|
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
|
||||||
<span class="glyphicon glyphicon-play-circle"></span>
|
|
||||||
test action
|
|
||||||
</div></div>
|
|
||||||
</td></tr>
|
|
||||||
<tr><td>
|
|
||||||
<div class="panel panel-default drop-shadow"><div class="panel-body">
|
|
||||||
<span class="glyphicon glyphicon-play-circle"></span>
|
|
||||||
test action
|
|
||||||
</div></div>
|
</div></div>
|
||||||
</td></tr>
|
</td></tr>
|
||||||
|
{{/.getActions()}}
|
||||||
</table>
|
</table>
|
||||||
<!-- /ACTIONS -->
|
<!-- /ACTIONS -->
|
||||||
</td>
|
</td>
|
||||||
|
|
@ -121,14 +101,8 @@
|
||||||
$("#"+name+"Modal").on('show.bs.modal', function (event) {
|
$("#"+name+"Modal").on('show.bs.modal', function (event) {
|
||||||
var button = $(event.relatedTarget);
|
var button = $(event.relatedTarget);
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
modal.find("input[type=text]").val(""); // Reset all inputs
|
modal.find("input").val(""); // Reset all inputs
|
||||||
if(button.data("id") >= 0){ // edit
|
|
||||||
modal.find("input[name=action]").val("modify_"+name);
|
|
||||||
}
|
|
||||||
else{ // create
|
|
||||||
modal.find("input[name=action]").val("create_"+name);
|
|
||||||
modal.find("input[name=id]").val(-1);
|
|
||||||
}
|
|
||||||
// set dynamic form data
|
// set dynamic form data
|
||||||
modal.find("select[name=type]").val(button.data("type"));
|
modal.find("select[name=type]").val(button.data("type"));
|
||||||
modal.find("select[name=type]").change(); // Update dynamic inputs
|
modal.find("select[name=type]").change(); // Update dynamic inputs
|
||||||
|
|
@ -155,8 +129,9 @@
|
||||||
</div>
|
</div>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="hidden" id="action" name="action" value="">
|
<input type="hidden" name="action" value="">
|
||||||
<input type="hidden" id="id" name="id">
|
<input type="hidden" name="flow-id">
|
||||||
|
<input type="hidden" name="trigger-id">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">Type:</label>
|
<label class="control-label">Type:</label>
|
||||||
<select class="form-control" name="type">
|
<select class="form-control" name="type">
|
||||||
|
|
@ -190,8 +165,9 @@
|
||||||
</div>
|
</div>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<input type="hidden" id="action" name="action" value="">
|
<input type="hidden" name="action" value="">
|
||||||
<input type="hidden" id="id" name="id">
|
<input type="hidden" name="flow_id">
|
||||||
|
<input type="hidden" name="action_id">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="control-label">Type:</label>
|
<label class="control-label">Type:</label>
|
||||||
<select class="form-control" name="type">
|
<select class="form-control" name="type">
|
||||||
|
|
@ -236,7 +212,7 @@
|
||||||
{{/triggerConf}}
|
{{/triggerConf}}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="sensor-data-conf-template" class="hidden">
|
<div id="action-data-conf-template" class="hidden">
|
||||||
{{#actionConf}}
|
{{#actionConf}}
|
||||||
<div id="{{.clazz.getName()}}">
|
<div id="{{.clazz.getName()}}">
|
||||||
{{#.params}}
|
{{#.params}}
|
||||||
|
|
|
||||||
|
|
@ -46,14 +46,14 @@ public class TriggerHttpPage extends HalHttpPage {
|
||||||
|
|
||||||
if(request.containsKey("action")){
|
if(request.containsKey("action")){
|
||||||
TriggerFlow flow = null;
|
TriggerFlow flow = null;
|
||||||
if (request.containsKey("flow_id"))
|
if (request.containsKey("flow-id") && !request.get("flow-id").isEmpty())
|
||||||
flow = TriggerFlow.getTriggerFlow(db, Integer.parseInt(request.get("flow_id")));
|
flow = TriggerFlow.getTriggerFlow(db, Integer.parseInt(request.get("flow-id")));
|
||||||
Trigger trigger = null;
|
Trigger trigger = null;
|
||||||
if (request.containsKey("trigger_id"))
|
if (request.containsKey("trigger-id") && !request.get("trigger-id").isEmpty())
|
||||||
trigger = Trigger.getTrigger(db, Integer.parseInt(request.get("trigger_id")));
|
trigger = Trigger.getTrigger(db, Integer.parseInt(request.get("trigger-id")));
|
||||||
Action action = null;
|
Action action = null;
|
||||||
if (request.containsKey("action_id"))
|
if (request.containsKey("action-id") && !request.get("action-id").isEmpty())
|
||||||
action = Action.getAction(db, Integer.parseInt(request.get("action_id")));
|
action = Action.getAction(db, Integer.parseInt(request.get("action-id")));
|
||||||
|
|
||||||
|
|
||||||
switch(request.get("action")) {
|
switch(request.get("action")) {
|
||||||
|
|
@ -68,10 +68,17 @@ public class TriggerHttpPage extends HalHttpPage {
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
case "create_trigger":
|
case "create_trigger":
|
||||||
//TODO: trigger = new HalTrigger();
|
if (flow == null){
|
||||||
|
HalAlertManager.getInstance().addAlert(new HalAlertManager.HalAlert(
|
||||||
|
HalAlertManager.AlertLevel.ERROR, "Invalid flow id", HalAlertManager.AlertTTL.ONE_VIEW));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
trigger = new Trigger();
|
||||||
flow.addTrigger(trigger);
|
flow.addTrigger(trigger);
|
||||||
|
/* FALLTHROUGH */
|
||||||
case "modify_trigger":
|
case "modify_trigger":
|
||||||
// TODO: save attrib
|
trigger.setObjectClass(request.get("type"));
|
||||||
|
trigger.getObjectConfigurator().setValues(request).applyConfiguration();
|
||||||
trigger.save(db);
|
trigger.save(db);
|
||||||
break;
|
break;
|
||||||
case "remove_trigger":
|
case "remove_trigger":
|
||||||
|
|
@ -81,10 +88,17 @@ public class TriggerHttpPage extends HalHttpPage {
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
case "create_action":
|
case "create_action":
|
||||||
//TODO: action = new HalAction();
|
if (flow == null){
|
||||||
|
HalAlertManager.getInstance().addAlert(new HalAlertManager.HalAlert(
|
||||||
|
HalAlertManager.AlertLevel.ERROR, "Invalid flow id", HalAlertManager.AlertTTL.ONE_VIEW));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
action = new Action();
|
||||||
flow.addAction(action);
|
flow.addAction(action);
|
||||||
|
/* FALLTHROUGH */
|
||||||
case "modify_action":
|
case "modify_action":
|
||||||
// TODO: save attrib
|
action.setObjectClass(request.get("type"));
|
||||||
|
action.getObjectConfigurator().setValues(request).applyConfiguration();
|
||||||
action.save(db);
|
action.save(db);
|
||||||
break;
|
break;
|
||||||
case "remove_action":
|
case "remove_action":
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
|
|
||||||
{"se.hal.intf.HalTrigger": "se.hal.trigger.DateTimeTrigger"},
|
{"se.hal.intf.HalTrigger": "se.hal.trigger.DateTimeTrigger"},
|
||||||
{"se.hal.intf.HalTrigger": "se.hal.trigger.TimerTrigger"}
|
{"se.hal.intf.HalTrigger": "se.hal.trigger.TimerTrigger"},
|
||||||
|
{"se.hal.intf.HalAction": "se.hal.trigger.action.SendEventAction"}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanObjectDSO;
|
import zutil.db.bean.DBBeanObjectDSO;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -21,7 +22,7 @@ public class Action extends DBBeanObjectDSO<HalAction>{
|
||||||
}
|
}
|
||||||
public static List<Action> getActions(DBConnection db, TriggerFlow flow) {
|
public static List<Action> getActions(DBConnection db, TriggerFlow flow) {
|
||||||
// TODO:
|
// TODO:
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanObjectDSO;
|
import zutil.db.bean.DBBeanObjectDSO;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,7 +23,7 @@ public class Trigger extends DBBeanObjectDSO<HalTrigger>{
|
||||||
}
|
}
|
||||||
public static List<Trigger> getTriggers(DBConnection db, TriggerFlow flow) {
|
public static List<Trigger> getTriggers(DBConnection db, TriggerFlow flow) {
|
||||||
// Todo:
|
// Todo:
|
||||||
return null;
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,6 @@ public class TimerTrigger implements HalTrigger {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
timer = new Timer(timerTime * 1000);
|
timer = new Timer(timerTime * 1000).start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
51
src/se/hal/trigger/action/SendEventAction.java
Executable file
51
src/se/hal/trigger/action/SendEventAction.java
Executable file
|
|
@ -0,0 +1,51 @@
|
||||||
|
package se.hal.trigger.action;
|
||||||
|
|
||||||
|
import se.hal.ControllerManager;
|
||||||
|
import se.hal.HalContext;
|
||||||
|
import se.hal.intf.HalAction;
|
||||||
|
import se.hal.intf.HalEventData;
|
||||||
|
import se.hal.struct.Event;
|
||||||
|
import zutil.db.DBConnection;
|
||||||
|
import zutil.log.LogUtil;
|
||||||
|
import zutil.ui.Configurator;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class SendEventAction implements HalAction {
|
||||||
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
|
|
||||||
|
@Configurator.Configurable(order = 1, value = "Event Device ID")
|
||||||
|
private int eventId;
|
||||||
|
@Configurator.Configurable(order = 1, value = "Data to Send")
|
||||||
|
private double data;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
try {
|
||||||
|
DBConnection db = HalContext.getDB();
|
||||||
|
Event event = Event.getEvent(db, eventId);
|
||||||
|
if (event != null) {
|
||||||
|
HalEventData dataObj = event.getDeviceConfig().getEventDataClass().newInstance();
|
||||||
|
dataObj.setData(data);
|
||||||
|
event.setDeviceData(dataObj);
|
||||||
|
// Send
|
||||||
|
ControllerManager.getInstance().send(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.warning("Unable to find event with id: "+ eventId);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.log(Level.SEVERE, null, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String toString(){
|
||||||
|
return "Send event: "+ eventId +" with data: "+ data;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue