added yaml dump&parse class
This commit is contained in:
parent
6ab3b63923
commit
e1d7becc2e
|
@ -28,6 +28,7 @@ dependencies {
|
||||||
implementation 'com.github.gwenn:sqlite-dialect:0.1.0'
|
implementation 'com.github.gwenn:sqlite-dialect:0.1.0'
|
||||||
implementation 'org.springframework.boot:spring-boot-devtools'
|
implementation 'org.springframework.boot:spring-boot-devtools'
|
||||||
implementation 'org.xerial:sqlite-jdbc:3.28.0'
|
implementation 'org.xerial:sqlite-jdbc:3.28.0'
|
||||||
|
implementation 'org.yaml:snakeyaml:1.26'
|
||||||
testCompile("org.springframework.boot:spring-boot-starter-test")
|
testCompile("org.springframework.boot:spring-boot-starter-test")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
!!org.hso.ecommerce.app.config.YAMLData {companyName: newCommerce GmbH, installationName: Fast-Web-Shop,
|
||||||
|
numberOfStorageSpaces: 128, parcelServiceApiURL: 'https://dhl.api.ecommerce.mosad.xyz',
|
||||||
|
parcelServiceName: DHL International GmbH}
|
|
@ -1,11 +1,13 @@
|
||||||
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")
|
||||||
|
@ -13,7 +15,17 @@ 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,89 @@
|
||||||
|
package org.hso.ecommerce.app.config;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
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.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.yaml.snakeyaml.Yaml;
|
||||||
|
import org.yaml.snakeyaml.constructor.Constructor;
|
||||||
|
|
||||||
|
public class AppSettings {
|
||||||
|
private static AppSettings conf;
|
||||||
|
|
||||||
|
private AppSettings() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AppSettings getInstance() {
|
||||||
|
if (AppSettings.conf == null) {
|
||||||
|
AppSettings.conf = new AppSettings();
|
||||||
|
}
|
||||||
|
return AppSettings.conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeDemoConfig() {
|
||||||
|
|
||||||
|
Yaml yaml = new Yaml();
|
||||||
|
|
||||||
|
YAMLData data = new YAMLData();
|
||||||
|
|
||||||
|
data.setInstallationName("Fast-Web-Shop");
|
||||||
|
data.setCompanyName("newCommerce GmbH");
|
||||||
|
//data.setCompanyAddress(new Address("Kupfergraben", "6", "10117", "Berlin", "Germany"));
|
||||||
|
data.setNumberOfStorageSpaces(128);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
List<Supplier> suppliers = new ArrayList<Supplier>();
|
||||||
|
suppliers.add(new Supplier("Reichelt elektronik GmbH & Co. KG", "d41d8cd98f00b204e9800998ecf8427e",
|
||||||
|
"https://reichelt.api.ecommerce.mosad.xyz",
|
||||||
|
new Address("Elektronikring", "1", "26452", "Sande", "Germany"), 4));
|
||||||
|
suppliers.add(new Supplier("Conrad Electronic SE", "18a17da5bac1cf00551b08c3e98720f5",
|
||||||
|
"https://conrad.api.ecommerce.mosad.xyz",
|
||||||
|
new Address("Klaus-Conrad-Straße", "1", "92240", "Hirschau", "Germany"), 5));
|
||||||
|
|
||||||
|
data.setSuppliers(suppliers);
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
data.setParcelServiceName("DHL International GmbH");
|
||||||
|
data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz");
|
||||||
|
|
||||||
|
FileWriter writer;
|
||||||
|
try {
|
||||||
|
writer = new FileWriter("./eCommerce_config.yml");
|
||||||
|
yaml.dump(data, writer);
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void readConfig() {
|
||||||
|
/*
|
||||||
|
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
||||||
|
InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("./eCommerce_config.yml");
|
||||||
|
YAMLData data = yaml.load(inputStream);
|
||||||
|
*/
|
||||||
|
String input = "!!org.hso.ecommerce.app.config.YAMLData {companyName: newCommerce GmbH, installationName: Fast-Web-Shop,\n" +
|
||||||
|
" numberOfStorageSpaces: 128, parcelServiceApiURL: 'https://dhl.api.ecommerce.mosad.xyz',\n" +
|
||||||
|
" parcelServiceName: DHL International GmbH}\n" +
|
||||||
|
"";
|
||||||
|
|
||||||
|
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
||||||
|
|
||||||
|
|
||||||
|
YAMLData data = yaml.load(input);
|
||||||
|
|
||||||
|
System.out.println(data.getCompanyName());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,99 @@
|
||||||
|
package org.hso.ecommerce.app.config;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class YAMLData {
|
||||||
|
|
||||||
|
private String installationName;
|
||||||
|
private String companyName;
|
||||||
|
//private Address companyAddress;
|
||||||
|
private int numberOfStorageSpaces;
|
||||||
|
//private List<Supplier> suppliers;
|
||||||
|
private String parcelServiceName;
|
||||||
|
private String parcelServiceApiURL;
|
||||||
|
|
||||||
|
|
||||||
|
public String getInstallationName() {
|
||||||
|
return installationName;
|
||||||
|
}
|
||||||
|
public void setInstallationName(String installationName) {
|
||||||
|
this.installationName = installationName;
|
||||||
|
}
|
||||||
|
public String getCompanyName() {
|
||||||
|
return companyName;
|
||||||
|
}
|
||||||
|
public void setCompanyName(String companyName) {
|
||||||
|
this.companyName = companyName;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public Address getCompanyAddress() {
|
||||||
|
return companyAddress;
|
||||||
|
}
|
||||||
|
public void setCompanyAddress(Address companyAddress) {
|
||||||
|
this.companyAddress = companyAddress;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public int getNumberOfStorageSpaces() {
|
||||||
|
return numberOfStorageSpaces;
|
||||||
|
}
|
||||||
|
public void setNumberOfStorageSpaces(int numberOfStorageSpaces) {
|
||||||
|
this.numberOfStorageSpaces = numberOfStorageSpaces;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public List<Supplier> getSuppliers() {
|
||||||
|
return suppliers;
|
||||||
|
}
|
||||||
|
public void setSuppliers(List<Supplier> suppliers) {
|
||||||
|
this.suppliers = suppliers;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
public String getParcelServiceName() {
|
||||||
|
return parcelServiceName;
|
||||||
|
}
|
||||||
|
public void setParcelServiceName(String parcelServiceName) {
|
||||||
|
this.parcelServiceName = parcelServiceName;
|
||||||
|
}
|
||||||
|
public String getParcelServiceApiURL() {
|
||||||
|
return parcelServiceApiURL;
|
||||||
|
}
|
||||||
|
public void setParcelServiceApiURL(String parcelServiceApiURL) {
|
||||||
|
this.parcelServiceApiURL = parcelServiceApiURL;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
public static class Address {
|
||||||
|
|
||||||
|
public String streetName;
|
||||||
|
public String houseNumber;
|
||||||
|
public String zipCode;
|
||||||
|
public String cityName;
|
||||||
|
public String countryName;
|
||||||
|
|
||||||
|
public Address(String streetName, String houseNumer, String zipCode, String cityName, String countryName) {
|
||||||
|
this.streetName = streetName;
|
||||||
|
this.houseNumber = houseNumer;
|
||||||
|
this.zipCode = zipCode;
|
||||||
|
this.cityName = cityName;
|
||||||
|
this.countryName = countryName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Supplier {
|
||||||
|
|
||||||
|
public String name;
|
||||||
|
public String id;
|
||||||
|
public String apiURL;
|
||||||
|
public Address companyAddress;
|
||||||
|
public int deliveryTime;
|
||||||
|
|
||||||
|
public Supplier(String name, String id, String apiURL, Address companyAddress, int deliveryTime) {
|
||||||
|
this.name = name;
|
||||||
|
this.id = id;
|
||||||
|
this.apiURL = apiURL;
|
||||||
|
this.companyAddress = companyAddress;
|
||||||
|
this.deliveryTime = deliveryTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
Reference in New Issue