This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/prototype/src/main/java/org/hso/ecommerce/app/config/AppSettings.java

90 lines
2.3 KiB
Java

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.hso.ecommerce.app.config.YAMLData.Address;
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;
try {
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();
}
}
}