removed unused initializer

converted Daterequest to kotlin
This commit is contained in:
Lukas-Heiligenbrunner 2020-02-28 16:35:55 +01:00
parent 022ae044ab
commit 76f5c36ba1
3 changed files with 124 additions and 128 deletions

View File

@ -142,11 +142,10 @@ class DeviceRequest : PostRequest() {
sb.append("{\"status\":\"success\"}")
}
"addtodb" -> {
var cityid = -1
try {
val device = jdbc.executeQuery("SELECT * FROM cities WHERE name='" + params["cityname"] + "' AND wastetype='" + params["wastetype"] + "' AND zone='" + params["zonename"] + "'")
device.first()
cityid = device.getInt("id")
var cityid = device.getInt("id")
jdbc.executeUpdate("INSERT INTO `device_city` (`DeviceID`, `CityID`) VALUES ('" + params["deviceid"] + "', '" + cityid + "');")
} catch (e: SQLException) {
e.printStackTrace()

View File

@ -1,126 +0,0 @@
package com.wasteinformationserver.website.datarequests;
import com.wasteinformationserver.basicutils.Log;
import com.wasteinformationserver.db.JDBC;
import com.wasteinformationserver.website.basicrequest.PostRequest;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
public class NewDateRequest extends PostRequest {
@Override
public String request(HashMap<String, String> params) {
StringBuilder sb = new StringBuilder();
ResultSet set;
JDBC jdbc = JDBC.getInstance();
if (!jdbc.isConnected()) {
Log.Log.error("no connection to db");
return "{\"query\" : \"nodbconn\"}";
}
switch (params.get("action")) {
case "getCitynames":
set = jdbc.executeQuery("select * from cities");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "";
while (set.next()) {
if (prev.equals(set.getString("name"))) {
} else {
if (!set.isFirst()) {
sb.append(",");
}
sb.append("{\"cityname\":\"" + set.getString("name") + "\"}");
}
prev = set.getString("name");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
Log.Log.debug(sb.toString());
break;
case "getzones":
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' ORDER BY zone ASC");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
int prev = 42;
while (set.next()) {
if (prev == set.getInt("zone")) {
} else {
sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
prev = set.getInt("zone");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "gettypes":
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zonename") + "' ORDER BY zone ASC");
Log.Log.debug(set.toString());
sb.append("{\"data\":[");
try {
String prev = "42";
while (set.next()) {
if (prev == set.getString("wastetype")) {
} else {
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}");
if (!set.isLast()) {
sb.append(",");
}
}
prev = set.getString("wastetype");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append("]");
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
case "newdate":
sb.append("{");
Log.Log.debug(params);
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params.get("cityname") + "' AND `zone`='" + params.get("zone") + "' AND `wastetype`='" + params.get("wastetype") + "'");
try {
set.last();
if (set.getRow() == 1) {
Log.Log.debug(set.getInt("id"));
int status = jdbc.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params.get("date") + "')");
if (status == 1) {
sb.append("\"status\" : \"success\"");
} else {
sb.append("\"status\" : \"error\"");
}
} else {
Log.Log.warning("city doesnt exist!");
sb.append("\"status\" : \"citydoesntexist\"");
}
} catch (SQLException e) {
e.printStackTrace();
}
sb.append(",\"query\":\"ok\"");
sb.append("}");
break;
}
return sb.toString();
}
}

View File

@ -0,0 +1,123 @@
package com.wasteinformationserver.website.datarequests
import com.wasteinformationserver.basicutils.Log.Log.debug
import com.wasteinformationserver.basicutils.Log.Log.error
import com.wasteinformationserver.basicutils.Log.Log.warning
import com.wasteinformationserver.db.JDBC
import com.wasteinformationserver.website.basicrequest.PostRequest
import java.sql.ResultSet
import java.sql.SQLException
class NewDateRequest : PostRequest() {
override fun request(params: HashMap<String, String>): String {
val sb = StringBuilder()
val set: ResultSet
val jdbc = JDBC.getInstance()
if (!jdbc.isConnected) {
error("no connection to db")
return "{\"query\" : \"nodbconn\"}"
}
when (params["action"]) {
"getCitynames" -> {
set = jdbc.executeQuery("select * from cities")
debug(set.toString())
sb.append("{\"data\":[")
try {
var prev = ""
while (set.next()) {
if (prev == set.getString("name")) {
}
else {
if (!set.isFirst) {
sb.append(",")
}
sb.append("{\"cityname\":\"" + set.getString("name") + "\"}")
}
prev = set.getString("name")
}
} catch (e: SQLException) {
e.printStackTrace()
}
sb.append("]")
sb.append(",\"query\":\"ok\"")
sb.append("}")
debug(sb.toString())
}
"getzones" -> {
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' ORDER BY zone ASC")
debug(set.toString())
sb.append("{\"data\":[")
try {
var prev = 42
while (set.next()) {
if (prev == set.getInt("zone")) {
}
else {
sb.append("{\"zone\":\"" + set.getInt("zone") + "\"}")
if (!set.isLast) {
sb.append(",")
}
}
prev = set.getInt("zone")
}
} catch (e: SQLException) {
e.printStackTrace()
}
sb.append("]")
sb.append(",\"query\":\"ok\"")
sb.append("}")
}
"gettypes" -> {
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zonename"] + "' ORDER BY zone ASC")
debug(set.toString())
sb.append("{\"data\":[")
try {
var prev = "42"
while (set.next()) {
if (prev === set.getString("wastetype")) {
}
else {
sb.append("{\"wastetype\":\"" + set.getString("wastetype") + "\"}")
if (!set.isLast) {
sb.append(",")
}
}
prev = set.getString("wastetype")
}
} catch (e: SQLException) {
e.printStackTrace()
}
sb.append("]")
sb.append(",\"query\":\"ok\"")
sb.append("}")
}
"newdate" -> {
sb.append("{")
debug(params)
set = jdbc.executeQuery("select * from cities WHERE `name`='" + params["cityname"] + "' AND `zone`='" + params["zone"] + "' AND `wastetype`='" + params["wastetype"] + "'")
try {
set.last()
if (set.row == 1) {
debug(set.getInt("id"))
val status = jdbc.executeUpdate("INSERT INTO `pickupdates`(`citywastezoneid`, `pickupdate`) VALUES ('" + set.getInt("id") + "','" + params["date"] + "')")
if (status == 1) {
sb.append("\"status\" : \"success\"")
}
else {
sb.append("\"status\" : \"error\"")
}
}
else {
warning("city doesnt exist!")
sb.append("\"status\" : \"citydoesntexist\"")
}
} catch (e: SQLException) {
e.printStackTrace()
}
sb.append(",\"query\":\"ok\"")
sb.append("}")
}
}
return sb.toString()
}
}