diff --git a/.idea/artifacts/WasteInformationServer_main_jar.xml b/.idea/artifacts/WasteInformationServer_main_jar.xml new file mode 100644 index 0000000..233f7ea --- /dev/null +++ b/.idea/artifacts/WasteInformationServer_main_jar.xml @@ -0,0 +1,11 @@ + + + $PROJECT_DIR$/out/artifacts/WasteInformationServer_main_jar + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..e96534f --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/java/com/wasteinformationserver/Date.java b/src/java/com/wasteinformationserver/Dateget.java similarity index 87% rename from src/java/com/wasteinformationserver/Date.java rename to src/java/com/wasteinformationserver/Dateget.java index b6000cc..6ab8d4e 100644 --- a/src/java/com/wasteinformationserver/Date.java +++ b/src/java/com/wasteinformationserver/Dateget.java @@ -11,7 +11,7 @@ import java.util.ArrayList; import java.util.GregorianCalendar; import java.util.Scanner; -public class Date { +public class Dateget { private int index = 0; ArrayList list = new ArrayList<>(); ArrayList listnew = new ArrayList<>(); @@ -26,7 +26,7 @@ public class Date { URL url = null; try { - url = new URL("https://www.steyr.at/system/web/kalender.aspx?vdatum="+datum+"&bdatum=19.10.2019&typ=&typid=0&typids=225781950&detailonr=0&menuonr=225781812"); + url = new URL("https://www.steyr.at/system/web/kalender.aspx?vdatum=" + datum + "&bdatum=19.10.2019&typ=&typid=0&typids=225781950&detailonr=0&menuonr=225781812"); Scanner scanner = new Scanner(new InputStreamReader(url.openStream())); int n = 0; @@ -81,22 +81,19 @@ public class Date { String part1 = parts[0]; // 004 String part2 = parts[1]; // 034556*/ - splitter(); + splitter(); } } } } - private void splitter() - { - String temp="

"; + private void splitter() { + String temp = "

"; - for (int n=0; n redirecting to login page"); - sendPage("/index.html",t); + sendPage("/index.html", t); } - }else { //only detect login state on html pages + } else { //only detect login state on html pages sendPage(path, t); } } private void sendPage(String path, HttpExchange t) throws IOException { - InputStream fs = getClass().getResourceAsStream("/wwwroot"+path); + InputStream fs = getClass().getResourceAsStream("/wwwroot" + path); - if (fs== null && path.substring(path.length() - 4).equals("html")) { + if (fs == null && path.substring(path.length() - 4).equals("html")) { Log.warning("wrong page sending 404"); - sendPage("/404Error.html",t); - } else if(fs== null){ + sendPage("/404Error.html", t); + } else if (fs == null) { - }else { + } 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"; diff --git a/src/java/com/wasteinformationserver/website/Webserver.java b/src/java/com/wasteinformationserver/website/Webserver.java index 49369e3..3c8e3e4 100644 --- a/src/java/com/wasteinformationserver/website/Webserver.java +++ b/src/java/com/wasteinformationserver/website/Webserver.java @@ -3,11 +3,11 @@ package com.wasteinformationserver.website; import com.sun.net.httpserver.HttpServer; import com.wasteinformationserver.basicutils.Log; import com.wasteinformationserver.website.datarequests.AdminRequests; -import com.wasteinformationserver.website.datarequests.NewDateRequest; -import com.wasteinformationserver.website.datarequests.login.CheckLoginState; import com.wasteinformationserver.website.datarequests.DataRequest; -import com.wasteinformationserver.website.datarequests.login.LoginRequest; +import com.wasteinformationserver.website.datarequests.NewDateRequest; import com.wasteinformationserver.website.datarequests.RegisterRequest; +import com.wasteinformationserver.website.datarequests.login.CheckLoginState; +import com.wasteinformationserver.website.datarequests.login.LoginRequest; import java.io.IOException; import java.net.InetSocketAddress; diff --git a/src/java/com/wasteinformationserver/website/basicrequest/GetRequest.java b/src/java/com/wasteinformationserver/website/basicrequest/GetRequest.java index d64dd21..75e18bf 100644 --- a/src/java/com/wasteinformationserver/website/basicrequest/GetRequest.java +++ b/src/java/com/wasteinformationserver/website/basicrequest/GetRequest.java @@ -37,7 +37,6 @@ public abstract class GetRequest implements HttpHandler { } /** - * * @param params received get params from com.wasteinformationserver.website * @return json reply to com.wasteinformationserver.website */ diff --git a/src/java/com/wasteinformationserver/website/basicrequest/PostRequest.java b/src/java/com/wasteinformationserver/website/basicrequest/PostRequest.java index e3a60a6..f3d4917 100644 --- a/src/java/com/wasteinformationserver/website/basicrequest/PostRequest.java +++ b/src/java/com/wasteinformationserver/website/basicrequest/PostRequest.java @@ -20,7 +20,7 @@ public abstract class PostRequest implements HttpHandler { while ((i = ios.read()) != -1) { sb.append((char) i); } - String query = sb.toString(); + String query = sb.toString(); HashMap params = new HashMap<>(); @@ -44,7 +44,6 @@ public abstract class PostRequest implements HttpHandler { } /** - * * @param params received get params from com.wasteinformationserver.website * @return json reply to com.wasteinformationserver.website */ diff --git a/src/java/com/wasteinformationserver/website/datarequests/AdminRequests.java b/src/java/com/wasteinformationserver/website/datarequests/AdminRequests.java index 80da6a0..1a3262d 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/AdminRequests.java +++ b/src/java/com/wasteinformationserver/website/datarequests/AdminRequests.java @@ -1,7 +1,5 @@ package com.wasteinformationserver.website.datarequests; -import com.wasteinformationserver.basicutils.Log; -import com.wasteinformationserver.db.JDCB; import com.wasteinformationserver.website.basicrequest.PostRequest; import java.io.File; @@ -20,7 +18,7 @@ public class AdminRequests extends PostRequest { break; case "restartserver": final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; - File currentJar = null; + File currentJar = null; try { currentJar = new File(AdminRequests.class.getProtectionDomain().getCodeSource().getLocation().toURI()); } catch (URISyntaxException e) { @@ -28,7 +26,7 @@ public class AdminRequests extends PostRequest { } /* is it a jar file? */ - if(!currentJar.getName().endsWith(".jar")) + if (!currentJar.getName().endsWith(".jar")) System.out.println("not jar"); /* Build command: java -jar application.jar */ diff --git a/src/java/com/wasteinformationserver/website/datarequests/DataRequest.java b/src/java/com/wasteinformationserver/website/datarequests/DataRequest.java index 59efd52..216b4b5 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/DataRequest.java +++ b/src/java/com/wasteinformationserver/website/datarequests/DataRequest.java @@ -8,12 +8,15 @@ import java.io.IOException; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.SQLIntegrityConstraintViolationException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.HashMap; public class DataRequest extends PostRequest { @Override public String request(HashMap params) { - String result = ""; + StringBuilder sb = new StringBuilder(); + JDCB jdcb; try { jdcb = JDCB.getInstance(); @@ -23,7 +26,6 @@ public class DataRequest extends PostRequest { } switch (params.get("action")) { case "newCity": - StringBuilder sb = new StringBuilder(); sb.append("{"); Log.debug(params.toString()); @@ -67,23 +69,19 @@ public class DataRequest extends PostRequest { sb.append(",\"query\":\"ok\""); sb.append("}"); - - result = sb.toString(); break; case "getAllCities": - StringBuilder builder = new StringBuilder(); - ResultSet sett = jdcb.executeQuery("select * from cities"); Log.debug(sett.toString()); - builder.append("{\"data\":["); + sb.append("{\"data\":["); try { while (sett.next()) { - builder.append("{\"cityname\":\"" + sett.getString("name") + "\""); - builder.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\""); - builder.append(",\"id\":\"" + sett.getString("id") + "\""); - builder.append(",\"zone\":\"" + sett.getString("zone") + "\"}"); + sb.append("{\"cityname\":\"" + sett.getString("name") + "\""); + sb.append(",\"wastetype\":\"" + sett.getString("wastetype") + "\""); + sb.append(",\"id\":\"" + sett.getString("id") + "\""); + sb.append(",\"zone\":\"" + sett.getString("zone") + "\"}"); if (!sett.isLast()) { - builder.append(","); + sb.append(","); } // System.out.println(sett.getString("name")); @@ -91,43 +89,89 @@ public class DataRequest extends PostRequest { } catch (SQLException e) { e.printStackTrace(); } - builder.append("]"); - builder.append(",\"query\":\"ok\""); - builder.append("}"); - result = builder.toString(); - Log.debug(result); + sb.append("]"); + sb.append(",\"query\":\"ok\""); + sb.append("}"); break; case "deletecity": //DELETE FROM `cities` WHERE `id`=0 - - StringBuilder sbb = new StringBuilder(); // TODO: 06.12.19 better naming and sb for all - sbb.append("{"); + sb.append("{"); Log.debug(params.get("id")); int status = 0; - try{ - status= jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id")+"'"); - if (status == 1){ + try { + status = jdcb.executeUpdate("DELETE FROM `cities` WHERE `id`='" + params.get("id") + "'"); + if (status == 1) { //success - sbb.append("\"status\" : \"success\""); - }else { - sbb.append("\"status\" : \"error\""); + sb.append("\"status\" : \"success\""); + } else { + sb.append("\"status\" : \"error\""); } - }catch (SQLIntegrityConstraintViolationException e){ + } catch (SQLIntegrityConstraintViolationException e) { Log.warning("dependencies of deletion exist"); - sbb.append("\"status\" : \"dependenciesnotdeleted\""); + sb.append("\"status\" : \"dependenciesnotdeleted\""); } catch (SQLException e) { - Log.error("sql exception: "+e.getMessage()); - sbb.append("\"status\" : \"error\""); + Log.error("sql exception: " + e.getMessage()); + sb.append("\"status\" : \"error\""); } Log.debug(status); - sbb.append(",\"query\":\"ok\""); - sbb.append("}"); - result = sbb.toString(); + sb.append(",\"query\":\"ok\""); + sb.append("}"); + break; + case "getcollectionnumber": //todo maybe combine all three to one + sb.append("{"); + + try { + ResultSet settt = jdcb.executeQuery("select * from pickupdates"); + settt.last(); + sb.append("\"collectionnumber\":\"" + settt.getRow() + "\""); + } catch (SQLException e) { + Log.error("sql exception: " + e.getMessage()); + sb.append("\"status\" : \"error\""); + } + + sb.append(",\"query\":\"ok\""); + sb.append("}"); + break; + case "getcollectioninfuture": + sb.append("{"); + + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + String time = sdf.format(date); + ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '"+time+"' AND '2222-12-27'"); + settt.last(); + sb.append("\"collectionnumber\":\"" + settt.getRow() + "\""); + } catch (SQLException e) { + Log.error("sql exception: " + e.getMessage()); + sb.append("\"status\" : \"error\""); + } + + sb.append(",\"query\":\"ok\""); + sb.append("}"); + break; + case "getfinishedcollections": + sb.append("{"); + + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Date date = new Date(); + String time = sdf.format(date); + ResultSet settt = jdcb.executeQuery("SELECT * FROM `pickupdates` WHERE `pickupdate` BETWEEN '0000-12-27' AND '"+time+"'"); + settt.last(); + sb.append("\"collectionnumber\":\"" + settt.getRow() + "\""); + } catch (SQLException e) { + Log.error("sql exception: " + e.getMessage()); + sb.append("\"status\" : \"error\""); + } + + sb.append(",\"query\":\"ok\""); + sb.append("}"); break; } - return result; + return sb.toString(); } } diff --git a/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java b/src/java/com/wasteinformationserver/website/datarequests/RegisterRequest.java index 340cc71..66985f5 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());"); + 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());"); } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java b/src/java/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java index f0ae85d..fb05a32 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java +++ b/src/java/com/wasteinformationserver/website/datarequests/login/CheckLoginState.java @@ -9,13 +9,13 @@ public class CheckLoginState extends PostRequest { @Override public String request(HashMap params) { Log.message("checking login state"); - if ((params.get("action")).equals("getloginstate")){ - if (LoginState.getObject().isLoggedIn()){ - return "{\"loggedin\":true, \"username\":\""+LoginState.getObject().getUsername()+"\", \"permission\":\""+LoginState.getObject().getPermission()+"\"}"; - }else { + if ((params.get("action")).equals("getloginstate")) { + if (LoginState.getObject().isLoggedIn()) { + return "{\"loggedin\":true, \"username\":\"" + LoginState.getObject().getUsername() + "\", \"permission\":\"" + LoginState.getObject().getPermission() + "\"}"; + } else { return "{\"loggedin\":false}"; } - }else if ((params.get("action")).equals("logout")){ + } else if ((params.get("action")).equals("logout")) { Log.debug("logging out"); LoginState.getObject().logOut(); return "{\"loggedin\":false}"; diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java b/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java index f0a05b3..1739434 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java +++ b/src/java/com/wasteinformationserver/website/datarequests/login/LoginRequest.java @@ -27,7 +27,8 @@ public class LoginRequest extends PostRequest { return "{\"status\" : \"nodbconn\"}"; } - ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'");; + ResultSet s = jdcb.executeQuery("select * from user where username ='" + username + "'"); + ; //new JDCB("users", "kOpaIJUjkgb9ur6S", "wasteinformation").executeQuery("select * from user where username ='" + username + "'"); Log.debug("successfully logged in to db"); String response = "{\"accept\": false}"; @@ -38,7 +39,7 @@ public class LoginRequest extends PostRequest { if (HttpTools.StringToMD5(password).equals(s.getString("password"))) { Log.debug("login success"); LoginState.getObject().logIn(); - LoginState.getObject().setAccountData(username,"","","", s.getInt("permission")); // TODO: 06.12.19 + LoginState.getObject().setAccountData(username, "", "", "", s.getInt("permission")); // TODO: 06.12.19 response = "{\"accept\": true}"; } else { Log.debug("wrong password"); diff --git a/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java b/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java index 128f1d1..676e9ee 100644 --- a/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java +++ b/src/java/com/wasteinformationserver/website/datarequests/login/LoginState.java @@ -1,11 +1,12 @@ package com.wasteinformationserver.website.datarequests.login; public class LoginState { - private LoginState() {} + private LoginState() { + } - private static LoginState mythis=new LoginState(); + private static LoginState mythis = new LoginState(); - public static LoginState getObject(){ + public static LoginState getObject() { return mythis; } @@ -17,23 +18,23 @@ public class LoginState { boolean loggedin = true; - public void logIn(){ - loggedin=true; + public void logIn() { + loggedin = true; } - public void logOut(){ - loggedin=false; + public void logOut() { + loggedin = false; } - public void setAccountData(String username, String firstname, String lastname, String email, int permission){ - this.username=username; - this.firstname=firstname; - this.lastname=lastname; - this.email=email; + public void setAccountData(String username, String firstname, String lastname, String email, int permission) { + this.username = username; + this.firstname = firstname; + this.lastname = lastname; + this.email = email; this.permission = permission; } - public boolean isLoggedIn(){ + public boolean isLoggedIn() { return loggedin; } diff --git a/src/resources/wwwroot/dashboard.html b/src/resources/wwwroot/dashboard.html index 99b7f5c..61f673c 100644 --- a/src/resources/wwwroot/dashboard.html +++ b/src/resources/wwwroot/dashboard.html @@ -132,9 +132,9 @@
-

150

+

42

-

Totale Abholungen

+

Total collections

@@ -162,9 +162,9 @@
-

44

+

44

-

Geplante Abholungen

+

Planned Collections

@@ -177,9 +177,9 @@
-

65

+

65

-

Abgeschlossene Abholungen

+

Finished Collections

diff --git a/src/resources/wwwroot/js/dashboard.js b/src/resources/wwwroot/js/dashboard.js index 8b601b2..10c2227 100644 --- a/src/resources/wwwroot/js/dashboard.js +++ b/src/resources/wwwroot/js/dashboard.js @@ -12,6 +12,24 @@ $(document).ready(function () { } }, 'json'); + //load total collections + $.post('/senddata/wastedata', 'action=getcollectionnumber', function (data) { + console.log(data); + $("#total-connection-labels").html(data.collectionnumber); + }, 'json'); + + //load future collections + $.post('/senddata/wastedata', 'action=getcollectioninfuture', function (data) { + console.log(data); + $("#planed-collection-label").html(data.collectionnumber); + }, 'json'); + + //load future collections + $.post('/senddata/wastedata', 'action=getfinishedcollections', function (data) { + console.log(data); + $("#finished-collection-label").html(data.collectionnumber); + }, 'json'); + var citytable; function reloadtable() {