Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
c71b50a041 | |||
af9d5662b1 | |||
a71c1a09a6 | |||
05cc2f83d6 | |||
f94fd7d037 | |||
|
59cb7c3c4f | ||
|
2ac3cf629f | ||
|
506c6f9b09 | ||
|
ba5048e119 | ||
|
26279130b7 | ||
|
30b51f9032 | ||
|
51f6ca8958 | ||
|
f8fd7d1b5e | ||
|
23df933504 | ||
|
3a51b08de8 | ||
|
f4fbce7977 | ||
|
605a2ca33d | ||
|
a633ba42e9 | ||
|
f0e654399a | ||
|
a98c3eae71 | ||
|
3fba0f9933 |
28
.github/workflows/build.yml
vendored
Normal file
28
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
# .github/workflows/gradle-build-pr.yml
|
||||
name: Run Gradle on pushs
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
pull_request:
|
||||
branches:
|
||||
- '*'
|
||||
jobs:
|
||||
gradle:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest, windows-latest]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 11
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
gradle-version: rc
|
||||
arguments: build
|
||||
- uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
gradle-version: rc
|
||||
arguments: jar
|
35
.gitlab-ci.yml
Normal file
35
.gitlab-ci.yml
Normal file
@ -0,0 +1,35 @@
|
||||
# This file is a template, and might need editing before it works on your project.
|
||||
# This is the Gradle build system for JVM applications
|
||||
# https://gradle.org/
|
||||
# https://github.com/gradle/gradle
|
||||
image: gradle:latest
|
||||
|
||||
# Disable the Gradle daemon for Continuous Integration servers as correctness
|
||||
# is usually a priority over speed in CI environments. Using a fresh
|
||||
# runtime for each build is more reliable since the runtime is completely
|
||||
# isolated from any previous builds.
|
||||
variables:
|
||||
GRADLE_OPTS: "-Dorg.gradle.daemon=false"
|
||||
|
||||
before_script:
|
||||
- export GRADLE_USER_HOME=`pwd`/.gradle
|
||||
|
||||
build:
|
||||
stage: build
|
||||
script: gradle --build-cache assemble
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_NAME"
|
||||
policy: push
|
||||
paths:
|
||||
- build
|
||||
- .gradle
|
||||
|
||||
test:
|
||||
stage: test
|
||||
script: gradle check
|
||||
cache:
|
||||
key: "$CI_COMMIT_REF_NAME"
|
||||
policy: pull
|
||||
paths:
|
||||
- build
|
||||
- .gradle
|
@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'com.wasteinformationserver'
|
||||
version '1.0.1'
|
||||
version '1.1.1'
|
||||
|
||||
sourceCompatibility = 1.8
|
||||
|
||||
|
156
db.sql
156
db.sql
@ -1,156 +0,0 @@
|
||||
-- phpMyAdmin SQL Dump
|
||||
-- version 4.9.0.1
|
||||
-- https://www.phpmyadmin.net/
|
||||
--
|
||||
-- Host: localhost
|
||||
-- Erstellungszeit: 06. Dez 2019 um 16:11
|
||||
-- Server-Version: 10.3.11-MariaDB
|
||||
-- PHP-Version: 5.6.40
|
||||
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET AUTOCOMMIT = 0;
|
||||
START TRANSACTION;
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
--
|
||||
-- Datenbank: `wasteinformation`
|
||||
--
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabellenstruktur für Tabelle `cities`
|
||||
--
|
||||
|
||||
CREATE TABLE `cities` (
|
||||
`id` int(11) NOT NULL,
|
||||
`userid` int(11) NOT NULL,
|
||||
`name` varchar(256) NOT NULL,
|
||||
`wastetype` varchar(64) NOT NULL,
|
||||
`zone` int(11) NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Daten für Tabelle `cities`
|
||||
--
|
||||
|
||||
INSERT INTO `cities` (`id`, `userid`, `name`, `wastetype`, `zone`) VALUES
|
||||
(2, 0, 'Steyr', 'Bio', 2),
|
||||
(3, 0, 'Steyr', 'Bio', 3),
|
||||
(4, 0, 'Steyr', 'Bio', 4),
|
||||
(128, 0, 'Steyr', 'Biowaste', 1),
|
||||
(130, 0, 'abc', 'Biowaste', 1);
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabellenstruktur für Tabelle `pickupdates`
|
||||
--
|
||||
|
||||
CREATE TABLE `pickupdates` (
|
||||
`id` int(11) NOT NULL,
|
||||
`citywastezoneid` int(11) NOT NULL,
|
||||
`pickupdate` date NOT NULL
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Daten für Tabelle `pickupdates`
|
||||
--
|
||||
|
||||
INSERT INTO `pickupdates` (`id`, `citywastezoneid`, `pickupdate`) VALUES
|
||||
(6, 4, '2019-12-06'),
|
||||
(7, 3, '2019-12-06'),
|
||||
(8, 2, '2019-12-06'),
|
||||
(9, 130, '2019-12-26');
|
||||
|
||||
-- --------------------------------------------------------
|
||||
|
||||
--
|
||||
-- Tabellenstruktur für Tabelle `user`
|
||||
--
|
||||
|
||||
CREATE TABLE `user` (
|
||||
`id` int(11) NOT NULL,
|
||||
`username` varchar(150) NOT NULL,
|
||||
`firstName` varchar(32) NOT NULL,
|
||||
`secondName` varchar(32) NOT NULL,
|
||||
`password` varchar(32) NOT NULL,
|
||||
`permission` int(11) NOT NULL DEFAULT 0,
|
||||
`email` varchar(64) NOT NULL,
|
||||
`logindate` timestamp NOT NULL DEFAULT current_timestamp()
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
|
||||
--
|
||||
-- Daten für Tabelle `user`
|
||||
--
|
||||
|
||||
INSERT INTO `user` (`id`, `username`, `firstName`, `secondName`, `password`, `permission`, `email`, `logindate`) VALUES
|
||||
(2, 'lheilige', 'lukas', 'heiligenbrunner', 'c6e2ddf577e0dfdc4366f788f1b27102', 0, 'lukas.heiligenbrunner@gmail.com', '2019-09-20 12:19:31'),
|
||||
(11, 'meindl', 'emil', 'meindl', '81dc9bdb52d04dc20036dbd8313ed055', 0, 'mailmeindl', '2019-09-27 10:23:46'),
|
||||
(15, 'horni', 'kk', 'kk', 'c4ca4238a0b923820dcc509a6f75849b', 1, 'kk', '2019-09-27 13:19:09');
|
||||
|
||||
--
|
||||
-- Indizes der exportierten Tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- Indizes für die Tabelle `cities`
|
||||
--
|
||||
ALTER TABLE `cities`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- Indizes für die Tabelle `pickupdates`
|
||||
--
|
||||
ALTER TABLE `pickupdates`
|
||||
ADD PRIMARY KEY (`id`),
|
||||
ADD KEY `citywastezoneid` (`citywastezoneid`);
|
||||
|
||||
--
|
||||
-- Indizes für die Tabelle `user`
|
||||
--
|
||||
ALTER TABLE `user`
|
||||
ADD PRIMARY KEY (`id`);
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für exportierte Tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für Tabelle `cities`
|
||||
--
|
||||
ALTER TABLE `cities`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=131;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für Tabelle `pickupdates`
|
||||
--
|
||||
ALTER TABLE `pickupdates`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
|
||||
|
||||
--
|
||||
-- AUTO_INCREMENT für Tabelle `user`
|
||||
--
|
||||
ALTER TABLE `user`
|
||||
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=16;
|
||||
|
||||
--
|
||||
-- Constraints der exportierten Tabellen
|
||||
--
|
||||
|
||||
--
|
||||
-- Constraints der Tabelle `pickupdates`
|
||||
--
|
||||
ALTER TABLE `pickupdates`
|
||||
ADD CONSTRAINT `pickupdates_ibfk_1` FOREIGN KEY (`citywastezoneid`) REFERENCES `cities` (`id`);
|
||||
COMMIT;
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
@ -1,4 +1,5 @@
|
||||
@file:JvmName("Main")
|
||||
|
||||
package com.wasteinformationserver
|
||||
|
||||
import com.wasteinformationserver.basicutils.Info
|
||||
@ -7,7 +8,6 @@ import com.wasteinformationserver.basicutils.Storage
|
||||
import com.wasteinformationserver.db.JDBC
|
||||
import com.wasteinformationserver.mqtt.MqttService
|
||||
import com.wasteinformationserver.website.Webserver
|
||||
import java.io.IOException
|
||||
|
||||
/**
|
||||
* application entry point
|
||||
@ -22,14 +22,9 @@ fun main() {
|
||||
Log.info("startup of WasteInformationServer")
|
||||
|
||||
Runtime.getRuntime().addShutdownHook(Thread(Runnable {
|
||||
try {
|
||||
Thread.sleep(200)
|
||||
Log.warning("Shutting down ...")
|
||||
JDBC.getInstance().disconnect();
|
||||
//shutdown routine
|
||||
} catch (e: InterruptedException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
// shutdown routine
|
||||
Log.warning("Shutting down ...")
|
||||
JDBC.getInstance().disconnect();
|
||||
}))
|
||||
|
||||
Log.info("Server version: " + Info.getVersion())
|
||||
@ -37,14 +32,8 @@ fun main() {
|
||||
|
||||
//initial connect to db
|
||||
Log.message("initial login to db")
|
||||
try {
|
||||
val stor = Storage.getInstance();
|
||||
JDBC.init(stor.dbUser, stor.dbPassword, stor.dbName, stor.dbhost, stor.dbPort)
|
||||
//JDBC.init("ingproject", "Kb9Dxklumt76ieq6", "ingproject", "db.power4future.at", 3306)
|
||||
//JDBC.init("users", "kOpaIJUjkgb9ur6S", "wasteinformation", "192.168.65.15", 3306);
|
||||
} catch (e: IOException) {
|
||||
Log.error("no connection to db")
|
||||
}
|
||||
val stor = Storage.getInstance();
|
||||
JDBC.init(stor.dbUser, stor.dbPassword, stor.dbName, stor.dbhost, stor.dbPort)
|
||||
|
||||
|
||||
//startup web server
|
||||
@ -55,11 +44,7 @@ fun main() {
|
||||
//startup mqtt service
|
||||
Log.message("starting mqtt service")
|
||||
|
||||
if (JDBC.isConnected()) {
|
||||
val m = MqttService(Storage.getInstance().mqttServer, Storage.getInstance().mqttPort.toString())
|
||||
// val m = MqttService("mqtt.heili.eu", "1883")
|
||||
m.startupService()
|
||||
}else{
|
||||
Log.error("could't start mqtt service because of missing db connection!")
|
||||
}
|
||||
val m = MqttService.getInstance()
|
||||
m.init(Storage.getInstance().mqttServer, Storage.getInstance().mqttPort.toString())
|
||||
m.startupService()
|
||||
}
|
@ -1,14 +1,18 @@
|
||||
package com.wasteinformationserver.db;
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log;
|
||||
import com.wasteinformationserver.basicutils.Storage;
|
||||
import com.wasteinformationserver.mqtt.MqttService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.*;
|
||||
import java.util.Scanner;
|
||||
|
||||
/**
|
||||
* basic connection class to a Database
|
||||
*
|
||||
* @author Lukas Heiligenbrunner
|
||||
* @author Emil Meindl
|
||||
*/
|
||||
public class JDBC {
|
||||
private static Connection conn;
|
||||
@ -22,7 +26,7 @@ public class JDBC {
|
||||
private static String ipc;
|
||||
private static int portc;
|
||||
|
||||
private JDBC(String username, String password, String dbname, String ip, int port) throws IOException {
|
||||
private JDBC(String username, String password, String dbname, String ip, int port) {
|
||||
logintodb(username, password, dbname, ip, port);
|
||||
}
|
||||
|
||||
@ -66,11 +70,7 @@ public class JDBC {
|
||||
*/
|
||||
public static JDBC getInstance() {
|
||||
if (!loggedin) {
|
||||
try {
|
||||
logintodb(usernamec, passwordc, dbnamec, ipc, portc);
|
||||
} catch (IOException e) {
|
||||
Log.Log.error("no connetion to db - retrying in 5min");
|
||||
}
|
||||
JDBC = new JDBC(usernamec, passwordc, dbnamec, ipc, portc);
|
||||
}
|
||||
return JDBC;
|
||||
}
|
||||
@ -85,21 +85,50 @@ public class JDBC {
|
||||
* @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 boolean logintodb(String username, String password, String dbname, String ip, int port) {
|
||||
try {
|
||||
DriverManager.setLoginTimeout(1);
|
||||
conn = DriverManager.getConnection(
|
||||
"jdbc:mysql://" + ip + ":" + port + "/" + dbname + "?useSSL=false&serverTimezone=CET",
|
||||
username,
|
||||
password);
|
||||
checkDBStructure();
|
||||
loggedin = true;
|
||||
Log.Log.message("Connected to database");
|
||||
} catch (SQLException e) {
|
||||
throw new IOException("No connection to database");
|
||||
// todo reconnect every 5mins or something
|
||||
// reconnect every 10 sec
|
||||
Log.Log.warning("Database-Connection not possible");
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(10 * 1000);
|
||||
} catch (InterruptedException interruptedException) {
|
||||
interruptedException.printStackTrace();
|
||||
}
|
||||
Log.Log.debug("Reading config");
|
||||
Storage st = Storage.Companion.getInstance();
|
||||
st.init();
|
||||
usernamec = st.getDbName();
|
||||
passwordc = st.getDbPassword();
|
||||
dbnamec = st.getDbName();
|
||||
ipc = st.getDbhost();
|
||||
portc = st.getDbPort();
|
||||
Log.Log.info("Retry connection");
|
||||
loggedin = logintodb(usernamec, passwordc, dbnamec, ipc, portc);
|
||||
if (loggedin) {
|
||||
// startup mqtt service if successfully connected
|
||||
MqttService srvc = MqttService.Companion.getInstance();
|
||||
srvc.init(st.getMqttServer(), String.valueOf(st.getMqttPort()));
|
||||
srvc.startupService();
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
return loggedin;
|
||||
}
|
||||
|
||||
public void disconnect(){
|
||||
public void disconnect() {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException throwables) {
|
||||
@ -115,12 +144,19 @@ public class JDBC {
|
||||
*/
|
||||
public ResultSet executeQuery(String sql) {
|
||||
try {
|
||||
conn.isValid(5);
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
return stmt.executeQuery();
|
||||
} catch (SQLNonTransientConnectionException ee) {
|
||||
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
|
||||
return this.executeQuery(sql);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,9 +167,17 @@ public class JDBC {
|
||||
* @throws SQLException
|
||||
*/
|
||||
public int executeUpdate(String sql) throws SQLException {
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
|
||||
return stmt.executeUpdate();
|
||||
try {
|
||||
conn.isValid(2);
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
return stmt.executeUpdate();
|
||||
} catch (SQLNonTransientConnectionException ee) {
|
||||
if (logintodb(usernamec, passwordc, dbnamec, ipc, portc)) {
|
||||
return this.executeUpdate(sql);
|
||||
} else {
|
||||
throw new SQLNonTransientConnectionException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,4 +188,42 @@ public class JDBC {
|
||||
public static boolean isConnected() {
|
||||
return loggedin;
|
||||
}
|
||||
|
||||
/**
|
||||
* validate the correctness of the current sql db structure
|
||||
*/
|
||||
public void checkDBStructure() {
|
||||
try {
|
||||
ResultSet seti = executeQuery("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = '" + dbnamec + "'");
|
||||
seti.last();
|
||||
Log.Log.debug("found " + seti.getInt(1) + " tables in db");
|
||||
if (seti.getInt(1) != 5) {
|
||||
// structure not valid
|
||||
Log.Log.info("recreating Database structure!");
|
||||
Scanner s = new Scanner(getClass().getResourceAsStream("/db.sql"));
|
||||
s.useDelimiter("(;(\r)?\n)|(--\n)");
|
||||
Statement st = null;
|
||||
try {
|
||||
st = conn.createStatement();
|
||||
while (s.hasNext()) {
|
||||
String line = s.next();
|
||||
if (line.startsWith("/*!") && line.endsWith("*/")) {
|
||||
int i = line.indexOf(' ');
|
||||
line = line.substring(i + 1, line.length() - " */".length());
|
||||
}
|
||||
|
||||
if (line.trim().length() > 0) {
|
||||
executeUpdate(line);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (st != null) st.close();
|
||||
}
|
||||
} else {
|
||||
Log.Log.message("found valid database structure!");
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
Log.Log.error("a unhandled SQLexception occured at db structure creation.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.wasteinformationserver.mqtt
|
||||
|
||||
import com.wasteinformationserver.basicutils.Log
|
||||
import com.wasteinformationserver.basicutils.Log.Log.debug
|
||||
import com.wasteinformationserver.basicutils.Log.Log.error
|
||||
import com.wasteinformationserver.basicutils.Log.Log.info
|
||||
@ -19,71 +20,84 @@ import java.util.*
|
||||
* @author Lukas Heiligenbrunner
|
||||
* @author Gregor Dutzler
|
||||
*/
|
||||
class MqttService(serverurl: String, port: String) {
|
||||
private val serveruri: String = "tcp://$serverurl:$port"
|
||||
private var client: MqttClient = MqttClient(serveruri, "JavaSample42")
|
||||
class MqttService {
|
||||
private var serveruri: String = "";
|
||||
private lateinit var client: MqttClient;
|
||||
private var db: JDBC = JDBC.getInstance()
|
||||
|
||||
/**
|
||||
* initial login to db
|
||||
*/
|
||||
init {
|
||||
connectToDb()
|
||||
companion object {
|
||||
private val obj = MqttService()
|
||||
fun getInstance(): MqttService {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
fun init(serverurl: String, port: String){
|
||||
serveruri = "tcp://$serverurl:$port"
|
||||
}
|
||||
|
||||
/**
|
||||
* startup of the mqtt service
|
||||
*/
|
||||
fun startupService() {
|
||||
try {
|
||||
client = MqttClient(serveruri, "JavaSample42")
|
||||
val connOpts = MqttConnectOptions()
|
||||
connOpts.isCleanSession = true
|
||||
client.connect(connOpts)
|
||||
client.setCallback(object : MqttCallback {
|
||||
override fun connectionLost(throwable: Throwable) {
|
||||
error("connection lost")
|
||||
connectToDb()
|
||||
}
|
||||
if(JDBC.isConnected()) {
|
||||
try {
|
||||
client = MqttClient(serveruri, "WasteInformationServerID")
|
||||
val connOpts = MqttConnectOptions()
|
||||
connOpts.isCleanSession = true
|
||||
client.connect(connOpts)
|
||||
client.setCallback(object : MqttCallback {
|
||||
override fun connectionLost(throwable: Throwable) {
|
||||
error("connection lost")
|
||||
Thread.sleep(500)
|
||||
// restart service
|
||||
startupService()
|
||||
}
|
||||
|
||||
override fun messageArrived(s: String, mqttMessage: MqttMessage) {
|
||||
val deviceid = String(mqttMessage.payload)
|
||||
message("received Request from PCB")
|
||||
val res = db.executeQuery("SELECT * from devices WHERE DeviceID=$deviceid")
|
||||
try {
|
||||
res.last()
|
||||
if (res.row != 0) { //existing device
|
||||
res.first()
|
||||
val devicecities = db.executeQuery("SELECT * from device_city WHERE DeviceID='$deviceid'")
|
||||
devicecities.last()
|
||||
if (devicecities.row == 0) { //not configured
|
||||
tramsmitMessage("$deviceid,-1")
|
||||
}
|
||||
else {
|
||||
devicecities.first()
|
||||
devicecities.previous()
|
||||
override fun messageArrived(s: String, mqttMessage: MqttMessage) {
|
||||
val deviceid = String(mqttMessage.payload)
|
||||
message("received Request from PCB")
|
||||
val res = db.executeQuery("SELECT * from devices WHERE DeviceID=$deviceid")
|
||||
try {
|
||||
res.last()
|
||||
if (res.row != 0) {
|
||||
// existing device
|
||||
res.first()
|
||||
val devicecities = db.executeQuery("SELECT * from device_city WHERE DeviceID='$deviceid'")
|
||||
devicecities.last()
|
||||
if (devicecities.row == 0) {
|
||||
// not configured
|
||||
tramsmitMessage("$deviceid,-1")
|
||||
}
|
||||
else {
|
||||
devicecities.first()
|
||||
devicecities.previous()
|
||||
|
||||
while (devicecities.next()) {
|
||||
val cityid = devicecities.getInt("CityID")
|
||||
checkDatabase(cityid, deviceid.toInt())
|
||||
while (devicecities.next()) {
|
||||
val cityid = devicecities.getInt("CityID")
|
||||
checkDatabase(cityid, deviceid.toInt())
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// new device
|
||||
db.executeUpdate("INSERT INTO devices (DeviceID) VALUES ($deviceid)")
|
||||
info("new device registered to server")
|
||||
tramsmitMessage("$deviceid,-1")
|
||||
}
|
||||
} catch (e: SQLException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
else { //new device
|
||||
db.executeUpdate("INSERT INTO devices (DeviceID) VALUES ($deviceid)")
|
||||
info("new device registered to server")
|
||||
tramsmitMessage("$deviceid,-1")
|
||||
}
|
||||
} catch (e: SQLException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
override fun deliveryComplete(iMqttDeliveryToken: IMqttDeliveryToken) {}
|
||||
})
|
||||
client.subscribe("TopicIn")
|
||||
} catch (e: MqttException) {
|
||||
error("Connection to the Broker failed")
|
||||
override fun deliveryComplete(iMqttDeliveryToken: IMqttDeliveryToken) {}
|
||||
})
|
||||
client.subscribe("TopicIn")
|
||||
} catch (e: MqttException) {
|
||||
error("Connection to the Broker failed")
|
||||
}
|
||||
}else{
|
||||
Log.error("could't start mqtt service because of missing db connection!")
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,7 +112,8 @@ class MqttService(serverurl: String, port: String) {
|
||||
val set2 = db.executeQuery("SELECT * FROM cities WHERE `id`='$citywastezoneid'")
|
||||
try {
|
||||
set2.last()
|
||||
if (set2.row != 1) { //error
|
||||
if (set2.row != 1) {
|
||||
//error
|
||||
warning("multiple Rows with same city id found - DB Error")
|
||||
}
|
||||
else {
|
||||
@ -111,7 +126,8 @@ class MqttService(serverurl: String, port: String) {
|
||||
val result = db.executeQuery("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=$citywastezoneid")
|
||||
try {
|
||||
result.last()
|
||||
if (result.row == 0) { //if not found in db --> send zero
|
||||
if (result.row == 0) {
|
||||
//if not found in db --> send zero
|
||||
debug("not found in db")
|
||||
tramsmitMessage("$deviceid,$wastetype,0")
|
||||
}
|
||||
@ -130,7 +146,8 @@ class MqttService(serverurl: String, port: String) {
|
||||
return
|
||||
}
|
||||
} while (result.next())
|
||||
tramsmitMessage("$deviceid,$wastetype,0") //transmit zero if not returned before
|
||||
tramsmitMessage("$deviceid,$wastetype,0")
|
||||
//transmit zero if not returned before
|
||||
}
|
||||
} catch (e: SQLException) {
|
||||
e.printStackTrace()
|
||||
@ -165,11 +182,4 @@ class MqttService(serverurl: String, port: String) {
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* receives connection object and initial connection to db
|
||||
*/
|
||||
private fun connectToDb() {
|
||||
db = JDBC.getInstance()
|
||||
}
|
||||
}
|
@ -7,7 +7,6 @@ import com.wasteinformationserver.basicutils.Storage
|
||||
import com.wasteinformationserver.db.JDBC
|
||||
import com.wasteinformationserver.website.HttpTools.Companion.stringToMD5
|
||||
import com.wasteinformationserver.website.basicrequest.PostRequest
|
||||
import java.io.IOException
|
||||
import java.sql.SQLException
|
||||
import java.util.*
|
||||
|
||||
@ -43,7 +42,7 @@ class LoginRequest : PostRequest() {
|
||||
s.last()
|
||||
if (s.row == 1) {
|
||||
//success
|
||||
if (StringToMD5(password!!) == s.getString("password")) {
|
||||
if (stringToMD5(password!!) == s.getString("password")) {
|
||||
debug("login success")
|
||||
LoginState.getObject().logIn()
|
||||
LoginState.getObject().setAccountData(username, s.getString("firstName"), s.getString("secondName"), s.getString("email"), s.getInt("permission"))
|
||||
|
87
src/resources/db.sql
Normal file
87
src/resources/db.sql
Normal file
@ -0,0 +1,87 @@
|
||||
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||
SET time_zone = "+00:00";
|
||||
|
||||
/*!40101 SET @OLD_CHARACTER_SET_CLIENT = @@CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET @OLD_CHARACTER_SET_RESULTS = @@CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET @OLD_COLLATION_CONNECTION = @@COLLATION_CONNECTION */;
|
||||
/*!40101 SET NAMES utf8mb4 */;
|
||||
|
||||
|
||||
CREATE TABLE cities
|
||||
(
|
||||
id int(11) NOT NULL,
|
||||
userid int(11) NOT NULL,
|
||||
name varchar(256) NOT NULL,
|
||||
wastetype varchar(64) NOT NULL,
|
||||
zone int(11) NOT NULL
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
CREATE TABLE devices
|
||||
(
|
||||
DeviceID int(11) NOT NULL,
|
||||
CityID int(11) NOT NULL DEFAULT '-1',
|
||||
DeviceName varchar(15) DEFAULT NULL,
|
||||
DeviceLocation varchar(15) DEFAULT NULL
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
CREATE TABLE device_city
|
||||
(
|
||||
DeviceID int(11) NOT NULL,
|
||||
CityID int(11) NOT NULL
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8mb4;
|
||||
|
||||
CREATE TABLE pickupdates
|
||||
(
|
||||
id int(11) NOT NULL,
|
||||
citywastezoneid int(11) NOT NULL,
|
||||
pickupdate date NOT NULL
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
CREATE TABLE `user`
|
||||
(
|
||||
id int(11) NOT NULL,
|
||||
username varchar(150) NOT NULL,
|
||||
firstName varchar(32) NOT NULL,
|
||||
secondName varchar(32) NOT NULL,
|
||||
password varchar(32) NOT NULL,
|
||||
permission int(11) NOT NULL DEFAULT '0',
|
||||
email varchar(64) NOT NULL,
|
||||
logindate timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
) ENGINE = InnoDB
|
||||
DEFAULT CHARSET = utf8;
|
||||
|
||||
|
||||
ALTER TABLE cities
|
||||
ADD PRIMARY KEY (id);
|
||||
|
||||
ALTER TABLE devices
|
||||
ADD PRIMARY KEY (DeviceID);
|
||||
|
||||
ALTER TABLE pickupdates
|
||||
ADD PRIMARY KEY (id),
|
||||
ADD KEY citywastezoneid (citywastezoneid);
|
||||
|
||||
ALTER TABLE `user`
|
||||
ADD PRIMARY KEY (id);
|
||||
|
||||
|
||||
ALTER TABLE cities
|
||||
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
|
||||
AUTO_INCREMENT = 143;
|
||||
ALTER TABLE pickupdates
|
||||
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
|
||||
AUTO_INCREMENT = 67;
|
||||
ALTER TABLE `user`
|
||||
MODIFY id int(11) NOT NULL AUTO_INCREMENT,
|
||||
AUTO_INCREMENT = 17;
|
||||
|
||||
ALTER TABLE pickupdates
|
||||
ADD CONSTRAINT pickupdates_ibfk_1 FOREIGN KEY (citywastezoneid) REFERENCES cities (id);
|
||||
|
||||
/*!40101 SET CHARACTER_SET_CLIENT = @OLD_CHARACTER_SET_CLIENT */;
|
||||
/*!40101 SET CHARACTER_SET_RESULTS = @OLD_CHARACTER_SET_RESULTS */;
|
||||
/*!40101 SET COLLATION_CONNECTION = @OLD_COLLATION_CONNECTION */;
|
@ -269,7 +269,7 @@ class Dashboard {
|
||||
}
|
||||
|
||||
$(".delbtn").click(function (event) {
|
||||
var id = event.target.getAttribute("dataid");
|
||||
const id = event.target.getAttribute("dataid");
|
||||
console.log("clicked btn data " + id);
|
||||
$.post('/senddata/wastedata', 'action=deletecity&id=' + id, function (data) {
|
||||
console.log(data);
|
||||
@ -283,12 +283,12 @@ class Dashboard {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
reloadtable();
|
||||
_this.reloadtable();
|
||||
} else if (data.status === "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
title: 'This city is a dependency of a date',
|
||||
html: 'Do you want do delete it anyway with all dependencies?',
|
||||
html: 'Please delete all dependencies first!',
|
||||
}).then((result) => {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
@ -353,7 +353,7 @@ class Dashboard {
|
||||
console.log('Popup closed. ')
|
||||
|
||||
});
|
||||
reloadDateTable();
|
||||
_this.reloadDateTable();
|
||||
} else if (data.status == "dependenciesnotdeleted") {
|
||||
Swal.fire({
|
||||
icon: "warning",
|
||||
|
@ -3,19 +3,17 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Login Page</title>
|
||||
<!--Made with love by Mutiullah Samim -->
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="lib/bootstrap.min.css">
|
||||
|
||||
<!-- Latest compiled and minified CSS -->
|
||||
<link rel="stylesheet" href="lib/bootstrap.min.css">
|
||||
<!-- jQuery library -->
|
||||
<script src="lib/AdminLTE/plugins/jquery/jquery.min.js"></script>
|
||||
|
||||
<!-- jQuery library -->
|
||||
<script src="lib/jquery.min.js"></script>
|
||||
<!-- Popper JS -->
|
||||
<script src="lib/popper.min.js"></script>
|
||||
|
||||
<!-- Popper JS -->
|
||||
<script src="lib/popper.min.js"></script>
|
||||
|
||||
<!-- Latest compiled JavaScript -->
|
||||
<script src="lib/bootstrap.min.js"></script>
|
||||
<!-- Latest compiled JavaScript -->
|
||||
<script src="lib/AdminLTE/plugins/bootstrap/js/bootstrap.min.js"></script>
|
||||
|
||||
<!--Fontawesome CDN-->
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css" integrity="sha384-mzrmE5qonljUremFsqc01SB46JvROS7bZs3IO2EmfFsd15uHvIt+Y8vEf7N7fWAU" crossorigin="anonymous">
|
||||
|
Loading…
x
Reference in New Issue
Block a user