From 795ddc516d059ab19d8cbcbd8c83acaca2f55bde Mon Sep 17 00:00:00 2001 From: Hannes Braun Date: Mon, 19 Dec 2022 20:26:45 +0100 Subject: [PATCH] Deduplicate default values in StartupController --- .../controller/StartupController.kt | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt index 5ec69fc..d8cfac8 100644 --- a/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt +++ b/src/main/kotlin/org/mosad/thecitadelofricks/controller/StartupController.kt @@ -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")