From 8c0652b26b33334499145092933bef7742fa345e Mon Sep 17 00:00:00 2001 From: Seil0 Date: Wed, 17 Jun 2020 22:32:48 +0200 Subject: [PATCH] exit if the settings file has not been found * use a final variable for the settings file name --- .../java/org/hso/ecommerce/app/config/AppSettings.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/prototype/src/main/java/org/hso/ecommerce/app/config/AppSettings.java b/prototype/src/main/java/org/hso/ecommerce/app/config/AppSettings.java index fe02203..552a13c 100644 --- a/prototype/src/main/java/org/hso/ecommerce/app/config/AppSettings.java +++ b/prototype/src/main/java/org/hso/ecommerce/app/config/AppSettings.java @@ -15,6 +15,7 @@ import javax.annotation.PostConstruct; public class AppSettings { private YAMLData data; + private final String configFile = "eCommerce_config.yml"; private String installationName; private String companyName; @@ -90,7 +91,7 @@ public class AppSettings { data.setParcelServiceName("DHL International GmbH"); data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz"); - try (FileWriter writer = new FileWriter("./eCommerce_config.yml")) { + try (FileWriter writer = new FileWriter("./" + configFile)) { Yaml yaml = new Yaml(); yaml.dump(data, writer); } catch (IOException e) { @@ -106,14 +107,16 @@ public class AppSettings { public YAMLData readConfig() { YAMLData data = new YAMLData(); - try (InputStream inputStream = new FileInputStream("./eCommerce_config.yml")) { + try (InputStream inputStream = new FileInputStream("./" + configFile)) { Yaml yaml = new Yaml(new Constructor(YAMLData.class)); data = yaml.load(inputStream); } catch (FileNotFoundException e) { - System.err.println("The file \"eCommerce_config.yml\" has not been found, please create a valid Configuration file."); + System.err.println("The file \"" + configFile + "\" has not been found, please create a valid Configuration file."); e.printStackTrace(); + System.exit(1); } catch (IOException e) { e.printStackTrace(); + System.exit(1); } return data;