commit 10/09/2025
This commit is contained in:
@@ -126,7 +126,7 @@ class MariaDB(
|
||||
|
||||
try {
|
||||
val statement =
|
||||
connection?.prepareStatement("INSERT INTO log (datenya, timenya, machine, description) VALUES (?, ?, ?, ?)")
|
||||
connection?.prepareStatement("INSERT INTO logs (datenya, timenya, machine, description) VALUES (?, ?, ?, ?)")
|
||||
statement?.setString(1, dateString)
|
||||
statement?.setString(2, timeString)
|
||||
statement?.setString(3, machine)
|
||||
@@ -152,16 +152,15 @@ class MariaDB(
|
||||
try {
|
||||
val statement = connection?.prepareStatement(
|
||||
if (logFilter.isBlank()) {
|
||||
"SELECT * FROM log WHERE datenya = ?"
|
||||
"SELECT * FROM logs WHERE datenya = ?"
|
||||
} else {
|
||||
"SELECT * FROM log WHERE datenya = ? AND (description LIKE ? OR machine LIKE ?)"
|
||||
"SELECT * FROM logs WHERE datenya = ? AND (description LIKE ?)"
|
||||
}
|
||||
)
|
||||
statement?.setString(1, logDate)
|
||||
if (!logFilter.isBlank()) {
|
||||
val filter = "%$logFilter%"
|
||||
statement?.setString(2, filter)
|
||||
statement?.setString(3, filter)
|
||||
}
|
||||
val resultSet = statement?.executeQuery()
|
||||
val workbook = XSSFWorkbook()
|
||||
@@ -223,12 +222,15 @@ class MariaDB(
|
||||
*/
|
||||
fun GetLogForHtml(date: String, consumer: Consumer<ArrayList<Log>>) {
|
||||
val logList = ArrayList<Log>()
|
||||
println("GetLogForHtml Date: $date" )
|
||||
if (ValiDateForLogHtml(date)) {
|
||||
try {
|
||||
// must convert from DD-MM-YYYY to DD/MM/YYYY, because in database we use DD/MM/YYYY
|
||||
val adjusteddate = date.replace("-", "/")
|
||||
val statement = connection?.prepareStatement("SELECT * FROM logs WHERE datenya = ?")
|
||||
statement?.setString(1, adjusteddate)
|
||||
println("GetLogForHtml Date: $adjusteddate" )
|
||||
println("GetLogForHtml SQL: " +statement?.toString())
|
||||
val resultSet = statement?.executeQuery()
|
||||
while (resultSet?.next() == true) {
|
||||
val log = Log(
|
||||
@@ -256,6 +258,8 @@ class MariaDB(
|
||||
*/
|
||||
fun GetLogForHtml(date: String, filter: String, consumer: Consumer<ArrayList<Log>>) {
|
||||
val logList = ArrayList<Log>()
|
||||
println("GetLogForHtml Date: $date Filter: $filter" )
|
||||
|
||||
if (ValiDateForLogHtml(date)) {
|
||||
try {
|
||||
// must convert from DD-MM-YYYY to DD/MM/YYYY, because in database we use DD/MM/YYYY
|
||||
@@ -264,6 +268,8 @@ class MariaDB(
|
||||
connection?.prepareStatement("SELECT * FROM logs WHERE datenya = ? AND description LIKE ?")
|
||||
statement?.setString(1, adjusteddate)
|
||||
statement?.setString(2, "%$filter%")
|
||||
println("GetLogForHtml Date: $adjusteddate , Filter=$filter" )
|
||||
println("GetLogForHtml SQL: " +statement?.toString())
|
||||
val resultSet = statement?.executeQuery()
|
||||
while (resultSet?.next() == true) {
|
||||
val log = Log(
|
||||
@@ -594,7 +600,7 @@ class MariaDB(
|
||||
*/
|
||||
fun Add_LanguageLink(languageLink: LanguageLink): Boolean {
|
||||
try {
|
||||
val statement = connection?.prepareStatement("INSERT INTO languagelink (TAG, Language) VALUES (?, ?)")
|
||||
val statement = connection?.prepareStatement("INSERT INTO languagelinking (TAG, Language) VALUES (?, ?)")
|
||||
statement?.setString(1, languageLink.TAG)
|
||||
statement?.setString(2, languageLink.Language)
|
||||
val rowsAffected = statement?.executeUpdate()
|
||||
@@ -620,7 +626,7 @@ class MariaDB(
|
||||
try {
|
||||
if (connection != null) {
|
||||
connection!!.autoCommit = false
|
||||
val sql = "INSERT INTO languagelink (TAG, Language) VALUES (?, ?)"
|
||||
val sql = "INSERT INTO languagelinking (TAG, Language) VALUES (?, ?)"
|
||||
val statement = connection!!.prepareStatement(sql)
|
||||
for (ll in languageLinkList) {
|
||||
statement.setString(1, ll.TAG)
|
||||
@@ -629,12 +635,12 @@ class MariaDB(
|
||||
}
|
||||
statement.executeBatch()
|
||||
connection!!.commit()
|
||||
Logger.info("Bulk languagelink insert successful: ${languageLinkList.size} entries" as Any)
|
||||
Logger.info("Bulk languagelinking insert successful: ${languageLinkList.size} entries" as Any)
|
||||
connection!!.autoCommit = true
|
||||
return true
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error adding languagelink entries: ${e.message}" as Any)
|
||||
Logger.error("Error adding languagelinking entries: ${e.message}" as Any)
|
||||
}
|
||||
}
|
||||
return false
|
||||
@@ -650,7 +656,7 @@ class MariaDB(
|
||||
fun Update_LanguageLink_by_index(index: UInt, languageLink: LanguageLink): Boolean {
|
||||
try {
|
||||
val statement =
|
||||
connection?.prepareStatement("UPDATE languagelink SET TAG = ?, Language = ? WHERE `index` = ?")
|
||||
connection?.prepareStatement("UPDATE languagelinking SET TAG = ?, Language = ? WHERE `index` = ?")
|
||||
statement?.setString(1, languageLink.TAG)
|
||||
statement?.setString(2, languageLink.Language)
|
||||
statement?.setLong(3, index.toLong())
|
||||
@@ -674,17 +680,17 @@ class MariaDB(
|
||||
*/
|
||||
fun Delete_LanguageLink_by_index(index: UInt): Boolean {
|
||||
try {
|
||||
val statement = connection?.prepareStatement("DELETE FROM languagelink WHERE `index` = ?")
|
||||
val statement = connection?.prepareStatement("DELETE FROM languagelinking WHERE `index` = ?")
|
||||
statement?.setLong(1, index.toLong())
|
||||
val rowsAffected = statement?.executeUpdate()
|
||||
if (rowsAffected != null && rowsAffected > 0) {
|
||||
Logger.info("Deleted $rowsAffected row(s) from languagelink with index $index" as Any)
|
||||
Logger.info("Deleted $rowsAffected row(s) from languagelinking with index $index" as Any)
|
||||
return true
|
||||
} else {
|
||||
Logger.warn("No rows deleted from languagelink with index $index" as Any)
|
||||
Logger.warn("No rows deleted from languagelinking with index $index" as Any)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error deleting from languagelink with index $index: ${e.message}" as Any)
|
||||
Logger.error("Error deleting from languagelinking with index $index: ${e.message}" as Any)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -696,12 +702,12 @@ class MariaDB(
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
// use TRUNCATE to reset auto increment index
|
||||
statement?.executeUpdate("TRUNCATE TABLE languagelink")
|
||||
Logger.info("LanguageLink table cleared" as Any)
|
||||
statement?.executeUpdate("TRUNCATE TABLE languagelinking")
|
||||
Logger.info("languagelinking table cleared" as Any)
|
||||
LanguageLinkList.clear()
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
Logger.error("Error clearing LanguageLink table: ${e.message}" as Any)
|
||||
Logger.error("Error clearing languagelinking table: ${e.message}" as Any)
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -713,9 +719,9 @@ class MariaDB(
|
||||
fun Export_LanguageLink_XLSX(): XSSFWorkbook? {
|
||||
try {
|
||||
val statement = connection?.createStatement()
|
||||
val resultSet = statement?.executeQuery("SELECT * FROM languagelink")
|
||||
val resultSet = statement?.executeQuery("SELECT * FROM languagelinking")
|
||||
val workbook = XSSFWorkbook()
|
||||
val sheet = workbook.createSheet("LanguageLink")
|
||||
val sheet = workbook.createSheet("languagelinking")
|
||||
val headerRow = sheet.createRow(0)
|
||||
val headers = arrayOf("Index", "TAG", "Language")
|
||||
for ((colIndex, header) in headers.withIndex()) {
|
||||
@@ -734,7 +740,7 @@ class MariaDB(
|
||||
}
|
||||
return workbook
|
||||
} catch (e: Exception) {
|
||||
Logger.error { "Error exporting LanguageLink, Msg: ${e.message}" }
|
||||
Logger.error { "Error exporting languagelinking, Msg: ${e.message}" }
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
if (!exists) {
|
||||
if (ValidFile(addvalue.Path)) {
|
||||
if (db.Add_Soundbank(addvalue)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to add soundbank to database")
|
||||
} else it.status(400)
|
||||
@@ -216,10 +216,10 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
} else it.status(400)
|
||||
.result("TAG=${addvalue.TAG} already exists for the same Language=${addvalue.Language} and Category=${addvalue.Category}")
|
||||
} else it.status(400).result("Invalid Path")
|
||||
} else it.status(400).result("Invalid Language")
|
||||
} else it.status(400).result("Invalid Category")
|
||||
} else it.status(400).result("Invalid TAG")
|
||||
} else it.status(400).result("Invalid Description")
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Language")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Category")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid TAG")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Description")))
|
||||
} catch (_: Exception) {
|
||||
it.status(400).result("Invalid request body")
|
||||
}
|
||||
@@ -227,7 +227,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate soundbank table
|
||||
if (db.Clear_Soundbank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate soundbank table")
|
||||
}
|
||||
@@ -236,10 +236,10 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Soundbank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete soundbank with index $index")
|
||||
}
|
||||
@@ -250,7 +250,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
// tidak ada path param index
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val sb = db.SoundbankList.find { xx -> xx.index == index }
|
||||
if (sb == null) {
|
||||
@@ -260,7 +260,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// soundbank dengan index tersebut ditemukan, sekarang update
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _tag = json.get("TAG").asText()
|
||||
@@ -283,7 +283,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
sb.Category = _category
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Category")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Category")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
@@ -302,7 +302,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Soundbank_by_index(index, sb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500).result("Failed to update soundbank with index $index")
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for soundbank with index $index")
|
||||
@@ -328,18 +328,18 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Soundbank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import soundbank from XLSX")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -354,21 +354,21 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate messagebank table
|
||||
if (db.Clear_Messagebank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate messagebank table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate messagebank table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Messagebank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete messagebank with index $index")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to delete messagebank with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -376,15 +376,15 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update messagebank by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val mb = db.MessagebankList.find { xx -> xx.index == index }
|
||||
if (mb == null) {
|
||||
it.status(404).result("Messagebank with index $index not found")
|
||||
it.status(404).result(objectmapper.writeValueAsString(mapOf("message" to "Messagebank with index $index not found")))
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _language = json.get("Language").asText()
|
||||
@@ -411,7 +411,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
mb.Voice_Type = _voice_type
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Voice_Type")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Voice_Type")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
@@ -425,11 +425,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Messagebank_by_index(index, mb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update messagebank with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update messagebank with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for messagebank with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for messagebank with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,24 +446,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export messagebank to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export messagebank to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Messagebank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import messagebank from XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to import messagebank from XLSX")))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -482,30 +482,30 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
if (db.LanguageLinkList.any { ll -> ll.TAG==tag }){
|
||||
val newvalue = LanguageLink(0u, tag, languages.joinToString(";"))
|
||||
if (db.Add_LanguageLink(newvalue)){
|
||||
it.result("OK")
|
||||
} else it.status(500).result("Failed to add language link to database")
|
||||
} else it.status(400).result("TAG=$tag already exists" )
|
||||
} else it.status(400).result("Contains unsupported language" )
|
||||
} else it.status(400).result("Invalid tag or language")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to add language link to database")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "TAG=$tag already exists")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Contains unsupported language")))
|
||||
} else it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid tag or language")))
|
||||
}
|
||||
delete("List") {
|
||||
// truncate language link table
|
||||
if (db.Clear_LanguageLink()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate language link table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate language link table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_LanguageLink_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete language link with index $index")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to delete language link with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -513,18 +513,18 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val ll = db.LanguageLinkList.find { xx -> xx.index == index }
|
||||
if (ll == null) {
|
||||
it.status(404).result("Language link with index $index not found")
|
||||
it.status(404).result(objectmapper.writeValueAsString(mapOf("message" to "Language link with index $index not found")))
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _tag = json.get("TAG").asText()
|
||||
val _language = json.get("Language").asText()
|
||||
val _tag = json.get("tag").asText()
|
||||
val _language = json.get("language").asText()
|
||||
var changed = false
|
||||
if (ValidString(_language) && _language != ll.Language) {
|
||||
ll.Language = _language
|
||||
@@ -536,11 +536,11 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_LanguageLink_by_index(index, ll)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update language link with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update language link with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for language link with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for language link with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -557,24 +557,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export language link to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export language link to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_LanguageLink_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import language link from XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to import language link from XLSX")))
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -586,19 +586,19 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
delete("List") {
|
||||
// truncate timer table
|
||||
if (db.Clear_Schedulebank()) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to truncate schedulebank table")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to truncate schedulebank table")))
|
||||
}
|
||||
}
|
||||
delete("DeleteByIndex/{index}") {
|
||||
// delete by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
if (db.Delete_Schedulebank_by_index(index)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to delete schedule with index $index")
|
||||
}
|
||||
@@ -608,7 +608,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
// update by index
|
||||
val index = it.pathParam("index").toUIntOrNull()
|
||||
if (index == null) {
|
||||
it.status(400).result("Invalid index")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid index")))
|
||||
} else {
|
||||
val sb = db.SchedulebankList.find { xx -> xx.index == index }
|
||||
if (sb == null) {
|
||||
@@ -616,7 +616,7 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
} else {
|
||||
val json: JsonNode = objectmapper.readTree(it.body())
|
||||
if (json.isEmpty) {
|
||||
it.status(400).result("UpdateByIndex with index=$index has empty body")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "UpdateByIndex with index=$index has empty body")))
|
||||
} else {
|
||||
val _description = json.get("Description").asText()
|
||||
val _time = json.get("Time").asText()
|
||||
@@ -670,17 +670,17 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
sb.Language = _language
|
||||
changed = true
|
||||
} else {
|
||||
it.status(400).result("Invalid Language")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid Language")))
|
||||
return@patch
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
if (db.Update_Schedulebank_by_index(index, sb)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else it.status(500)
|
||||
.result("Failed to update schedule with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Failed to update schedule with index $index")))
|
||||
} else it.status(400)
|
||||
.result("Nothing has changed for schedule with index $index")
|
||||
.result(objectmapper.writeValueAsString(mapOf("message" to "Nothing has changed for schedule with index $index")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -697,24 +697,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
xlsxdata.write(out)
|
||||
}
|
||||
} else {
|
||||
it.status(500).result("Failed to export schedulebank to XLSX")
|
||||
it.status(500).result(objectmapper.writeValueAsString(mapOf("message" to "Failed to export schedulebank to XLSX")))
|
||||
}
|
||||
}
|
||||
post("ImportXLSX") {
|
||||
val uploaded = it.uploadedFile("file")
|
||||
if (uploaded == null) {
|
||||
it.status(400).result("No file uploaded")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "No file uploaded")))
|
||||
return@post
|
||||
}
|
||||
try {
|
||||
val xlsx = XSSFWorkbook(uploaded.content())
|
||||
if (db.Import_Schedulebank_XLSX(xlsx)) {
|
||||
it.result("OK")
|
||||
it.result(objectmapper.writeValueAsString(mapOf("message" to "OK")))
|
||||
} else {
|
||||
it.status(500).result("Failed to import schedulebank from XLSX")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
it.status(400).result("Invalid XLSX file")
|
||||
it.status(400).result(objectmapper.writeValueAsString(mapOf("message" to "Invalid XLSX file")))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -738,14 +738,15 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>, val
|
||||
get1.status(400).result("Invalid logdate")
|
||||
}
|
||||
}
|
||||
get("ExportXLSX/<logdate>/<logfilter>") { get1 ->
|
||||
val logdate = get1.pathParam("logdate")
|
||||
val logfilter = get1.pathParam("logfilter")
|
||||
if (ValidDate(logdate)) {
|
||||
get("ExportXLSX") { get1 ->
|
||||
val logdate = get1.queryParam("date") ?: ""
|
||||
val logfilter = get1.queryParam("filter") ?: ""
|
||||
println("Export log to XLSX, date=$logdate, filter=$logfilter")
|
||||
if (ValiDateForLogHtml(logdate)) {
|
||||
val xlsxdata = if (ValidString(logfilter)) {
|
||||
db.Export_Log_XLSX(logdate, logfilter)
|
||||
db.Export_Log_XLSX(logdate.replace('-','/'), logfilter)
|
||||
} else {
|
||||
db.Export_Log_XLSX(logdate, "")
|
||||
db.Export_Log_XLSX(logdate.replace('-','/'), "")
|
||||
}
|
||||
if (xlsxdata != null) {
|
||||
get1.header(
|
||||
|
||||
Reference in New Issue
Block a user