Update & Delete users, adds username to control requests

This commit is contained in:
Patrick McDonagh
2017-03-02 10:41:48 -06:00
parent 5e4a06ddf1
commit 082c13666b
5 changed files with 227 additions and 51 deletions

View File

@@ -49,37 +49,42 @@ public class WebServer{
public void handle(HttpExchange t) throws IOException {
JSONObject respJSON = new JSONObject();
Map<String, String> params = queryToMap(t.getRequestURI().getQuery());
String action = "";
String user = "";
for(Map.Entry<String, String> param_map : params.entrySet()){
String key = param_map.getKey();
String param = param_map.getValue();
switch (key){
case "start":
if(param.equals("true")) {
attachedPOC.thisWell.start("web");
respJSON.put("startCommand", "true");
respJSON.put("status", attachedPOC.thisWell.getRunStatusString());
} else {
respJSON.put("startCommand", "invalid value - " + param);
}
switch (key) {
case "cmd":
action = param;
break;
case "stop":
if(param.equals("true")) {
attachedPOC.thisWell.stop("web");
respJSON.put("stopCommand", "true");
respJSON.put("status", attachedPOC.thisWell.getRunStatusString());
} else {
respJSON.put("stopCommand", "invalid value - " + param);
}
case "user":
user = param;
break;
default:
respJSON.put(key, "not implemented");
}
}
if ((user.length() > 0) && (action.length() > 0)) {
switch (action) {
case "start":
attachedPOC.thisWell.start(user);
respJSON.put("startCommand", "true");
respJSON.put("status", attachedPOC.thisWell.getRunStatusString());
break;
case "stop":
attachedPOC.thisWell.stop(user);
respJSON.put("stopCommand", "true");
respJSON.put("status", attachedPOC.thisWell.getRunStatusString());
break;
default:
respJSON.put(action, "not implemented");
break;
}
} else {
respJSON.put("bad request", "cmd and user parameters required");
}
String response = respJSON.toJSONString();
t.sendResponseHeaders(200, response.getBytes().length);