commit 14072025
This commit is contained in:
18
.idea/dataSources.xml
generated
Normal file
18
.idea/dataSources.xml
generated
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||||
|
<data-source source="LOCAL" name="mariadB" uuid="a738dd17-8123-478b-81aa-6ecf4f890ccc">
|
||||||
|
<driver-ref>mariadb</driver-ref>
|
||||||
|
<synchronize>true</synchronize>
|
||||||
|
<jdbc-driver>org.mariadb.jdbc.Driver</jdbc-driver>
|
||||||
|
<jdbc-url>jdbc:mariadb://localhost:3306/aas</jdbc-url>
|
||||||
|
<jdbc-additional-properties>
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.host.port" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.resource.type" value="Deployment" />
|
||||||
|
<property name="com.intellij.clouds.kubernetes.db.container.port" />
|
||||||
|
</jdbc-additional-properties>
|
||||||
|
<working-dir>$ProjectFileDir$</working-dir>
|
||||||
|
</data-source>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
5
.idea/inspectionProfiles/Project_Default.xml
generated
5
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,11 @@
|
|||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||||
|
<Languages>
|
||||||
|
<language minSize="47" name="Kotlin" />
|
||||||
|
</Languages>
|
||||||
|
</inspection_tool>
|
||||||
<inspection_tool class="FunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="FunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
||||||
|
|||||||
7
.idea/sqldialects.xml
generated
Normal file
7
.idea/sqldialects.xml
generated
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="SqlDialectMappings">
|
||||||
|
<file url="file://$PROJECT_DIR$/src/database/MariaDB.kt" dialect="GenericSQL" />
|
||||||
|
<file url="PROJECT" dialect="MariaDB" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -6,4 +6,20 @@ data class Log(
|
|||||||
val timenya: String,
|
val timenya: String,
|
||||||
val machine: String,
|
val machine: String,
|
||||||
val description : String
|
val description : String
|
||||||
)
|
) {
|
||||||
|
@Suppress("unused")
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun ValidDate(date: String): Boolean {
|
||||||
|
// Simple date validation (DD/MM/YYYY)
|
||||||
|
val regex = Regex("""^(0[1-9]|[12][0-9]|3[01])/(0[1-9]|1[0-2])/\d{4}$""")
|
||||||
|
return regex.matches(date)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun validTime(time: String): Boolean {
|
||||||
|
// Simple time validation (HH:MM:SS)
|
||||||
|
val regex = Regex("""^(0[0-9]|1[0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9])$""")
|
||||||
|
return regex.matches(time)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package database
|
|||||||
import org.mariadb.jdbc.Connection
|
import org.mariadb.jdbc.Connection
|
||||||
import org.tinylog.Logger
|
import org.tinylog.Logger
|
||||||
import java.sql.DriverManager
|
import java.sql.DriverManager
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class to manage a connection to a MariaDB database.
|
* A class to manage a connection to a MariaDB database.
|
||||||
@@ -13,6 +15,7 @@ import java.sql.DriverManager
|
|||||||
* @property username The username for the database connection.
|
* @property username The username for the database connection.
|
||||||
* @property password The password for the database connection.
|
* @property password The password for the database connection.
|
||||||
*/
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
class MariaDB (
|
class MariaDB (
|
||||||
address : String = "localhost",
|
address : String = "localhost",
|
||||||
port : Int = 3306,
|
port : Int = 3306,
|
||||||
@@ -30,6 +33,8 @@ class MariaDB (
|
|||||||
connection = DriverManager.getConnection("jdbc:mariadb://$address:$port/$dbName", username, password) as Connection
|
connection = DriverManager.getConnection("jdbc:mariadb://$address:$port/$dbName", username, password) as Connection
|
||||||
Logger.info("Connected to MariaDB" as Any)
|
Logger.info("Connected to MariaDB" as Any)
|
||||||
connected = true
|
connected = true
|
||||||
|
Reload_Soundbank()
|
||||||
|
Reload_Messagebank()
|
||||||
} catch (e : Exception) {
|
} catch (e : Exception) {
|
||||||
Logger.error("Failed to connect to MariaDB: ${e.message}" as Any)
|
Logger.error("Failed to connect to MariaDB: ${e.message}" as Any)
|
||||||
}
|
}
|
||||||
@@ -49,6 +54,116 @@ class MariaDB (
|
|||||||
connected = false
|
connected = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Log from database
|
||||||
|
* @return ArrayList of Log objects
|
||||||
|
*/
|
||||||
|
fun GetLog() : ArrayList<Log> {
|
||||||
|
val logList = ArrayList<Log>()
|
||||||
|
try {
|
||||||
|
val statement = connection?.createStatement()
|
||||||
|
val resultSet = statement?.executeQuery("SELECT * FROM log")
|
||||||
|
while (resultSet?.next() == true) {
|
||||||
|
val log = Log(
|
||||||
|
resultSet.getLong("index").toULong(),
|
||||||
|
resultSet.getString("datenya"),
|
||||||
|
resultSet.getString("timenya"),
|
||||||
|
resultSet.getString("machine"),
|
||||||
|
resultSet.getString("description")
|
||||||
|
)
|
||||||
|
logList.add(log)
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Logger.error("Error fetching logs: ${e.message}" as Any)
|
||||||
|
}
|
||||||
|
return logList
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Log from database by date
|
||||||
|
* @param date The date to filter logs by (format: DD/MM/YYYY)
|
||||||
|
* @return ArrayList of Log objects for the specified date
|
||||||
|
*/
|
||||||
|
fun GetLog(date : String) : ArrayList<Log> {
|
||||||
|
val logList = ArrayList<Log>()
|
||||||
|
try {
|
||||||
|
val statement = connection?.prepareStatement("SELECT * FROM log WHERE datenya = ?")
|
||||||
|
statement?.setString(1, date)
|
||||||
|
val resultSet = statement?.executeQuery()
|
||||||
|
while (resultSet?.next() == true) {
|
||||||
|
val log = Log(
|
||||||
|
resultSet.getLong("index").toULong(),
|
||||||
|
resultSet.getString("datenya"),
|
||||||
|
resultSet.getString("timenya"),
|
||||||
|
resultSet.getString("machine"),
|
||||||
|
resultSet.getString("description")
|
||||||
|
)
|
||||||
|
logList.add(log)
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Logger.error("Error fetching logs for date $date: ${e.message}" as Any)
|
||||||
|
}
|
||||||
|
return logList
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Log from database by date
|
||||||
|
* @param date The date to filter logs by (as LocalDateTime)
|
||||||
|
* @return ArrayList of Log objects for the specified date
|
||||||
|
*/
|
||||||
|
fun GetLog(date : LocalDateTime) : ArrayList<Log> {
|
||||||
|
val datenya = DateTimeFormatter.ofPattern("DD/MM/YYYY").format(date)
|
||||||
|
return GetLog(datenya)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads the soundbank list from the database.
|
||||||
|
*/
|
||||||
|
private fun Reload_Soundbank() {
|
||||||
|
SoundbankList.clear()
|
||||||
|
try {
|
||||||
|
val statement = connection?.createStatement()
|
||||||
|
val resultSet = statement?.executeQuery("SELECT * FROM soundbank")
|
||||||
|
while (resultSet?.next() == true) {
|
||||||
|
val soundbank = Soundbank(
|
||||||
|
resultSet.getLong("index").toUInt(),
|
||||||
|
resultSet.getString("Description"),
|
||||||
|
resultSet.getString("TAG"),
|
||||||
|
resultSet.getString("Category"),
|
||||||
|
resultSet.getString("Language"),
|
||||||
|
resultSet.getString("VoiceType"),
|
||||||
|
resultSet.getString("Path")
|
||||||
|
)
|
||||||
|
SoundbankList.add(soundbank)
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Logger.error("Error fetching soundbanks: ${e.message}" as Any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reloads the messagebank list from the database.
|
||||||
|
*/
|
||||||
|
private fun Reload_Messagebank() {
|
||||||
|
MessagebankList.clear()
|
||||||
|
try {
|
||||||
|
val statement = connection?.createStatement()
|
||||||
|
val resultSet = statement?.executeQuery("SELECT * FROM messagebank")
|
||||||
|
while (resultSet?.next() == true) {
|
||||||
|
val messagebank = Messagebank(
|
||||||
|
resultSet.getLong("index").toUInt(),
|
||||||
|
resultSet.getString("Description"),
|
||||||
|
resultSet.getString("TAG"),
|
||||||
|
resultSet.getInt("Category").toUInt(),
|
||||||
|
resultSet.getString("Language"),
|
||||||
|
resultSet.getString("VoiceType"),
|
||||||
|
resultSet.getString("Path")
|
||||||
|
)
|
||||||
|
MessagebankList.add(messagebank)
|
||||||
|
}
|
||||||
|
} catch (e : Exception) {
|
||||||
|
Logger.error("Error fetching messagebanks: ${e.message}" as Any)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user