From ea0c8c45d6c6f4a8997195f42b710060c99158ac Mon Sep 17 00:00:00 2001 From: Seil0 Date: Thu, 18 Jun 2020 14:04:54 +0200 Subject: [PATCH] rename eCommerce_config.yml to config.yml * if no config file is present, create a default config file --- prototype/config.yml | 21 +++++++ prototype/eCommerce_config.yml | 21 ------- .../hso/ecommerce/app/config/AppSettings.java | 55 ++++++++++--------- 3 files changed, 51 insertions(+), 46 deletions(-) create mode 100644 prototype/config.yml delete mode 100644 prototype/eCommerce_config.yml diff --git a/prototype/config.yml b/prototype/config.yml new file mode 100644 index 0000000..5012f67 --- /dev/null +++ b/prototype/config.yml @@ -0,0 +1,21 @@ +!!org.hso.ecommerce.app.config.YAMLData +companyAddress: {cityName: Musterstadt, countryName: Germany, houseNumber: '1', streetName: Musterstraße, + zipCode: '12345'} +companyName: eCommerce Shop UG +installationName: eCommerce +numberOfStorageSpaces: 128 +parcelServiceApiURL: http://[::1]:8082/ +parcelServiceName: Parcel Service +suppliers: +- apiURL: http://[::1]:8081/bank/ + companyAddress: {cityName: Musterstadt, countryName: Germany, houseNumber: '2', + streetName: Musterstraße, zipCode: '12345'} + deliveryTime: 4 + id: d41d8cd98f00b204e9800998ecf8427e + name: Bank of Chees +- apiURL: http://[::1]:8081/mda/ + companyAddress: {cityName: Musterstadt, countryName: Germany, houseNumber: '3', + streetName: Musterstraße, zipCode: '12345'} + deliveryTime: 5 + id: 18a17da5bac1cf00551b08c3e98720f5 + name: MDA diff --git a/prototype/eCommerce_config.yml b/prototype/eCommerce_config.yml deleted file mode 100644 index c46e0cc..0000000 --- a/prototype/eCommerce_config.yml +++ /dev/null @@ -1,21 +0,0 @@ -!!org.hso.ecommerce.app.config.YAMLData -companyAddress: {cityName: Berlin, countryName: Germany, houseNumber: '6', streetName: Kupfergraben, - zipCode: '10117'} -companyName: newCommerce GmbH -installationName: Fast-Web-Shop -numberOfStorageSpaces: 128 -parcelServiceApiURL: https://dhl.api.ecommerce.mosad.xyz -parcelServiceName: DHL International GmbH -suppliers: -- apiURL: https://reichelt.api.ecommerce.mosad.xyz - companyAddress: {cityName: Sande, countryName: Germany, houseNumber: '1', streetName: Elektronikring, - zipCode: '26452'} - deliveryTime: 4 - id: d41d8cd98f00b204e9800998ecf8427e - name: Reichelt elektronik GmbH & Co. KG -- apiURL: https://conrad.api.ecommerce.mosad.xyz - companyAddress: {cityName: Hirschau, countryName: Germany, houseNumber: '1', streetName: Klaus-Conrad-Straße, - zipCode: '92240'} - deliveryTime: 5 - id: 18a17da5bac1cf00551b08c3e98720f5 - name: Conrad Electronic SE 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 552a13c..625ed65 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,7 +15,7 @@ import javax.annotation.PostConstruct; public class AppSettings { private YAMLData data; - private final String configFile = "eCommerce_config.yml"; + private final String configFile = "config.yml"; private String installationName; private String companyName; @@ -24,11 +24,11 @@ public class AppSettings { private List suppliers; private String parcelServiceName; private String parcelServiceApiURL; - - @PostConstruct + /** * on initialization read the config and store the data in static objects */ + @PostConstruct public void init() { data = readConfig(); @@ -44,52 +44,52 @@ public class AppSettings { } /** - * write a demo config file + * write the default config file */ - public void writeDemoConfig() { + public void writeDefaultConfig() { YAMLData data = new YAMLData(); - data.setInstallationName("Fast-Web-Shop"); - data.setCompanyName("newCommerce GmbH"); + data.setInstallationName("eCommerce"); + data.setCompanyName("eCommerce Shop UG"); data.setCompanyAddress(new Address( - "Kupfergraben", - "6", - "10117", - "Berlin", + "Musterstraße", + "1", + "12345", + "Musterstadt", "Germany" )); data.setNumberOfStorageSpaces(128); List suppliers = new ArrayList<>(); suppliers.add(new YAMLData.Supplier( - "Reichelt elektronik GmbH & Co. KG", + "Bank of Chees", "d41d8cd98f00b204e9800998ecf8427e", - "https://reichelt.api.ecommerce.mosad.xyz", + "http://[::1]:8081/bank/", 4, new Address( - "Elektronikring", - "1", - "26452", - "Sande", + "Musterstraße", + "2", + "12345", + "Musterstadt", "Germany" ) )); suppliers.add(new YAMLData.Supplier( - "Conrad Electronic SE", + "MDA", "18a17da5bac1cf00551b08c3e98720f5", - "https://conrad.api.ecommerce.mosad.xyz", + "http://[::1]:8081/mda/", 5, new Address( - "Klaus-Conrad-Straße", - "1", - "92240", - "Hirschau", + "Musterstraße", + "3", + "12345", + "Musterstadt", "Germany" ) )); data.setSuppliers(suppliers); - data.setParcelServiceName("DHL International GmbH"); - data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz"); + data.setParcelServiceName("Parcel Service"); + data.setParcelServiceApiURL("http://[::1]:8082/"); try (FileWriter writer = new FileWriter("./" + configFile)) { Yaml yaml = new Yaml(); @@ -107,6 +107,11 @@ public class AppSettings { public YAMLData readConfig() { YAMLData data = new YAMLData(); + File file = new File("./" + configFile); + if (!file.exists()) { + writeDefaultConfig(); + } + try (InputStream inputStream = new FileInputStream("./" + configFile)) { Yaml yaml = new Yaml(new Constructor(YAMLData.class)); data = yaml.load(inputStream);