rename eCommerce_config.yml to config.yml

* if no config file is present, create a default config file
This commit is contained in:
Jannik 2020-06-18 14:04:54 +02:00
parent 8c0652b26b
commit ea0c8c45d6
Signed by: Seil0
GPG Key ID: E8459F3723C52C24
3 changed files with 51 additions and 46 deletions

21
prototype/config.yml Normal file
View File

@ -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

View File

@ -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

View File

@ -15,7 +15,7 @@ import javax.annotation.PostConstruct;
public class AppSettings { public class AppSettings {
private YAMLData data; private YAMLData data;
private final String configFile = "eCommerce_config.yml"; private final String configFile = "config.yml";
private String installationName; private String installationName;
private String companyName; private String companyName;
@ -25,10 +25,10 @@ public class AppSettings {
private String parcelServiceName; private String parcelServiceName;
private String parcelServiceApiURL; private String parcelServiceApiURL;
@PostConstruct
/** /**
* on initialization read the config and store the data in static objects * on initialization read the config and store the data in static objects
*/ */
@PostConstruct
public void init() { public void init() {
data = readConfig(); 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(); YAMLData data = new YAMLData();
data.setInstallationName("Fast-Web-Shop"); data.setInstallationName("eCommerce");
data.setCompanyName("newCommerce GmbH"); data.setCompanyName("eCommerce Shop UG");
data.setCompanyAddress(new Address( data.setCompanyAddress(new Address(
"Kupfergraben", "Musterstraße",
"6", "1",
"10117", "12345",
"Berlin", "Musterstadt",
"Germany" "Germany"
)); ));
data.setNumberOfStorageSpaces(128); data.setNumberOfStorageSpaces(128);
List<YAMLData.Supplier> suppliers = new ArrayList<>(); List<YAMLData.Supplier> suppliers = new ArrayList<>();
suppliers.add(new YAMLData.Supplier( suppliers.add(new YAMLData.Supplier(
"Reichelt elektronik GmbH & Co. KG", "Bank of Chees",
"d41d8cd98f00b204e9800998ecf8427e", "d41d8cd98f00b204e9800998ecf8427e",
"https://reichelt.api.ecommerce.mosad.xyz", "http://[::1]:8081/bank/",
4, 4,
new Address( new Address(
"Elektronikring", "Musterstraße",
"1", "2",
"26452", "12345",
"Sande", "Musterstadt",
"Germany" "Germany"
) )
)); ));
suppliers.add(new YAMLData.Supplier( suppliers.add(new YAMLData.Supplier(
"Conrad Electronic SE", "MDA",
"18a17da5bac1cf00551b08c3e98720f5", "18a17da5bac1cf00551b08c3e98720f5",
"https://conrad.api.ecommerce.mosad.xyz", "http://[::1]:8081/mda/",
5, 5,
new Address( new Address(
"Klaus-Conrad-Straße", "Musterstraße",
"1", "3",
"92240", "12345",
"Hirschau", "Musterstadt",
"Germany" "Germany"
) )
)); ));
data.setSuppliers(suppliers); data.setSuppliers(suppliers);
data.setParcelServiceName("DHL International GmbH"); data.setParcelServiceName("Parcel Service");
data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz"); data.setParcelServiceApiURL("http://[::1]:8082/");
try (FileWriter writer = new FileWriter("./" + configFile)) { try (FileWriter writer = new FileWriter("./" + configFile)) {
Yaml yaml = new Yaml(); Yaml yaml = new Yaml();
@ -107,6 +107,11 @@ public class AppSettings {
public YAMLData readConfig() { public YAMLData readConfig() {
YAMLData data = new YAMLData(); YAMLData data = new YAMLData();
File file = new File("./" + configFile);
if (!file.exists()) {
writeDefaultConfig();
}
try (InputStream inputStream = new FileInputStream("./" + configFile)) { try (InputStream inputStream = new FileInputStream("./" + configFile)) {
Yaml yaml = new Yaml(new Constructor(YAMLData.class)); Yaml yaml = new Yaml(new Constructor(YAMLData.class));
data = yaml.load(inputStream); data = yaml.load(inputStream);