2020-05-10 21:23:44 +02:00
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 ;
2020-05-10 22:19:58 +02:00
import org.hso.ecommerce.app.config.YAMLData.Address ;
2020-05-10 21:23:44 +02:00
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 " ) ;
2020-05-10 22:19:58 +02:00
data . setCompanyAddress ( new Address ( " Kupfergraben " , " 6 " , " 10117 " , " Berlin " , " Germany " ) ) ;
2020-05-10 21:23:44 +02:00
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 ( ) {
2020-05-10 22:19:58 +02:00
2020-05-10 21:23:44 +02:00
Yaml yaml = new Yaml ( new Constructor ( YAMLData . class ) ) ;
2020-05-10 22:19:58 +02:00
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 ( ) ;
}
2020-05-10 21:23:44 +02:00
}
}