fix ApplicationSettings.readConfig()
This commit is contained in:
parent
d121532fba
commit
e1c00eca8f
|
@ -1,13 +1,11 @@
|
||||||
package org.hso.ecommerce.app;
|
package org.hso.ecommerce.app;
|
||||||
|
|
||||||
import org.hso.ecommerce.app.config.AppSettings;
|
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
import org.springframework.boot.autoconfigure.domain.EntityScan;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@ComponentScan(basePackages = {"org.hso.ecommerce"})
|
@ComponentScan(basePackages = {"org.hso.ecommerce"})
|
||||||
@EntityScan("org.hso.ecommerce")
|
@EntityScan("org.hso.ecommerce")
|
||||||
|
@ -15,14 +13,7 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||||
public class Application {
|
public class Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
AppSettings appSettings = AppSettings.getInstance(); // This does not belongs here
|
|
||||||
|
|
||||||
appSettings.writeDemoConfig();
|
|
||||||
|
|
||||||
appSettings.readConfig(); // This does not belongs here either
|
|
||||||
|
|
||||||
//SpringApplication.run(Application.class, args);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
package org.hso.ecommerce.app;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.app.config.AppSettings;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class InitController {
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void init() {
|
||||||
|
System.out.println("Initialize!");
|
||||||
|
|
||||||
|
|
||||||
|
AppSettings appSettings = AppSettings.getInstance();
|
||||||
|
//appSettings.writeDemoConfig();
|
||||||
|
appSettings.readConfig();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,90 +1,77 @@
|
||||||
package org.hso.ecommerce.app.config;
|
package org.hso.ecommerce.app.config;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.*;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.FileWriter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.hso.ecommerce.app.config.YAMLData.Address;
|
import org.hso.ecommerce.app.config.YAMLData.Address;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
import org.yaml.snakeyaml.constructor.Constructor;
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
|
|
||||||
|
@Component
|
||||||
public class AppSettings {
|
public class AppSettings {
|
||||||
private static AppSettings conf;
|
private static AppSettings instance;
|
||||||
|
|
||||||
private AppSettings() {
|
private AppSettings() {
|
||||||
|
// constructor
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AppSettings getInstance() {
|
public static AppSettings getInstance() {
|
||||||
if (AppSettings.conf == null) {
|
if (instance == null) {
|
||||||
AppSettings.conf = new AppSettings();
|
instance = new AppSettings();
|
||||||
}
|
}
|
||||||
return AppSettings.conf;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeDemoConfig() {
|
public void writeDemoConfig() {
|
||||||
|
|
||||||
Yaml yaml = new Yaml();
|
|
||||||
|
|
||||||
YAMLData data = new YAMLData();
|
YAMLData data = new YAMLData();
|
||||||
|
|
||||||
data.setInstallationName("Fast-Web-Shop");
|
data.setInstallationName("Fast-Web-Shop");
|
||||||
data.setCompanyName("newCommerce GmbH");
|
data.setCompanyName("newCommerce GmbH");
|
||||||
data.setCompanyAddress(new Address("Kupfergraben", "6", "10117", "Berlin", "Germany"));
|
data.setCompanyAddress(new Address(
|
||||||
|
"Kupfergraben",
|
||||||
|
"6",
|
||||||
|
"10117",
|
||||||
|
"Berlin",
|
||||||
|
"Germany"
|
||||||
|
));
|
||||||
data.setNumberOfStorageSpaces(128);
|
data.setNumberOfStorageSpaces(128);
|
||||||
|
|
||||||
/*
|
// List<YAMLData.Supplier> suppliers = new ArrayList<YAMLData.Supplier>();
|
||||||
|
// suppliers.add(new YAMLData.Supplier("Reichelt elektronik GmbH & Co. KG", "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
List<Supplier> suppliers = new ArrayList<Supplier>();
|
// "https://reichelt.api.ecommerce.mosad.xyz",
|
||||||
suppliers.add(new Supplier("Reichelt elektronik GmbH & Co. KG", "d41d8cd98f00b204e9800998ecf8427e",
|
// new Address("Elektronikring", "1", "26452", "Sande", "Germany"), 4));
|
||||||
"https://reichelt.api.ecommerce.mosad.xyz",
|
// suppliers.add(new YAMLData.Supplier("Conrad Electronic SE", "18a17da5bac1cf00551b08c3e98720f5",
|
||||||
new Address("Elektronikring", "1", "26452", "Sande", "Germany"), 4));
|
// "https://conrad.api.ecommerce.mosad.xyz",
|
||||||
suppliers.add(new Supplier("Conrad Electronic SE", "18a17da5bac1cf00551b08c3e98720f5",
|
// new Address("Klaus-Conrad-Straße", "1", "92240", "Hirschau", "Germany"), 5));
|
||||||
"https://conrad.api.ecommerce.mosad.xyz",
|
//
|
||||||
new Address("Klaus-Conrad-Straße", "1", "92240", "Hirschau", "Germany"), 5));
|
// data.setSuppliers(suppliers);
|
||||||
|
|
||||||
data.setSuppliers(suppliers);
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
data.setParcelServiceName("DHL International GmbH");
|
data.setParcelServiceName("DHL International GmbH");
|
||||||
data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz");
|
data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz");
|
||||||
|
|
||||||
FileWriter writer;
|
try (FileWriter writer = new FileWriter("./eCommerce_config.yml")) {
|
||||||
try {
|
Yaml yaml = new Yaml();
|
||||||
writer = new FileWriter("./eCommerce_config.yml");
|
|
||||||
yaml.dump(data, writer);
|
yaml.dump(data, writer);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readConfig() {
|
public YAMLData readConfig() {
|
||||||
|
YAMLData data = new YAMLData();
|
||||||
|
|
||||||
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
try (InputStream inputStream = new FileInputStream("./eCommerce_config.yml")) {
|
||||||
|
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
||||||
|
data = yaml.load(inputStream);
|
||||||
|
|
||||||
InputStream inputStream;
|
System.out.println(data.getCompanyName());
|
||||||
try {
|
} catch (IOException e) {
|
||||||
inputStream = new FileInputStream("./eCommerce_config.yml");
|
|
||||||
|
|
||||||
YAMLData data = yaml.load(inputStream);
|
|
||||||
|
|
||||||
System.out.println(data.getCompanyName());
|
|
||||||
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
package org.hso.ecommerce.app.config;
|
package org.hso.ecommerce.app.config;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
|
|
||||||
public class YAMLData {
|
public class YAMLData {
|
||||||
|
|
||||||
private String installationName;
|
private String installationName;
|
||||||
|
@ -26,14 +23,12 @@ public class YAMLData {
|
||||||
public void setCompanyName(String companyName) {
|
public void setCompanyName(String companyName) {
|
||||||
this.companyName = companyName;
|
this.companyName = companyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Address getCompanyAddress() {
|
public Address getCompanyAddress() {
|
||||||
return companyAddress;
|
return companyAddress;
|
||||||
}
|
}
|
||||||
public void setCompanyAddress(Address companyAddress) {
|
public void setCompanyAddress(Address companyAddress) {
|
||||||
this.companyAddress = companyAddress;
|
this.companyAddress = companyAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfStorageSpaces() {
|
public int getNumberOfStorageSpaces() {
|
||||||
return numberOfStorageSpaces;
|
return numberOfStorageSpaces;
|
||||||
}
|
}
|
||||||
|
@ -69,13 +64,57 @@ public class YAMLData {
|
||||||
public String cityName;
|
public String cityName;
|
||||||
public String countryName;
|
public String countryName;
|
||||||
|
|
||||||
public Address(String streetName, String houseNumer, String zipCode, String cityName, String countryName) {
|
public Address() {
|
||||||
|
// needed by snakeyaml
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address(String streetName, String houseNumber, String zipCode, String cityName, String countryName) {
|
||||||
this.streetName = streetName;
|
this.streetName = streetName;
|
||||||
this.houseNumber = houseNumer;
|
this.houseNumber = houseNumber;
|
||||||
this.zipCode = zipCode;
|
this.zipCode = zipCode;
|
||||||
this.cityName = cityName;
|
this.cityName = cityName;
|
||||||
this.countryName = countryName;
|
this.countryName = countryName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getStreetName() {
|
||||||
|
return streetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreetName(String streetName) {
|
||||||
|
this.streetName = streetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHouseNumber() {
|
||||||
|
return houseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHouseNumber(String houseNumber) {
|
||||||
|
this.houseNumber = houseNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getZipCode() {
|
||||||
|
return zipCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZipCode(String zipCode) {
|
||||||
|
this.zipCode = zipCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCityName() {
|
||||||
|
return cityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCityName(String cityName) {
|
||||||
|
this.cityName = cityName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCountryName() {
|
||||||
|
return countryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCountryName(String countryName) {
|
||||||
|
this.countryName = countryName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
public static class Supplier {
|
public static class Supplier {
|
||||||
|
@ -86,6 +125,10 @@ public class YAMLData {
|
||||||
public Address companyAddress;
|
public Address companyAddress;
|
||||||
public int deliveryTime;
|
public int deliveryTime;
|
||||||
|
|
||||||
|
public Supplier() {
|
||||||
|
// needed by snakeyaml
|
||||||
|
}
|
||||||
|
|
||||||
public Supplier(String name, String id, String apiURL, Address companyAddress, int deliveryTime) {
|
public Supplier(String name, String id, String apiURL, Address companyAddress, int deliveryTime) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
Reference in New Issue