From c590b612b5061ecaae316ad038b203a88205fffc Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Mon, 20 Jan 2020 18:20:37 +0100 Subject: [PATCH] some name and warning fixings --- build.gradle | 2 +- .../{main.java => Main.java} | 6 ++--- .../mqtt/MqttService.java | 2 +- .../website/MainPage.java | 5 ++-- .../website/datarequests/DeviceRequest.java | 24 +++++++------------ .../website/datarequests/RegisterRequest.java | 2 +- 6 files changed, 18 insertions(+), 23 deletions(-) rename src/java/com/wasteinformationserver/{main.java => Main.java} (87%) diff --git a/build.gradle b/build.gradle index cf09ad6..528a7f7 100644 --- a/build.gradle +++ b/build.gradle @@ -32,7 +32,7 @@ dependencies { task run (type: JavaExec){ description = "Secure algorythm testing" - main = 'com.wasteinformationserver.main' + main = 'com.wasteinformationserver.Main' classpath = sourceSets.main.runtimeClasspath } diff --git a/src/java/com/wasteinformationserver/main.java b/src/java/com/wasteinformationserver/Main.java similarity index 87% rename from src/java/com/wasteinformationserver/main.java rename to src/java/com/wasteinformationserver/Main.java index 0db24cf..15710d1 100644 --- a/src/java/com/wasteinformationserver/main.java +++ b/src/java/com/wasteinformationserver/Main.java @@ -8,7 +8,7 @@ import com.wasteinformationserver.website.Webserver; import java.io.IOException; -public class main { +public class Main { public static void main(String[] args) { Log.setLevel(Log.DEBUG); Info.init(); @@ -32,8 +32,8 @@ public class main { //initial connect to db Log.message("initial login to db"); try { - //JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); - JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); + JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306); + //JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306); } catch (IOException e) { //e.printStackTrace(); Log.error("no connection to db"); diff --git a/src/java/com/wasteinformationserver/mqtt/MqttService.java b/src/java/com/wasteinformationserver/mqtt/MqttService.java index 97213ba..46e5e58 100644 --- a/src/java/com/wasteinformationserver/mqtt/MqttService.java +++ b/src/java/com/wasteinformationserver/mqtt/MqttService.java @@ -21,7 +21,7 @@ public class MqttService { try { db = JDBC.getInstance(); } catch (IOException e) { - e.printStackTrace(); + Log.error("no connetion to db"); } } diff --git a/src/java/com/wasteinformationserver/website/MainPage.java b/src/java/com/wasteinformationserver/website/MainPage.java index 319bf61..87c1bab 100644 --- a/src/java/com/wasteinformationserver/website/MainPage.java +++ b/src/java/com/wasteinformationserver/website/MainPage.java @@ -57,8 +57,9 @@ public class MainPage implements HttpHandler { } else { // Object exists and is a file: accept with response code 200. String mime = "text/html"; - if (path.substring(path.length() - 3).equals(".js")) mime = "application/javascript"; - if (path.substring(path.length() - 3).equals("css")) mime = "text/css"; + final String s = path.substring(path.length() - 3); + if (s.equals(".js")) mime = "application/javascript"; + if (s.equals("css")) mime = "text/css"; Headers h = t.getResponseHeaders(); h.set("Content-Type", mime); diff --git a/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java index 7fa9eaf..f087b4c 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java +++ b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java @@ -15,7 +15,7 @@ public class DeviceRequest extends PostRequest { JDBC jdbc = null; try { - jdbc = jdbc.getInstance(); + jdbc = JDBC.getInstance(); } catch (IOException e) { e.printStackTrace(); } @@ -37,7 +37,7 @@ public class DeviceRequest extends PostRequest { int deviceid = setunconfigured.getInt("DeviceID"); int cityid = setunconfigured.getInt("CityID"); - sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\"}"); + sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"cityid\":\"").append(cityid).append("\"}"); if (!(setunconfigured.isLast() && configsize == 0)) { sb.append(","); @@ -55,7 +55,7 @@ public class DeviceRequest extends PostRequest { String wastetype = setconfigured.getString("wastetype"); String zone = setconfigured.getString("zone"); - sb.append("{\"deviceid\":\"" + deviceid + "\",\"cityid\":\"" + cityid + "\",\"devicename\":\"" + devicename + "\",\"devicelocation\":\"" + devicelocation + "\",\"cityname\":\"" + cityname + "\",\"wastetype\":\"" + wastetype + "\",\"zone\":\"" + zone + "\"}"); + sb.append("{\"deviceid\":\"").append(deviceid).append("\",\"cityid\":\"").append(cityid).append("\",\"devicename\":\"").append(devicename).append("\",\"devicelocation\":\"").append(devicelocation).append("\",\"cityname\":\"").append(cityname).append("\",\"wastetype\":\"").append(wastetype).append("\",\"zone\":\"").append(zone).append("\"}"); if (!setconfigured.isLast()) { sb.append(","); @@ -74,13 +74,11 @@ public class DeviceRequest extends PostRequest { try { String prev = ""; while (setunconfigured.next()) { - if (prev.equals(setunconfigured.getString("name"))) { - - } else { + if (!prev.equals(setunconfigured.getString("name"))) { if (!setunconfigured.isFirst()) { sb.append(","); } - sb.append("\"" + setunconfigured.getString("name") + "\":\"" + setunconfigured.getString("name") + "\""); + sb.append("\"").append(setunconfigured.getString("name")).append("\":\"").append(setunconfigured.getString("name")).append("\""); } prev = setunconfigured.getString("name"); } @@ -97,10 +95,8 @@ public class DeviceRequest extends PostRequest { try { int prev = 42; while (setunconfigured.next()) { - if (prev == setunconfigured.getInt("zone")) { - - } else { - sb.append("\"" + setunconfigured.getInt("zone") + "\":\"" + setunconfigured.getInt("zone") + "\""); + if (prev != setunconfigured.getInt("zone")) { + sb.append("\"").append(setunconfigured.getInt("zone")).append("\":\"").append(setunconfigured.getInt("zone")).append("\""); if (!setunconfigured.isLast()) { sb.append(","); } @@ -119,9 +115,7 @@ public class DeviceRequest extends PostRequest { try { String prev = "42"; while (setunconfigured.next()) { - if (prev == setunconfigured.getString("wastetype")) { - - } else { + if (!prev.equals(setunconfigured.getString("wastetype"))) { sb.append("\"" + setunconfigured.getString("wastetype") + "\":\"" + setunconfigured.getString("wastetype") + "\""); if (!setunconfigured.isLast()) { sb.append(","); @@ -151,7 +145,7 @@ public class DeviceRequest extends PostRequest { break; case "deleteDevice": try { - int res = jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'"); + jdbc.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params.get("id") + "'"); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java b/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java index 6e203af..0721068 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java +++ b/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java @@ -24,7 +24,7 @@ public class RegisterRequest extends PostRequest { } //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation"); try { - int s = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());"); + myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params.get("username") + "', '" + params.get("firstname") + "', '" + params.get("lastname") + "', '" + passhash + "', '" + params.get("email") + "', current_timestamp());"); } catch (SQLException e) { e.printStackTrace(); }