code cleanup
deleted deadcode
This commit is contained in:
parent
b3fcd26964
commit
f4a00620a3
@ -40,7 +40,7 @@ task run (type: JavaExec){
|
|||||||
|
|
||||||
task createProperties(dependsOn: processResources) {
|
task createProperties(dependsOn: processResources) {
|
||||||
doLast {
|
doLast {
|
||||||
new File("$projectDir/src/resources/version.properties").withWriter { w ->
|
new File("$projectDir/src/resources/version.prop").withWriter { w ->
|
||||||
Properties p = new Properties()
|
Properties p = new Properties()
|
||||||
p['version'] = project.version.toString()
|
p['version'] = project.version.toString()
|
||||||
p['buildtime'] = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date())
|
p['buildtime'] = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date())
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
/**
|
|
||||||
* dead code...
|
|
||||||
*/
|
|
||||||
package com.wasteinformationserver;
|
|
||||||
|
|
||||||
import com.wasteinformationserver.basicutils.Log;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.GregorianCalendar;
|
|
||||||
import java.util.Scanner;
|
|
||||||
|
|
||||||
public class Dateget {
|
|
||||||
private int index = 0;
|
|
||||||
ArrayList<String> list = new ArrayList<>();
|
|
||||||
ArrayList<String> listnew = new ArrayList<>();
|
|
||||||
public String nextDate;
|
|
||||||
|
|
||||||
|
|
||||||
public void getdata() {
|
|
||||||
|
|
||||||
GregorianCalendar now = new GregorianCalendar();
|
|
||||||
DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM);
|
|
||||||
String datum = df.format(now.getTime());
|
|
||||||
|
|
||||||
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");
|
|
||||||
Scanner scanner = new Scanner(new InputStreamReader(url.openStream()));
|
|
||||||
|
|
||||||
int n = 0;
|
|
||||||
while (scanner.hasNext()) {
|
|
||||||
String temp = scanner.next();
|
|
||||||
addList(temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
Filter();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addList(String temp) {
|
|
||||||
list.add(index, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printList() {
|
|
||||||
for (int n = 0; n < list.size(); n++) {
|
|
||||||
Log.Log.debug(list.get(n));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printListnew() {
|
|
||||||
for (int n = 0; n < listnew.size(); n++) {
|
|
||||||
Log.Log.debug(listnew.get(n));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Filter() {
|
|
||||||
String temp = "href=\"/system/web/kalender.aspx?detailonr=225781954-6&menuonr=225781812\">Hausabfall";
|
|
||||||
int counter = 0;
|
|
||||||
|
|
||||||
for (int n = 0; n < list.size(); n++) {
|
|
||||||
if (list.get(n).equals(temp)) {
|
|
||||||
counter++;
|
|
||||||
|
|
||||||
if (counter == 4) {
|
|
||||||
|
|
||||||
int zaehler = 0;
|
|
||||||
|
|
||||||
for (int v = n; v < list.size(); v++) {
|
|
||||||
listnew.add(zaehler, list.get(v));
|
|
||||||
zaehler++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* String string = "004-034556";
|
|
||||||
String[] parts = string.split("-");
|
|
||||||
String part1 = parts[0]; // 004
|
|
||||||
String part2 = parts[1]; // 034556*/
|
|
||||||
|
|
||||||
splitter();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void splitter() {
|
|
||||||
String temp = "</ul><h2>";
|
|
||||||
|
|
||||||
for (int n = 0; n < listnew.size(); n++) {
|
|
||||||
|
|
||||||
if (listnew.get(n).equals(temp)) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -36,6 +36,7 @@ fun main() {
|
|||||||
Log.message("initial login to db")
|
Log.message("initial login to db")
|
||||||
try {
|
try {
|
||||||
JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306)
|
JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306)
|
||||||
|
// todo make dynamic with settings page
|
||||||
//JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
//JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
||||||
} catch (e: IOException) { //e.printStackTrace();
|
} catch (e: IOException) { //e.printStackTrace();
|
||||||
Log.error("no connection to db")
|
Log.error("no connection to db")
|
||||||
@ -50,6 +51,6 @@ fun main() {
|
|||||||
//startup mqtt service
|
//startup mqtt service
|
||||||
Log.message("starting mqtt service")
|
Log.message("starting mqtt service")
|
||||||
|
|
||||||
val m = MqttService("mqtt.heili.eu", "1883")
|
val m = MqttService("mqtt.heili.eu", "1883") // todo make dynamic with settings page
|
||||||
m.startupService()
|
m.startupService()
|
||||||
}
|
}
|
@ -51,7 +51,7 @@ public class Info {
|
|||||||
starttime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
|
starttime = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss").format(new Date());
|
||||||
Properties prop = new Properties();
|
Properties prop = new Properties();
|
||||||
try {
|
try {
|
||||||
URL url = Info.class.getResource("/version.properties");
|
URL url = Info.class.getResource("/version.prop");
|
||||||
|
|
||||||
prop.load(url.openStream());
|
prop.load(url.openStream());
|
||||||
version = (String) prop.get("version");
|
version = (String) prop.get("version");
|
||||||
@ -75,10 +75,10 @@ public class Info {
|
|||||||
long allocatedMemory = runtime.totalMemory();
|
long allocatedMemory = runtime.totalMemory();
|
||||||
long freeMemory = runtime.freeMemory();
|
long freeMemory = runtime.freeMemory();
|
||||||
|
|
||||||
sb.append("free memory: " + format.format(freeMemory / 1024) + "\n");
|
sb.append("free memory: ").append(format.format(freeMemory / 1024)).append("\n");
|
||||||
sb.append("allocated memory: " + format.format(allocatedMemory / 1024) + "\n");
|
sb.append("allocated memory: ").append(format.format(allocatedMemory / 1024)).append("\n");
|
||||||
sb.append("max memory: " + format.format(maxMemory / 1024) + "\n");
|
sb.append("max memory: ").append(format.format(maxMemory / 1024)).append("\n");
|
||||||
sb.append("total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "\n");
|
sb.append("total free memory: ").append(format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024)).append("\n");
|
||||||
|
|
||||||
System.out.println(sb.toString());
|
System.out.println(sb.toString());
|
||||||
}
|
}
|
||||||
|
@ -5,22 +5,22 @@ import java.util.*
|
|||||||
|
|
||||||
class Log {
|
class Log {
|
||||||
companion object Log{
|
companion object Log{
|
||||||
val CRITICAL_ERROR = 6
|
const val CRITICAL_ERROR = 6
|
||||||
val ERROR = 5
|
const val ERROR = 5
|
||||||
val WARNING = 4
|
const val WARNING = 4
|
||||||
val INFO = 3
|
const val INFO = 3
|
||||||
val MESSAGE = 2
|
const val MESSAGE = 2
|
||||||
val DEBUG = 1
|
const val DEBUG = 1
|
||||||
|
|
||||||
private val ANSI_RESET = "\u001B[0m"
|
private const val ANSI_RESET = "\u001B[0m"
|
||||||
private val ANSI_BLACK = "\u001B[30m"
|
private const val ANSI_BLACK = "\u001B[30m"
|
||||||
private val ANSI_RED = "\u001B[31m"
|
private const val ANSI_RED = "\u001B[31m"
|
||||||
private val ANSI_GREEN = "\u001B[32m"
|
private const val ANSI_GREEN = "\u001B[32m"
|
||||||
private val ANSI_YELLOW = "\u001B[33m"
|
private const val ANSI_YELLOW = "\u001B[33m"
|
||||||
private val ANSI_BLUE = "\u001B[34m"
|
private const val ANSI_BLUE = "\u001B[34m"
|
||||||
private val ANSI_PURPLE = "\u001B[35m"
|
private const val ANSI_PURPLE = "\u001B[35m"
|
||||||
private val ANSI_CYAN = "\u001B[36m"
|
private const val ANSI_CYAN = "\u001B[36m"
|
||||||
private val ANSI_WHITE = "\u001B[37m"
|
private const val ANSI_WHITE = "\u001B[37m"
|
||||||
|
|
||||||
private var Loglevel = 0
|
private var Loglevel = 0
|
||||||
|
|
||||||
@ -126,14 +126,14 @@ class Log {
|
|||||||
fun setLevel(level: Int) {
|
fun setLevel(level: Int) {
|
||||||
Loglevel = level
|
Loglevel = level
|
||||||
}
|
}
|
||||||
private val colors = ArrayList(Arrays.asList("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"))
|
|
||||||
|
private val colors = ArrayList(listOf("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"))
|
||||||
|
|
||||||
|
|
||||||
|
private fun calcDate(milliSecs: Long): String? {
|
||||||
private fun calcDate(millisecs: Long): String? {
|
val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
||||||
val date_format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
|
val resultDate = Date(milliSecs)
|
||||||
val resultdate = Date(millisecs)
|
return dateFormat.format(resultDate)
|
||||||
return date_format.format(resultdate)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,25 +0,0 @@
|
|||||||
package com.wasteinformationserver.db;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
abstract class Database {
|
|
||||||
|
|
||||||
protected String user;
|
|
||||||
protected String password;
|
|
||||||
|
|
||||||
protected String host;
|
|
||||||
protected int port;
|
|
||||||
|
|
||||||
protected String dbName;
|
|
||||||
|
|
||||||
public Database(String user, String password, String host, int port, String dbName) {
|
|
||||||
this.user = user;
|
|
||||||
this.password = password;
|
|
||||||
this.host = host;
|
|
||||||
this.port = port;
|
|
||||||
this.dbName = dbName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract Connection getConnection() throws SQLException;
|
|
||||||
}
|
|
@ -3,10 +3,7 @@ package com.wasteinformationserver.db;
|
|||||||
import com.wasteinformationserver.basicutils.Log;
|
import com.wasteinformationserver.basicutils.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.sql.Connection;
|
import java.sql.*;
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* basic connection class to a Database
|
* basic connection class to a Database
|
||||||
@ -25,6 +22,21 @@ public class JDBC {
|
|||||||
private static String ipc;
|
private static String ipc;
|
||||||
private static int portc;
|
private static int portc;
|
||||||
|
|
||||||
|
private JDBC(String username, String password, String dbname, String ip, int port) throws IOException {
|
||||||
|
logintodb(username, password, dbname, ip, port);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* instance of JDBC driver
|
||||||
|
*/
|
||||||
|
static {
|
||||||
|
try {
|
||||||
|
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* initialize database values
|
* initialize database values
|
||||||
* suggested on startup
|
* suggested on startup
|
||||||
@ -45,10 +57,6 @@ public class JDBC {
|
|||||||
JDBC = new JDBC(username, password, dbname, ip, port);
|
JDBC = new JDBC(username, password, dbname, ip, port);
|
||||||
}
|
}
|
||||||
|
|
||||||
private JDBC(String username, String password, String dbname, String ip, int port) throws IOException {
|
|
||||||
logintodb(username, password, dbname, ip, port);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get instance of db object
|
* get instance of db object
|
||||||
* logindata has to be set before!
|
* logindata has to be set before!
|
||||||
@ -67,22 +75,28 @@ public class JDBC {
|
|||||||
return JDBC;
|
return JDBC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initial login to db -- should be called only one time or for reconnect
|
||||||
|
*
|
||||||
|
* @param username username
|
||||||
|
* @param password password
|
||||||
|
* @param dbname Database name
|
||||||
|
* @param ip Host or ip address
|
||||||
|
* @param port Server port
|
||||||
|
* @throws IOException thrown if no connection to db is possible.
|
||||||
|
*/
|
||||||
private static void logintodb(String username, String password, String dbname, String ip, int port) throws IOException {
|
private static void logintodb(String username, String password, String dbname, String ip, int port) throws IOException {
|
||||||
Database db = new MySQLConnector(
|
|
||||||
username,
|
|
||||||
password,
|
|
||||||
ip,
|
|
||||||
port,
|
|
||||||
dbname);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = db.getConnection();
|
DriverManager.setLoginTimeout(1);
|
||||||
|
conn = DriverManager.getConnection(
|
||||||
|
"jdbc:mysql://" + ip + ":" + port + "/" + dbname + "?useSSL=false&serverTimezone=CET",
|
||||||
|
username,
|
||||||
|
password);
|
||||||
loggedin = true;
|
loggedin = true;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new IOException("No connection to database");
|
throw new IOException("No connection to database");
|
||||||
// todo reconnect every 5mins or something
|
// todo reconnect every 5mins or something
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,6 +128,11 @@ public class JDBC {
|
|||||||
return stmt.executeUpdate();
|
return stmt.executeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* check if connection is still established
|
||||||
|
*
|
||||||
|
* @return connection state
|
||||||
|
*/
|
||||||
public boolean isConnected() {
|
public boolean isConnected() {
|
||||||
return loggedin;
|
return loggedin;
|
||||||
}
|
}
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
package com.wasteinformationserver.db;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.DriverManager;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
class MySQLConnector extends Database {
|
|
||||||
|
|
||||||
static {
|
|
||||||
try {
|
|
||||||
Class.forName("com.mysql.cj.jdbc.Driver").getDeclaredConstructor().newInstance();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MySQLConnector(String user, String password, String host, int port, String dbName) {
|
|
||||||
super(user, password, host, port, dbName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection getConnection() throws SQLException {
|
|
||||||
DriverManager.setLoginTimeout(1);
|
|
||||||
return DriverManager.getConnection(
|
|
||||||
"jdbc:mysql://" + host + ":" + port + "/" + dbName + "?useSSL=false&serverTimezone=CET",
|
|
||||||
user,
|
|
||||||
password);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -4,9 +4,9 @@ import com.wasteinformationserver.basicutils.Log.Log.debug
|
|||||||
import com.wasteinformationserver.basicutils.Log.Log.error
|
import com.wasteinformationserver.basicutils.Log.Log.error
|
||||||
import com.wasteinformationserver.basicutils.Log.Log.info
|
import com.wasteinformationserver.basicutils.Log.Log.info
|
||||||
import com.wasteinformationserver.basicutils.Log.Log.message
|
import com.wasteinformationserver.basicutils.Log.Log.message
|
||||||
|
import com.wasteinformationserver.basicutils.Log.Log.warning
|
||||||
import com.wasteinformationserver.db.JDBC
|
import com.wasteinformationserver.db.JDBC
|
||||||
import org.eclipse.paho.client.mqttv3.*
|
import org.eclipse.paho.client.mqttv3.*
|
||||||
import java.io.IOException
|
|
||||||
import java.sql.SQLException
|
import java.sql.SQLException
|
||||||
import java.text.ParseException
|
import java.text.ParseException
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
@ -25,11 +25,7 @@ class MqttService(serverurl: String, port: String) {
|
|||||||
private var db: JDBC = JDBC.getInstance()
|
private var db: JDBC = JDBC.getInstance()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* init mqtt service
|
* initial login to db
|
||||||
* JDBC has to be inited before
|
|
||||||
*
|
|
||||||
* @param serverurl mqtt server ip or hostname
|
|
||||||
* @param port mqtt server port
|
|
||||||
*/
|
*/
|
||||||
init {
|
init {
|
||||||
connectToDb()
|
connectToDb()
|
||||||
@ -91,12 +87,19 @@ class MqttService(serverurl: String, port: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if device is configured and zone infos are stored in db
|
||||||
|
*
|
||||||
|
* @param citywastezoneid zone/city id
|
||||||
|
* @param deviceid device id
|
||||||
|
*/
|
||||||
private fun checkDatabase(citywastezoneid: Int, deviceid: Int) {
|
private fun checkDatabase(citywastezoneid: Int, deviceid: Int) {
|
||||||
var wastetype = -1
|
var wastetype = -1
|
||||||
val set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='$citywastezoneid'")
|
val set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='$citywastezoneid'")
|
||||||
try {
|
try {
|
||||||
set2.last()
|
set2.last()
|
||||||
if (set2.row != 1) { //error
|
if (set2.row != 1) { //error
|
||||||
|
warning("multiple Rows with same city id found - DB Error")
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
val typ = set2.getString("wastetype")
|
val typ = set2.getString("wastetype")
|
||||||
@ -136,8 +139,11 @@ class MqttService(serverurl: String, port: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* send a mqtt message to predefined topic
|
||||||
|
*/
|
||||||
private fun tramsmitMessage(temp: String) {
|
private fun tramsmitMessage(temp: String) {
|
||||||
debug("sending message >>>$temp")
|
message("reply back to PCB: $temp")
|
||||||
val message = MqttMessage(temp.toByteArray())
|
val message = MqttMessage(temp.toByteArray())
|
||||||
message.qos = 2
|
message.qos = 2
|
||||||
try {
|
try {
|
||||||
@ -147,16 +153,9 @@ class MqttService(serverurl: String, port: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getTyp(number: Int): String? {
|
/**
|
||||||
return when (number) {
|
* parse Type name to representing integer value
|
||||||
1 -> "Plastic"
|
*/
|
||||||
2 -> "Metal"
|
|
||||||
3 -> "Residual waste"
|
|
||||||
4 -> "Biowaste"
|
|
||||||
else -> null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getIntTyp(temp: String): Int {
|
private fun getIntTyp(temp: String): Int {
|
||||||
return when (temp) {
|
return when (temp) {
|
||||||
"Plastic" -> 1
|
"Plastic" -> 1
|
||||||
@ -167,6 +166,9 @@ class MqttService(serverurl: String, port: String) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* receives connection object and initial connection to db
|
||||||
|
*/
|
||||||
private fun connectToDb() {
|
private fun connectToDb() {
|
||||||
db = JDBC.getInstance()
|
db = JDBC.getInstance()
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ class HttpTools {
|
|||||||
* @param value input string
|
* @param value input string
|
||||||
* @return md5 hash
|
* @return md5 hash
|
||||||
*/
|
*/
|
||||||
fun StringToMD5(value: String): String {
|
fun stringToMD5(value: String): String {
|
||||||
return try {
|
return try {
|
||||||
val md = MessageDigest.getInstance("MD5")
|
val md = MessageDigest.getInstance("MD5")
|
||||||
val messageDigest = md.digest(value.toByteArray())
|
val messageDigest = md.digest(value.toByteArray())
|
||||||
|
@ -42,7 +42,7 @@ public class AdminRequests extends PostRequest {
|
|||||||
Log.Log.warning("not jar --> cant restart");
|
Log.Log.warning("not jar --> cant restart");
|
||||||
|
|
||||||
/* Build command: java -jar application.jar */
|
/* Build command: java -jar application.jar */
|
||||||
final ArrayList<String> command = new ArrayList<String>();
|
final ArrayList<String> command = new ArrayList<>();
|
||||||
command.add(javaBin);
|
command.add(javaBin);
|
||||||
command.add("-jar");
|
command.add("-jar");
|
||||||
command.add(currentJar.getPath());
|
command.add(currentJar.getPath());
|
||||||
|
@ -74,7 +74,7 @@ class DeviceRequest : PostRequest() {
|
|||||||
var prev = ""
|
var prev = ""
|
||||||
while (deviceset.next()) {
|
while (deviceset.next()) {
|
||||||
if (prev != deviceset.getString("name")) {
|
if (prev != deviceset.getString("name")) {
|
||||||
if (!deviceset.isFirst()) {
|
if (!deviceset.isFirst) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
}
|
}
|
||||||
sb.append("\"").append(deviceset.getString("name")).append("\":\"").append(deviceset.getString("name")).append("\"")
|
sb.append("\"").append(deviceset.getString("name")).append("\":\"").append(deviceset.getString("name")).append("\"")
|
||||||
@ -99,7 +99,7 @@ class DeviceRequest : PostRequest() {
|
|||||||
while (deviceset.next()) {
|
while (deviceset.next()) {
|
||||||
if (prev != deviceset.getInt("zone")) {
|
if (prev != deviceset.getInt("zone")) {
|
||||||
sb.append("\"").append(deviceset.getInt("zone")).append("\":\"").append(deviceset.getInt("zone")).append("\"")
|
sb.append("\"").append(deviceset.getInt("zone")).append("\":\"").append(deviceset.getInt("zone")).append("\"")
|
||||||
if (!deviceset.isLast()) {
|
if (!deviceset.isLast) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ class DeviceRequest : PostRequest() {
|
|||||||
while (deviceset.next()) {
|
while (deviceset.next()) {
|
||||||
if (prev != deviceset.getString("wastetype")) {
|
if (prev != deviceset.getString("wastetype")) {
|
||||||
sb.append("\"" + deviceset.getString("wastetype") + "\":\"" + deviceset.getString("wastetype") + "\"")
|
sb.append("\"" + deviceset.getString("wastetype") + "\":\"" + deviceset.getString("wastetype") + "\"")
|
||||||
if (!deviceset.isLast()) {
|
if (!deviceset.isLast) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,7 +171,7 @@ class DeviceRequest : PostRequest() {
|
|||||||
try {
|
try {
|
||||||
val device = jdbc.executeQuery("SELECT * FROM cities WHERE name='" + params["cityname"] + "' AND wastetype='" + params["wastetype"] + "' AND zone='" + params["zonename"] + "'")
|
val device = jdbc.executeQuery("SELECT * FROM cities WHERE name='" + params["cityname"] + "' AND wastetype='" + params["wastetype"] + "' AND zone='" + params["zonename"] + "'")
|
||||||
device.first()
|
device.first()
|
||||||
var cityid = device.getInt("id")
|
val cityid = device.getInt("id")
|
||||||
jdbc.executeUpdate("INSERT INTO `device_city` (`DeviceID`, `CityID`) VALUES ('" + params["deviceid"] + "', '" + cityid + "');")
|
jdbc.executeUpdate("INSERT INTO `device_city` (`DeviceID`, `CityID`) VALUES ('" + params["deviceid"] + "', '" + cityid + "');")
|
||||||
} catch (e: SQLException) {
|
} catch (e: SQLException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
|
@ -30,9 +30,7 @@ class NewDateRequest : PostRequest() {
|
|||||||
try {
|
try {
|
||||||
var prev = ""
|
var prev = ""
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
if (prev == set.getString("name")) {
|
if (prev != set.getString("name")) { // not same --> new element
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (!set.isFirst) {
|
if (!set.isFirst) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
}
|
}
|
||||||
@ -55,9 +53,7 @@ class NewDateRequest : PostRequest() {
|
|||||||
try {
|
try {
|
||||||
var prev = 42
|
var prev = 42
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
if (prev == set.getInt("zone")) {
|
if (prev != set.getInt("zone")) { // not same --> append next
|
||||||
}
|
|
||||||
else {
|
|
||||||
sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}")
|
sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}")
|
||||||
if (!set.isLast) {
|
if (!set.isLast) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
@ -79,9 +75,7 @@ class NewDateRequest : PostRequest() {
|
|||||||
try {
|
try {
|
||||||
var prev = "42"
|
var prev = "42"
|
||||||
while (set.next()) {
|
while (set.next()) {
|
||||||
if (prev === set.getString("wastetype")) {
|
if (prev !== set.getString("wastetype")) {
|
||||||
}
|
|
||||||
else {
|
|
||||||
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}")
|
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}")
|
||||||
if (!set.isLast) {
|
if (!set.isLast) {
|
||||||
sb.append(",")
|
sb.append(",")
|
||||||
|
@ -3,7 +3,7 @@ package com.wasteinformationserver.website.datarequests
|
|||||||
import com.wasteinformationserver.basicutils.Log
|
import com.wasteinformationserver.basicutils.Log
|
||||||
import com.wasteinformationserver.basicutils.Log.Log.debug
|
import com.wasteinformationserver.basicutils.Log.Log.debug
|
||||||
import com.wasteinformationserver.db.JDBC
|
import com.wasteinformationserver.db.JDBC
|
||||||
import com.wasteinformationserver.website.HttpTools.Companion.StringToMD5
|
import com.wasteinformationserver.website.HttpTools.Companion.stringToMD5
|
||||||
import com.wasteinformationserver.website.basicrequest.PostRequest
|
import com.wasteinformationserver.website.basicrequest.PostRequest
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.sql.SQLException
|
import java.sql.SQLException
|
||||||
@ -12,15 +12,16 @@ import java.util.*
|
|||||||
class RegisterRequest : PostRequest() {
|
class RegisterRequest : PostRequest() {
|
||||||
override fun request(params: HashMap<String, String>): String {
|
override fun request(params: HashMap<String, String>): String {
|
||||||
debug(params.toString())
|
debug(params.toString())
|
||||||
val passhash = StringToMD5(params["password"]!!)
|
val passhash = stringToMD5(params["password"]!!)
|
||||||
var reply: StringBuilder = StringBuilder("{")
|
val reply: StringBuilder = StringBuilder("{")
|
||||||
try {
|
try {
|
||||||
var myjd: JDBC = JDBC.getInstance()
|
val myjd: JDBC = JDBC.getInstance()
|
||||||
|
|
||||||
val status = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params["username"] + "', '" + params["firstname"] + "', '" + params["lastname"] + "', '" + passhash + "', '" + params["email"] + "', current_timestamp());")
|
val status = myjd.executeUpdate("INSERT INTO `user` (`username`, `firstName`, `secondName`, `password`, `email`, `logindate`) VALUES ('" + params["username"] + "', '" + params["firstname"] + "', '" + params["lastname"] + "', '" + passhash + "', '" + params["email"] + "', current_timestamp());")
|
||||||
if (status == 1) {
|
if (status == 1) {
|
||||||
reply.append("\"accept\": true")
|
reply.append("\"accept\": true")
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
reply.append("\"accept\": false")
|
reply.append("\"accept\": false")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,14 +6,14 @@ import java.util.*
|
|||||||
class UserInfoRequest : PostRequest() {
|
class UserInfoRequest : PostRequest() {
|
||||||
override fun request(params: HashMap<String, String>): String {
|
override fun request(params: HashMap<String, String>): String {
|
||||||
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
//TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
||||||
when (params.get("action")) {
|
when (params["action"]) {
|
||||||
"getlogins" -> {
|
"getlogins" -> {
|
||||||
println("heyho")
|
println("heyho")
|
||||||
}
|
}
|
||||||
""->{
|
"" -> {
|
||||||
//todo o
|
//todo o
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "{}";
|
return "{}"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,7 +4,7 @@ import com.wasteinformationserver.basicutils.Log.Log.debug
|
|||||||
import com.wasteinformationserver.basicutils.Log.Log.error
|
import com.wasteinformationserver.basicutils.Log.Log.error
|
||||||
import com.wasteinformationserver.basicutils.Log.Log.message
|
import com.wasteinformationserver.basicutils.Log.Log.message
|
||||||
import com.wasteinformationserver.db.JDBC
|
import com.wasteinformationserver.db.JDBC
|
||||||
import com.wasteinformationserver.website.HttpTools.Companion.StringToMD5
|
import com.wasteinformationserver.website.HttpTools.Companion.stringToMD5
|
||||||
import com.wasteinformationserver.website.basicrequest.PostRequest
|
import com.wasteinformationserver.website.basicrequest.PostRequest
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.sql.SQLException
|
import java.sql.SQLException
|
||||||
@ -33,12 +33,13 @@ class LoginRequest : PostRequest() {
|
|||||||
try {
|
try {
|
||||||
s.last()
|
s.last()
|
||||||
if (s.row == 1) { //success
|
if (s.row == 1) { //success
|
||||||
if (StringToMD5(password!!) == s.getString("password")) {
|
if (stringToMD5(password!!) == s.getString("password")) {
|
||||||
debug("login success")
|
debug("login success")
|
||||||
LoginState.getObject().logIn()
|
LoginState.getObject().logIn()
|
||||||
LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission"))
|
LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission"))
|
||||||
response = "{\"accept\": true}"
|
response = "{\"accept\": true}"
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
debug("wrong password")
|
debug("wrong password")
|
||||||
}
|
}
|
||||||
} else if (s.row == 0) { //user not found
|
} else if (s.row == 0) { //user not found
|
||||||
|
@ -5,7 +5,7 @@ package com.wasteinformationserver.website.datarequests.login;
|
|||||||
*/
|
*/
|
||||||
public class LoginState {
|
public class LoginState {
|
||||||
|
|
||||||
private static LoginState mythis = new LoginState();
|
private static final LoginState mythis = new LoginState();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get object
|
* get object
|
||||||
|
Loading…
Reference in New Issue
Block a user