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 java.io.IOException
/**
* application entry point
*
* @author Lukas Heiligenbrunner
*/
fun main() {
Log.setLevel(Log.DEBUG)
Info.init()

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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