commit 10/10/2025
Broadcast Zones and Sound Channels
This commit is contained in:
@@ -176,7 +176,7 @@ fun main() {
|
||||
|
||||
StreamerOutputs[cmd.ipaddress] = _bc
|
||||
Logger.info { "Created new Streamer Output for channel ${_sc.channel} with IP ${cmd.ipaddress}" }
|
||||
} else Logger.warn { "soundChannelDB doesn't have soundchannel with IP ${cmd.ipaddress}" }
|
||||
}
|
||||
|
||||
} else {
|
||||
// sudah ada, update data
|
||||
|
||||
@@ -995,7 +995,7 @@ class MariaDB(
|
||||
override fun Add(data: BroadcastZones): Boolean {
|
||||
try {
|
||||
val statement =
|
||||
connection.prepareStatement("INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) VALUES (?, ?, ?, ?)")
|
||||
connection.prepareStatement("INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) VALUES (?, ?, ?, ?)")
|
||||
statement?.setString(1, data.description)
|
||||
statement?.setString(2, data.SoundChannel)
|
||||
statement?.setString(3, data.id)
|
||||
@@ -1017,7 +1017,7 @@ class MariaDB(
|
||||
try {
|
||||
connection.autoCommit = false
|
||||
val sql =
|
||||
"INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) VALUES (?, ?, ?, ?)"
|
||||
"INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) VALUES (?, ?, ?, ?)"
|
||||
val statement = connection.prepareStatement(sql)
|
||||
for (bz in data) {
|
||||
statement.setString(1, bz.description)
|
||||
@@ -1040,7 +1040,7 @@ class MariaDB(
|
||||
override fun UpdateByIndex(index: Int, data: BroadcastZones): Boolean {
|
||||
try {
|
||||
val statement =
|
||||
connection.prepareStatement("UPDATE ${super.dbName} SET description = ?, SoundChannel = ?, Box = ?, Relay = ? WHERE `index` = ?")
|
||||
connection.prepareStatement("UPDATE ${super.dbName} SET description = ?, SoundChannel = ?, id = ?, bp = ? WHERE `index` = ?")
|
||||
statement?.setString(1, data.description)
|
||||
statement?.setString(2, data.SoundChannel)
|
||||
statement?.setString(3, data.id)
|
||||
@@ -1066,9 +1066,9 @@ class MariaDB(
|
||||
// use a temporary table to reorder the index
|
||||
statement?.executeUpdate("CREATE TABLE IF NOT EXISTS $tempdb_name LIKE ${super.dbName}")
|
||||
statement?.executeUpdate("TRUNCATE TABLE $tempdb_name")
|
||||
statement?.executeUpdate("INSERT INTO $tempdb_name (description, SoundChannel, Box, Relay) SELECT description, SoundChannel, Box, Relay FROM ${super.dbName} ORDER BY description ")
|
||||
statement?.executeUpdate("INSERT INTO $tempdb_name (description, SoundChannel, id, bp) SELECT description, SoundChannel, id, bp FROM ${super.dbName} ORDER BY description ")
|
||||
statement?.executeUpdate("TRUNCATE TABLE ${super.dbName}")
|
||||
statement?.executeUpdate("INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) SELECT description, SoundChannel, Box, Relay FROM $tempdb_name")
|
||||
statement?.executeUpdate("INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) SELECT description, SoundChannel, id, bp FROM $tempdb_name")
|
||||
statement?.executeUpdate("DROP TABLE $tempdb_name")
|
||||
Logger.info("${super.dbName} table resorted by description" as Any)
|
||||
// reload the local list
|
||||
@@ -1085,7 +1085,7 @@ class MariaDB(
|
||||
val sheet = workbook.getSheet("BroadcastZones")
|
||||
?: throw Exception("No sheet named 'BroadcastZones' found")
|
||||
val headerRow = sheet.getRow(0) ?: throw Exception("No header row found")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "Box", "Relay")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "id", "bp")
|
||||
for ((colIndex, header) in headers.withIndex()) {
|
||||
val cell = headerRow.getCell(colIndex) ?: throw Exception("Header '$header' not found")
|
||||
if (cell.stringCellValue != header) throw Exception("Header '$header' not found")
|
||||
@@ -1098,9 +1098,9 @@ class MariaDB(
|
||||
val row = sheet.getRow(rowIndex) ?: continue
|
||||
val description = row.getCell(1)?.stringCellValue ?: continue
|
||||
val soundChannel = row.getCell(2)?.stringCellValue ?: continue
|
||||
val box = row.getCell(3)?.stringCellValue ?: continue
|
||||
val relay = row.getCell(4)?.stringCellValue ?: continue
|
||||
val broadcastZone = BroadcastZones(0u, description, soundChannel, box, relay)
|
||||
val id = row.getCell(3)?.stringCellValue ?: continue
|
||||
val bp = row.getCell(4)?.stringCellValue ?: continue
|
||||
val broadcastZone = BroadcastZones(0u, description, soundChannel, id, bp)
|
||||
_broadcastZonesList.add(broadcastZone)
|
||||
}
|
||||
return AddAll(_broadcastZonesList)
|
||||
@@ -1117,7 +1117,7 @@ class MariaDB(
|
||||
val workbook = XSSFWorkbook()
|
||||
val sheet = workbook.createSheet("BroadcastZones")
|
||||
val headerRow = sheet.createRow(0)
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "Box", "Relay")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "id", "bp")
|
||||
for ((colIndex, header) in headers.withIndex()) {
|
||||
val cell = headerRow.createCell(colIndex)
|
||||
cell.setCellValue(header)
|
||||
@@ -1128,8 +1128,8 @@ class MariaDB(
|
||||
row.createCell(0).setCellValue(resultSet.getString("index"))
|
||||
row.createCell(1).setCellValue(resultSet.getString("description"))
|
||||
row.createCell(2).setCellValue(resultSet.getString("SoundChannel"))
|
||||
row.createCell(3).setCellValue(resultSet.getString("Box"))
|
||||
row.createCell(4).setCellValue(resultSet.getString("Relay"))
|
||||
row.createCell(3).setCellValue(resultSet.getString("id"))
|
||||
row.createCell(4).setCellValue(resultSet.getString("bp"))
|
||||
}
|
||||
for (i in headers.indices) {
|
||||
sheet.autoSizeColumn(i)
|
||||
@@ -2361,6 +2361,17 @@ class MariaDB(
|
||||
.sorted()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all distinct sound channel from soundchannelDB
|
||||
* @return a list of distinct sound channel sorted alphabetically
|
||||
*/
|
||||
fun Get_SoundChannel_List(): List<String> {
|
||||
return soundchannelDB.List
|
||||
.distinctBy { it.channel }
|
||||
.map { it.channel }
|
||||
.sorted()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a username already exists in the userDB (case-insensitive)
|
||||
*/
|
||||
|
||||
@@ -1114,17 +1114,6 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
}
|
||||
path("BroadcastZones") {
|
||||
get("List") {
|
||||
// TODO : temporary, convert BroadcastZones to BroadcastZonesHtml, karena harus revisi javascript di Bootstrap Studio
|
||||
// val newlist: ArrayList<BroadcastZonesHtml> = db.broadcastDB.List.map { xx ->
|
||||
// BroadcastZonesHtml(
|
||||
// xx.index,
|
||||
// xx.description,
|
||||
// xx.SoundChannel,
|
||||
// xx.id,
|
||||
// xx.bp
|
||||
// )
|
||||
// } as ArrayList<BroadcastZonesHtml>
|
||||
|
||||
it.result(MariaDB.ArrayListtoString(db.broadcastDB.List))
|
||||
}
|
||||
get("BroadcastZoneDescriptions") { ctx ->
|
||||
@@ -1276,6 +1265,9 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
get("List") {
|
||||
it.result(MariaDB.ArrayListtoString(db.soundchannelDB.List))
|
||||
}
|
||||
get("SoundChannelDescriptions") {
|
||||
it.result(objectmapper.writeValueAsString(db.Get_SoundChannel_List()))
|
||||
}
|
||||
delete("List") {
|
||||
// truncate sound channel table
|
||||
if (db.soundchannelDB.Clear()) {
|
||||
@@ -1318,29 +1310,24 @@ class WebApp(val listenPort: Int, val userlist: List<Pair<String, String>>) {
|
||||
} else {
|
||||
|
||||
// cek apakah ada soundchannel lain yang pakai ip dan channel yang sama
|
||||
if (db.soundchannelDB.List.any { xx ->
|
||||
xx.index != index && _ip.equals(
|
||||
xx.ip
|
||||
) && _channel.equals(xx.channel, true)
|
||||
}) {
|
||||
println("Another sound channel already uses IP $_ip and channel $_channel")
|
||||
it.status(400)
|
||||
.result(objectmapper.writeValueAsString(resultMessage("Another sound channel already uses IP $_ip and channel $_channel")))
|
||||
return@patch
|
||||
val othersc = db.soundchannelDB.List.filter { sc -> sc.ip == _ip }.filter { sc -> sc.index != index }
|
||||
if (othersc.isNotEmpty()){
|
||||
it.status(400).result(objectmapper.writeValueAsString(resultMessage("This IP address is already used by another sound channel")))
|
||||
} else {
|
||||
// ada sesuatu yang ganti
|
||||
val newsc = SoundChannel(0u, _channel, _ip)
|
||||
if (db.soundchannelDB.UpdateByIndex(index.toInt(), newsc)) {
|
||||
println("Updated sound channel with index $index")
|
||||
db.soundchannelDB.Resort()
|
||||
it.result(objectmapper.writeValueAsString(resultMessage("OK")))
|
||||
} else {
|
||||
println("Failed to update sound channel with index $index")
|
||||
it.status(500)
|
||||
.result(objectmapper.writeValueAsString(resultMessage("Failed to update sound channel with index $index")))
|
||||
}
|
||||
}
|
||||
|
||||
// ada sesuatu yang ganti
|
||||
val newsc = SoundChannel(0u, _channel, _ip)
|
||||
if (db.soundchannelDB.UpdateByIndex(index.toInt(), newsc)) {
|
||||
println("Updated sound channel with index $index")
|
||||
db.soundchannelDB.Resort()
|
||||
it.result(objectmapper.writeValueAsString(resultMessage("OK")))
|
||||
} else {
|
||||
println("Failed to update sound channel with index $index")
|
||||
it.status(500)
|
||||
.result(objectmapper.writeValueAsString(resultMessage("Failed to update sound channel with index $index")))
|
||||
return@patch
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user