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