External sensors are editable from web
Former-commit-id: 64343310cae1cbd1b14343f170ea7adc66d11671
This commit is contained in:
parent
2823057e76
commit
046aea1a2c
5 changed files with 61 additions and 14 deletions
BIN
hal-default.db
BIN
hal-default.db
Binary file not shown.
4
src/se/koc/hal/deamon/DataDeletionDaemon.java
Normal file → Executable file
4
src/se/koc/hal/deamon/DataDeletionDaemon.java
Normal file → Executable file
|
|
@ -28,7 +28,7 @@ public class DataDeletionDaemon extends TimerTask implements HalDaemon {
|
|||
try {
|
||||
List<Sensor> sensorList = Sensor.getSensors(HalContext.getDB());
|
||||
for(Sensor sensor : sensorList){
|
||||
logger.fine("Deleting old data for sensor_id: " + sensor.getId());
|
||||
logger.fine("Deleting old data for sensor id: " + sensor.getId());
|
||||
aggregateSensor(sensor.getId());
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
|
@ -80,8 +80,6 @@ public class DataDeletionDaemon extends TimerTask implements HalDaemon {
|
|||
stmt.setLong(3, TimeConstants.HOUR_IN_MS-1);
|
||||
stmt.setLong(4, System.currentTimeMillis()-TimeConstants.SEVEN_DAYS_IN_MS);
|
||||
DBConnection.exec(stmt, new AggrDataDeletor(sensorId));
|
||||
|
||||
logger.fine("Done deleting");
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,10 +27,29 @@ public class PCConfigureHttpPage extends HalHttpPage {
|
|||
|
||||
// Save new input
|
||||
if(request.containsKey("action")){
|
||||
if(request.get("action").equals("update_user")){
|
||||
localUser.setUserName(request.get("username"));
|
||||
localUser.setAddress(request.get("address"));
|
||||
localUser.save(db);
|
||||
String action = request.get("action");
|
||||
switch(action) {
|
||||
case "modify_local_user":
|
||||
localUser.setUserName(request.get("username"));
|
||||
localUser.setAddress(request.get("address"));
|
||||
localUser.save(db);
|
||||
break;
|
||||
|
||||
case "create_local_sensor": break;
|
||||
case "modify_local_sensor": break;
|
||||
case "remove_local_sensor": break;
|
||||
|
||||
case "create_external_user": break;
|
||||
case "modify_external_user": break;
|
||||
case "remove_external_user": break;
|
||||
|
||||
case "modify_external_sensor":
|
||||
Sensor sensor = Sensor.getSensor(db, Integer.parseInt(request.get("id")));
|
||||
if(sensor != null){
|
||||
sensor.setSynced(Boolean.parseBoolean(request.get("sync")));
|
||||
sensor.save(db);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,13 +12,19 @@ import zutil.db.handler.SimpleSQLResult;
|
|||
|
||||
@DBBean.DBTable("sensor")
|
||||
public class Sensor extends DBBean{
|
||||
// Sensor specific data
|
||||
private String name;
|
||||
private long user_id;
|
||||
private String type;
|
||||
private String config;
|
||||
private long external_id;
|
||||
|
||||
|
||||
// User configuration
|
||||
private long user_id;
|
||||
private long external_id;
|
||||
/** local sensor= if sensor should be public. external sensor= if sensor should be requested from host **/
|
||||
private boolean sync;
|
||||
|
||||
|
||||
|
||||
public static List<Sensor> getExternalSensors(DBConnection db) throws SQLException{
|
||||
PreparedStatement stmt = db.getPreparedStatement( "SELECT sensor.* FROM sensor,user WHERE user.external == 1 AND user.id == sensor.user_id" );
|
||||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(Sensor.class, db) );
|
||||
|
|
@ -40,7 +46,11 @@ public class Sensor extends DBBean{
|
|||
return DBConnection.exec(stmt, DBBeanSQLResultHandler.createList(Sensor.class, db) );
|
||||
}
|
||||
|
||||
|
||||
public static Sensor getSensor(DBConnection db, int id) throws SQLException{
|
||||
return DBBean.load(db, Sensor.class, id);
|
||||
}
|
||||
|
||||
|
||||
public static long getHighestSequenceId(long sensorId) throws SQLException{
|
||||
PreparedStatement stmt = HalContext.getDB().getPreparedStatement("SELECT MAX(sequence_id) FROM sensor_data_aggr WHERE sensor_id == ?");
|
||||
stmt.setLong(1, sensorId);
|
||||
|
|
@ -74,4 +84,10 @@ public class Sensor extends DBBean{
|
|||
public void setExternalId(long external_id) {
|
||||
this.external_id = external_id;
|
||||
}
|
||||
public boolean isSynced() {
|
||||
return sync;
|
||||
}
|
||||
public void setSynced(boolean synced) {
|
||||
this.sync = synced;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
<div class="panel-heading">Profile Information</div>
|
||||
<div class="panel-body">
|
||||
<form class="form-horizontal" method="POST">
|
||||
<input type="hidden" name="action" value="update_user">
|
||||
<input type="hidden" name="action" value="modify_local_user">
|
||||
<div class="form-group">
|
||||
<label for="username" class="col-sm-2 control-label">Username:</label>
|
||||
<div class="col-sm-10">
|
||||
|
|
@ -130,8 +130,22 @@
|
|||
<td>{{.config}}</td>
|
||||
<td>
|
||||
<div class="btn-toolbar pull-right">
|
||||
<button class="btn btn-default btn-xs"><span class="glyphicon glyphicon-save"></span></button>
|
||||
<button class="btn btn-default btn-xs"><span class="glyphicon glyphicon-remove"></span></button>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="action" value="modify_external_sensor">
|
||||
<input type="hidden" name="id" value="{{.getId()}}">
|
||||
{{^.sync}}
|
||||
<input type="hidden" name="sync" value="true">
|
||||
<button type="submit" class="btn btn-default btn-xs" title="Start Syncing">
|
||||
<span class="glyphicon glyphicon-save"></span>
|
||||
</button>
|
||||
{{/.sync}}
|
||||
{{#.sync}}
|
||||
<input type="hidden" name="sync" value="false">
|
||||
<button type="submit" class="btn btn-danger btn-xs" title="Stop Syncing and Clear Data">
|
||||
<span class="glyphicon glyphicon-remove"></span>
|
||||
</button>
|
||||
{{/.sync}}
|
||||
</form>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue