added javadoc

This commit is contained in:
Lukas Heiligenbrunner 2020-03-13 11:04:09 +01:00
parent e28cfd4a20
commit 9f39b4f9c8
8 changed files with 126 additions and 2 deletions

View File

@ -8,6 +8,11 @@ import com.wasteinformationserver.mqtt.MqttService
import com.wasteinformationserver.website.Webserver import com.wasteinformationserver.website.Webserver
import java.io.IOException import java.io.IOException
/**
* application entry point
*
* @author Lukas Heiligenbrunner
*/
fun main() { fun main() {
Log.setLevel(Log.DEBUG) Log.setLevel(Log.DEBUG)
Info.init() Info.init()

View File

@ -7,6 +7,11 @@ import com.wasteinformationserver.basicutils.Log.Log.warning
import com.wasteinformationserver.website.datarequests.login.LoginState import com.wasteinformationserver.website.datarequests.login.LoginState
import java.io.IOException import java.io.IOException
/**
* Http handler to deliver all the main pages (index.html ...)
*
* @author Lukas Heiligenbrunner
*/
class MainPage : HttpHandler { class MainPage : HttpHandler {
@Throws(IOException::class) @Throws(IOException::class)
override fun handle(t: HttpExchange) { override fun handle(t: HttpExchange) {

View File

@ -10,6 +10,11 @@ import java.io.IOException
import java.net.BindException import java.net.BindException
import java.net.InetSocketAddress import java.net.InetSocketAddress
/**
* class to create the website nodes at specific paths
*
* @author Lukas Heiligenbrunner
*/
class Webserver { class Webserver {
fun startserver() { fun startserver() {
info("starting Webserver") info("starting Webserver")

View File

@ -9,14 +9,25 @@ import java.net.URISyntaxException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
/**
* all requests for Admin page
*
* @author Lukas Heiligenbrunner
*/
public class AdminRequests extends PostRequest { public class AdminRequests extends PostRequest {
@Override @Override
public String request(HashMap<String, String> params) { public String request(HashMap<String, String> params) {
String result = ""; String result = "";
switch (params.get("action")) { switch (params.get("action")) {
/**
* shut down the whole application
*/
case "shutdownserver": case "shutdownserver":
System.exit(0); System.exit(0);
break; break;
/**
* restart the server application
*/
case "restartserver": case "restartserver":
final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java"; final String javaBin = System.getProperty("java.home") + File.separator + "bin" + File.separator + "java";
File currentJar = null; File currentJar = null;

View File

@ -13,6 +13,11 @@ import java.sql.SQLIntegrityConstraintViolationException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
/**
* General Datarequests for Dashboard
*
* @author Lukas Heiligenbrunner
*/
class DataRequest : PostRequest() { class DataRequest : PostRequest() {
override fun request(params: HashMap<String, String>): String { override fun request(params: HashMap<String, String>): String {
val sb = StringBuilder() val sb = StringBuilder()
@ -25,6 +30,9 @@ class DataRequest : PostRequest() {
return "{\"query\" : \"nodbconn\"}" return "{\"query\" : \"nodbconn\"}"
} }
when (params["action"]) { when (params["action"]) {
/**
* create a new city entry in db
*/
"newCity" -> { "newCity" -> {
sb.append("{") sb.append("{")
debug(params.toString()) debug(params.toString())
@ -63,6 +71,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* return all defined cities from db
*/
"getAllCities" -> { "getAllCities" -> {
set = jdbc.executeQuery("select * from cities") set = jdbc.executeQuery("select * from cities")
debug(set.toString()) debug(set.toString())
@ -84,6 +95,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* delete a specific city
*/
"deletecity" -> { "deletecity" -> {
//DELETE FROM `cities` WHERE `id`=0 //DELETE FROM `cities` WHERE `id`=0
sb.append("{") sb.append("{")
@ -106,6 +120,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* returns all configured dates with its city and zone
*/
"getAllDates" -> { "getAllDates" -> {
set = jdbc.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " + set = jdbc.executeQuery("SELECT pickupdates.id,pickupdates.pickupdate,cities.userid,cities.name,cities.wastetype,cities.zone " +
"FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id") "FROM `pickupdates` INNER JOIN `cities` ON pickupdates.citywastezoneid = cities.id")
@ -128,6 +145,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* delete a specific date
*/
"deletedate" -> { "deletedate" -> {
sb.append("{") sb.append("{")
try { try {
@ -148,6 +168,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* return version foot data
*/
"getversionandbuildtime" -> { "getversionandbuildtime" -> {
sb.append("{") sb.append("{")
sb.append("\"version\" : \"" + Info.getVersion() + "\"") sb.append("\"version\" : \"" + Info.getVersion() + "\"")
@ -155,6 +178,9 @@ class DataRequest : PostRequest() {
sb.append(",\"query\":\"ok\"") sb.append(",\"query\":\"ok\"")
sb.append("}") sb.append("}")
} }
/**
* return head data with basic collection infos
*/
"getStartHeaderData" -> { "getStartHeaderData" -> {
sb.append("{") sb.append("{")
try { try {

View File

@ -9,6 +9,11 @@ import java.sql.ResultSet
import java.sql.SQLException import java.sql.SQLException
import java.util.* import java.util.*
/**
* Class for all requests on device Page
*
* @author Lukas Heiligenbrunner
*/
class DeviceRequest : PostRequest() { class DeviceRequest : PostRequest() {
override fun request(params: HashMap<String, String>): String { override fun request(params: HashMap<String, String>): String {
var jdbc: JDBC? = null var jdbc: JDBC? = null
@ -20,6 +25,9 @@ class DeviceRequest : PostRequest() {
val sb = StringBuilder() val sb = StringBuilder()
var deviceset: ResultSet var deviceset: ResultSet
when (params["action"]) { when (params["action"]) {
/**
* return all available devices
*/
"getdevices" -> { "getdevices" -> {
deviceset = jdbc!!.executeQuery("SELECT * FROM `devices") deviceset = jdbc!!.executeQuery("SELECT * FROM `devices")
sb.append("{\"data\":[") sb.append("{\"data\":[")
@ -56,6 +64,9 @@ class DeviceRequest : PostRequest() {
e.printStackTrace() e.printStackTrace()
} }
} }
/**
* returns all available city names
*/
"getCitynames" -> { "getCitynames" -> {
deviceset = jdbc!!.executeQuery("select * from cities") deviceset = jdbc!!.executeQuery("select * from cities")
debug(deviceset.toString()) debug(deviceset.toString())
@ -77,6 +88,9 @@ class DeviceRequest : PostRequest() {
sb.append("}") sb.append("}")
debug(sb.toString()) debug(sb.toString())
} }
/**
* returns all available zones for specified city
*/
"getzones" -> { "getzones" -> {
deviceset = jdbc!!.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' ORDER BY zone ASC") deviceset = jdbc!!.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' ORDER BY zone ASC")
debug(deviceset.toString()) debug(deviceset.toString())
@ -97,6 +111,9 @@ class DeviceRequest : PostRequest() {
} }
sb.append("}") sb.append("}")
} }
/**
* returns all available waste types for specified zone and city
*/
"gettypes" -> { "gettypes" -> {
deviceset = jdbc!!.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zonename"] + "' ORDER BY zone ASC") deviceset = jdbc!!.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zonename"] + "' ORDER BY zone ASC")
debug(deviceset.toString()) debug(deviceset.toString())
@ -117,6 +134,9 @@ class DeviceRequest : PostRequest() {
} }
sb.append("}") sb.append("}")
} }
/**
* configure device and save infos to db
*/
"savetodb" -> try { "savetodb" -> try {
val cityset = jdbc!!.executeQuery("SELECT id from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zonename"] + "' AND `wastetype`='" + params["wastetype"] + "'") val cityset = jdbc!!.executeQuery("SELECT id from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zonename"] + "' AND `wastetype`='" + params["wastetype"] + "'")
cityset.last() cityset.last()
@ -133,6 +153,9 @@ class DeviceRequest : PostRequest() {
} catch (e: SQLException) { } catch (e: SQLException) {
e.printStackTrace() e.printStackTrace()
} }
/**
* delete a configured device from db
*/
"deleteDevice" -> { "deleteDevice" -> {
try { try {
jdbc!!.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params["id"] + "'") jdbc!!.executeUpdate("DELETE FROM devices WHERE `DeviceID`='" + params["id"] + "'")
@ -142,6 +165,9 @@ class DeviceRequest : PostRequest() {
} }
sb.append("{\"status\":\"success\"}") sb.append("{\"status\":\"success\"}")
} }
/**
* add new city/zone/type to db to existing one
*/
"addtodb" -> { "addtodb" -> {
var cityid = -1 var cityid = -1
try { try {
@ -154,6 +180,9 @@ class DeviceRequest : PostRequest() {
} }
sb.append("{\"success\":true}") sb.append("{\"success\":true}")
} }
/**
* return header information such as devicenumber and number of unconfigured devices
*/
"getheader" -> { "getheader" -> {
try { try {
var numberset = jdbc!!.executeQuery("SELECT * FROM devices") var numberset = jdbc!!.executeQuery("SELECT * FROM devices")

View File

@ -9,6 +9,11 @@ import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
/**
* todo
*
* @author Lukas Heiligenbrunner
*/
public class NewDateRequest extends PostRequest { public class NewDateRequest extends PostRequest {
@Override @Override
public String request(HashMap<String, String> params) { public String request(HashMap<String, String> params) {

View File

@ -1,12 +1,16 @@
package com.wasteinformationserver.website.datarequests.login; package com.wasteinformationserver.website.datarequests.login;
/** /**
* * singleton representing the login state of the user
*/ */
public class LoginState { public class LoginState {
private static LoginState mythis = new LoginState(); private static LoginState mythis = new LoginState();
/**
* get object
* @return LoginState instance
*/
public static LoginState getObject() { public static LoginState getObject() {
return mythis; return mythis;
} }
@ -17,16 +21,26 @@ public class LoginState {
private String email; private String email;
private int permission; private int permission;
boolean loggedin = false; private boolean loggedin = false;
/**
* login the user
*/
public void logIn() { public void logIn() {
loggedin = true; loggedin = true;
} }
/**
* logout the user
*/
public void logOut() { public void logOut() {
loggedin = false; loggedin = false;
} }
/**
* set the account infos
* username, firstname, lastname, email and permission level
*/
public void setAccountData(String username, String firstname, String lastname, String email, int permission) { public void setAccountData(String username, String firstname, String lastname, String email, int permission) {
this.username = username; this.username = username;
this.firstname = firstname; this.firstname = firstname;
@ -35,26 +49,50 @@ public class LoginState {
this.permission = permission; this.permission = permission;
} }
/**
* check if user is logged in
* @return loginstate
*/
public boolean isLoggedIn() { public boolean isLoggedIn() {
return loggedin; return loggedin;
} }
/**
* get username
* @return username
*/
public String getUsername() { public String getUsername() {
return username; return username;
} }
/**
* get firstname
* @return firstname
*/
public String getFirstname() { public String getFirstname() {
return firstname; return firstname;
} }
/**
* get lastname
* @return lastname
*/
public String getLastname() { public String getLastname() {
return lastname; return lastname;
} }
/**
* get email address
* @return mail address
*/
public String getEmail() { public String getEmail() {
return email; return email;
} }
/**
* get permission level
* @return level as int
*/
public int getPermission() { public int getPermission() {
return permission; return permission;
} }