Local user is now configurable
Former-commit-id: 19d9d740432459ec65488e5a8b59e1c5719f8001
This commit is contained in:
parent
84fd5adb5e
commit
4ac7dcdea7
4 changed files with 44 additions and 38 deletions
|
|
@ -9,7 +9,6 @@ import java.net.UnknownHostException;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
@ -39,10 +38,10 @@ public class DataSynchronizationClient extends TimerTask implements HalDaemon{
|
||||||
List<User> users = User.getExternalUsers(db);
|
List<User> users = User.getExternalUsers(db);
|
||||||
for(User user : users){
|
for(User user : users){
|
||||||
if(user.getHostname() == null){
|
if(user.getHostname() == null){
|
||||||
logger.fine("Hostname not defined for user: "+ user.getName());
|
logger.fine("Hostname not defined for user: "+ user.getUserName());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
logger.fine("Synchronizing user: "+ user.getName() +" ("+user.getHostname()+":"+user.getPort()+")");
|
logger.fine("Synchronizing user: "+ user.getUserName() +" ("+user.getHostname()+":"+user.getPort()+")");
|
||||||
try (Socket s = new Socket(user.getHostname(), user.getPort());){
|
try (Socket s = new Socket(user.getHostname(), user.getPort());){
|
||||||
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
ObjectOutputStream out = new ObjectOutputStream(s.getOutputStream());
|
||||||
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
ObjectInputStream in = new ObjectInputStream(s.getInputStream());
|
||||||
|
|
@ -72,7 +71,7 @@ public class DataSynchronizationClient extends TimerTask implements HalDaemon{
|
||||||
stmt.setFloat(6, data.confidence);
|
stmt.setFloat(6, data.confidence);
|
||||||
DBConnection.exec(stmt);
|
DBConnection.exec(stmt);
|
||||||
}
|
}
|
||||||
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getName());
|
logger.fine("Stored " + dataList.size() + " entries for sensor " + sensor.getId() + " from " + user.getUserName());
|
||||||
}
|
}
|
||||||
out.writeObject(null);
|
out.writeObject(null);
|
||||||
out.close();
|
out.close();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package se.koc.hal.page;
|
package se.koc.hal.page;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import se.koc.hal.HalContext;
|
import se.koc.hal.HalContext;
|
||||||
|
|
@ -9,9 +7,6 @@ import se.koc.hal.struct.Sensor;
|
||||||
import se.koc.hal.struct.User;
|
import se.koc.hal.struct.User;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.io.file.FileUtil;
|
import zutil.io.file.FileUtil;
|
||||||
import zutil.net.http.HttpHeaderParser;
|
|
||||||
import zutil.net.http.HttpPage;
|
|
||||||
import zutil.net.http.HttpPrintStream;
|
|
||||||
import zutil.parser.Templator;
|
import zutil.parser.Templator;
|
||||||
|
|
||||||
public class PCConfigureHttpPage extends HalHttpPage {
|
public class PCConfigureHttpPage extends HalHttpPage {
|
||||||
|
|
@ -21,23 +16,33 @@ public class PCConfigureHttpPage extends HalHttpPage {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Templator httpRespond(
|
public Templator httpRespond(
|
||||||
Map<String, Object> session,
|
Map<String, Object> session,
|
||||||
Map<String, String> cookie,
|
Map<String, String> cookie,
|
||||||
Map<String, String> request)
|
Map<String, String> request)
|
||||||
throws Exception{
|
throws Exception{
|
||||||
|
|
||||||
|
DBConnection db = HalContext.getDB();
|
||||||
|
User localUser = User.getLocalUser(db);
|
||||||
|
|
||||||
DBConnection db = HalContext.getDB();
|
// Save new input
|
||||||
|
if(request.containsKey("form")){
|
||||||
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
|
if(request.get("form").equals("user")){
|
||||||
tmpl.set("user", User.getLocalUser(db));
|
localUser.setUserName(request.get("username"));
|
||||||
tmpl.set("localSensor", Sensor.getLocalSensors(db));
|
localUser.setAddress(request.get("address"));
|
||||||
tmpl.set("extUsers", User.getExternalUsers(db));
|
localUser.save(db);
|
||||||
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return tmpl;
|
// Output
|
||||||
|
Templator tmpl = new Templator(FileUtil.find("web-resource/configure.tmpl"));
|
||||||
|
tmpl.set("user", localUser);
|
||||||
|
tmpl.set("localSensor", Sensor.getLocalSensors(db));
|
||||||
|
tmpl.set("extUsers", User.getExternalUsers(db));
|
||||||
|
tmpl.set("extSensor", Sensor.getExternalSensors(db));
|
||||||
|
|
||||||
}
|
return tmpl;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
||||||
import zutil.db.DBConnection;
|
import zutil.db.DBConnection;
|
||||||
import zutil.db.bean.DBBean;
|
import zutil.db.bean.DBBean;
|
||||||
import zutil.db.bean.DBBeanSQLResultHandler;
|
import zutil.db.bean.DBBeanSQLResultHandler;
|
||||||
|
import zutil.ui.Configurator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Ziver on 2015-12-03.
|
* Created by Ziver on 2015-12-03.
|
||||||
|
|
@ -37,10 +38,10 @@ public class User extends DBBean{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getName() {
|
public String getUserName() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
public void setName(String name) {
|
public void setUserName(String name) {
|
||||||
this.username = name;
|
this.username = name;
|
||||||
}
|
}
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,20 @@
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-heading">Profile Information</div>
|
<div class="panel-heading">Profile Information</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<form>
|
<form method="POST">
|
||||||
<hidden id="id" value="{{user.getId()}}">
|
<input type="hidden" name="form" value="user">
|
||||||
<div class="form-group col-md-4">
|
<input type="hidden" name="id" value="{{user.getId()}}">
|
||||||
<label for="username">Username</label>
|
<div class="form-group col-md-4">
|
||||||
<input type="text" class="form-control" id="username" value="{{user.username}}">
|
<label for="username">Username</label>
|
||||||
</div>
|
<input type="text" class="form-control" id="username" name="username" value="{{user.username}}">
|
||||||
<div class="form-group col-md-8">
|
</div>
|
||||||
<label for="address">Address</label>
|
<div class="form-group col-md-8">
|
||||||
<input type="text" class="form-control" id="address" value="{{user.address}}">
|
<label for="address">Address</label>
|
||||||
</div>
|
<input type="text" class="form-control" id="address" name="address" value="{{user.address}}">
|
||||||
<div class="col-md-12">
|
</div>
|
||||||
<button type="submit" class="btn btn-default">Save</button>
|
<div class="col-md-12">
|
||||||
</div>
|
<button type="submit" class="btn btn-default pull-right">Save</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue