Deduplicate default values in StartupController

This commit is contained in:
Hannes Braun 2022-12-19 20:26:45 +01:00
parent e6f09c11ba
commit 795ddc516d
Signed by: hannesbraun
GPG Key ID: 7B6557E1DFD685BE
1 changed files with 16 additions and 24 deletions

View File

@ -77,29 +77,21 @@ class StartupController {
val properties = Properties()
properties.loadFromXML(FileInputStream(fileConfig))
cachetAPIKey = try {
properties.getProperty("cachetAPIKey")
} catch (ex: Exception) {
"0"
}
try {
cachetAPIKey = properties.getProperty("cachetAPIKey")
} catch (_: Exception) {}
cachetBaseURL = try {
properties.getProperty("cachetBaseURL")
} catch (ex: Exception) {
"https://status.mosad.xyz"
}
try {
cachetBaseURL = properties.getProperty("cachetBaseURL")
} catch (_: Exception) {}
mensaMenuURL = try {
properties.getProperty("mensaMenuURL")
} catch (ex: Exception) {
"https://www.swfr.de/essen-trinken/speiseplaene/mensa-offenburg/"
}
try {
mensaMenuURL = properties.getProperty("mensaMenuURL")
} catch (_: Exception) {}
mensaName = try {
properties.getProperty("mensaName")
} catch (ex: Exception) {
"Offenburg"
}
try {
mensaName = properties.getProperty("mensaName")
} catch (_: Exception) {}
} catch (ex: Exception) {
logger.error("error while loading config", ex)
@ -111,10 +103,10 @@ class StartupController {
private fun createConfig() = try {
val properties = Properties()
properties.setProperty("cachetAPIKey", "0")
properties.setProperty("cachetBaseURL", "https://status.mosad.xyz")
properties.setProperty("mensaMenuURL", "https://www.swfr.de/essen-trinken/speiseplaene/mensa-offenburg/")
properties.setProperty("mensaName", "Offenburg")
properties.setProperty("cachetAPIKey", cachetAPIKey)
properties.setProperty("cachetBaseURL", cachetBaseURL)
properties.setProperty("mensaMenuURL", mensaMenuURL)
properties.setProperty("mensaName", mensaName)
val outputStream = FileOutputStream(fileConfig)
properties.storeToXML(outputStream, "tcor configuration")