feature/config #78
@ -6,3 +6,16 @@ installationName: Fast-Web-Shop
|
|||||||
numberOfStorageSpaces: 128
|
numberOfStorageSpaces: 128
|
||||||
parcelServiceApiURL: https://dhl.api.ecommerce.mosad.xyz
|
parcelServiceApiURL: https://dhl.api.ecommerce.mosad.xyz
|
||||||
parcelServiceName: DHL International GmbH
|
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
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
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();
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
@ -9,21 +9,42 @@ 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;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class AppSettings {
|
public class AppSettings {
|
||||||
private static AppSettings instance;
|
|
||||||
|
|
||||||
private AppSettings() {
|
private static YAMLData data;
|
||||||
// constructor
|
|
||||||
}
|
private static String installationName;
|
||||||
|
private static String companyName;
|
||||||
public static AppSettings getInstance() {
|
private static Address companyAddress;
|
||||||
if (instance == null) {
|
private static int numberOfStorageSpaces;
|
||||||
instance = new AppSettings();
|
private static List<YAMLData.Supplier> suppliers;
|
||||||
}
|
private static String parcelServiceName;
|
||||||
return instance;
|
private static String parcelServiceApiURL;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
/**
|
||||||
|
* on initialization read the config and store the data in static objects
|
||||||
|
*/
|
||||||
|
public void init() {
|
||||||
|
data = readConfig();
|
||||||
|
|
||||||
|
installationName = data.getInstallationName();
|
||||||
|
companyName = data.getCompanyName();
|
||||||
|
companyAddress = data.getCompanyAddress();
|
||||||
|
numberOfStorageSpaces = data.getNumberOfStorageSpaces();
|
||||||
|
suppliers = data.getSuppliers();
|
||||||
|
parcelServiceName = data.getParcelServiceName();
|
||||||
|
parcelServiceApiURL = data.getParcelServiceApiURL();
|
||||||
|
|
||||||
|
System.out.println("Initialised Settings!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* write a demo config file
|
||||||
|
*/
|
||||||
public void writeDemoConfig() {
|
public void writeDemoConfig() {
|
||||||
YAMLData data = new YAMLData();
|
YAMLData data = new YAMLData();
|
||||||
data.setInstallationName("Fast-Web-Shop");
|
data.setInstallationName("Fast-Web-Shop");
|
||||||
@ -37,15 +58,34 @@ public class AppSettings {
|
|||||||
));
|
));
|
||||||
data.setNumberOfStorageSpaces(128);
|
data.setNumberOfStorageSpaces(128);
|
||||||
|
|
||||||
// List<YAMLData.Supplier> suppliers = new ArrayList<YAMLData.Supplier>();
|
List<YAMLData.Supplier> suppliers = new ArrayList<>();
|
||||||
// suppliers.add(new YAMLData.Supplier("Reichelt elektronik GmbH & Co. KG", "d41d8cd98f00b204e9800998ecf8427e",
|
suppliers.add(new YAMLData.Supplier(
|
||||||
// "https://reichelt.api.ecommerce.mosad.xyz",
|
"Reichelt elektronik GmbH & Co. KG",
|
||||||
// new Address("Elektronikring", "1", "26452", "Sande", "Germany"), 4));
|
"d41d8cd98f00b204e9800998ecf8427e",
|
||||||
// suppliers.add(new YAMLData.Supplier("Conrad Electronic SE", "18a17da5bac1cf00551b08c3e98720f5",
|
"https://reichelt.api.ecommerce.mosad.xyz",
|
||||||
// "https://conrad.api.ecommerce.mosad.xyz",
|
4,
|
||||||
// new Address("Klaus-Conrad-Straße", "1", "92240", "Hirschau", "Germany"), 5));
|
new Address(
|
||||||
//
|
"Elektronikring",
|
||||||
// data.setSuppliers(suppliers);
|
"1",
|
||||||
|
"26452",
|
||||||
|
"Sande",
|
||||||
|
"Germany"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
suppliers.add(new YAMLData.Supplier(
|
||||||
|
"Conrad Electronic SE",
|
||||||
|
"18a17da5bac1cf00551b08c3e98720f5",
|
||||||
|
"https://conrad.api.ecommerce.mosad.xyz",
|
||||||
|
5,
|
||||||
|
new Address(
|
||||||
|
"Klaus-Conrad-Straße",
|
||||||
|
"1",
|
||||||
|
"92240",
|
||||||
|
"Hirschau",
|
||||||
|
"Germany"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
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");
|
||||||
@ -59,14 +99,19 @@ public class AppSettings {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* read a config file named "eCommerce_config.yml" from the applications root directory
|
||||||
|
* @return the settings as YAMLData object
|
||||||
|
*/
|
||||||
public YAMLData readConfig() {
|
public YAMLData readConfig() {
|
||||||
YAMLData data = new YAMLData();
|
YAMLData data = new YAMLData();
|
||||||
|
|
||||||
try (InputStream inputStream = new FileInputStream("./eCommerce_config.yml")) {
|
try (InputStream inputStream = new FileInputStream("./eCommerce_config.yml")) {
|
||||||
|
|||||||
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
Yaml yaml = new Yaml(new Constructor(YAMLData.class));
|
||||||
data = yaml.load(inputStream);
|
data = yaml.load(inputStream);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println(data.getCompanyName());
|
System.err.println("The file \"eCommerce_config.yml\" has not been found, please create a valid Configuration file.");
|
||||||
|
e.printStackTrace();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -74,4 +119,35 @@ public class AppSettings {
|
|||||||
return data;
|
return data;
|
||||||
CodeSteak
commented
Führt nach im catch(...) Fall evtl zu null pointer deref. Vlcht im catch leere werte setzen oder app beenden. Führt nach im catch(...) Fall evtl zu null pointer deref. Vlcht im catch leere werte setzen oder app beenden.
Seil0
commented
Wollen wir mit leeren Werten starten oder beenden? Ich hab jetzt mal ein Wollen wir mit leeren Werten starten oder beenden? Ich hab jetzt mal ein `System.exit()` eingebaut.
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
public static YAMLData getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getInstallationName() {
|
||||||
CodeSteak
commented
In den Getter ist nicht sichergestellt, dass die werte schon initialisiert sind. Andere Komponenten könnten schon vorher PostConstruct ausgeführt haben. In den Getter ist nicht sichergestellt, dass die werte schon initialisiert sind. Andere Komponenten könnten schon vorher PostConstruct ausgeführt haben.
|
|||||||
|
return installationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getCompanyName() {
|
||||||
|
return companyName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Address getCompanyAddress() {
|
||||||
|
return companyAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getNumberOfStorageSpaces() {
|
||||||
|
return numberOfStorageSpaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<YAMLData.Supplier> getSuppliers() {
|
||||||
|
return suppliers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getParcelServiceName() {
|
||||||
|
return parcelServiceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getParcelServiceApiURL() {
|
||||||
|
return parcelServiceApiURL;
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,12 +1,14 @@
|
|||||||
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;
|
||||||
private String companyName;
|
private String companyName;
|
||||||
private Address companyAddress;
|
private Address companyAddress;
|
||||||
private int numberOfStorageSpaces;
|
private int numberOfStorageSpaces;
|
||||||
//private List<Supplier> suppliers;
|
private List<Supplier> suppliers;
|
||||||
private String parcelServiceName;
|
private String parcelServiceName;
|
||||||
private String parcelServiceApiURL;
|
private String parcelServiceApiURL;
|
||||||
|
|
||||||
@ -35,14 +37,12 @@ public class YAMLData {
|
|||||||
public void setNumberOfStorageSpaces(int numberOfStorageSpaces) {
|
public void setNumberOfStorageSpaces(int numberOfStorageSpaces) {
|
||||||
this.numberOfStorageSpaces = numberOfStorageSpaces;
|
this.numberOfStorageSpaces = numberOfStorageSpaces;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public List<Supplier> getSuppliers() {
|
public List<Supplier> getSuppliers() {
|
||||||
return suppliers;
|
return suppliers;
|
||||||
}
|
}
|
||||||
public void setSuppliers(List<Supplier> suppliers) {
|
public void setSuppliers(List<Supplier> suppliers) {
|
||||||
this.suppliers = suppliers;
|
this.suppliers = suppliers;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
public String getParcelServiceName() {
|
public String getParcelServiceName() {
|
||||||
return parcelServiceName;
|
return parcelServiceName;
|
||||||
}
|
}
|
||||||
@ -116,27 +116,68 @@ public class YAMLData {
|
|||||||
this.countryName = countryName;
|
this.countryName = countryName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
public static class Supplier {
|
public static class Supplier {
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
public String id;
|
public String id;
|
||||||
public String apiURL;
|
public String apiURL;
|
||||||
public Address companyAddress;
|
|
||||||
public int deliveryTime;
|
public int deliveryTime;
|
||||||
|
public Address companyAddress;
|
||||||
|
|
||||||
|
|
||||||
public Supplier() {
|
public Supplier() {
|
||||||
// needed by snakeyaml
|
// needed by snakeyaml
|
||||||
}
|
}
|
||||||
|
|
||||||
public Supplier(String name, String id, String apiURL, Address companyAddress, int deliveryTime) {
|
public Supplier(String name, String id, String apiURL, int deliveryTime, Address companyAddress) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.apiURL = apiURL;
|
this.apiURL = apiURL;
|
||||||
|
this.deliveryTime = deliveryTime;
|
||||||
this.companyAddress = companyAddress;
|
this.companyAddress = companyAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApiURL() {
|
||||||
|
return apiURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiURL(String apiURL) {
|
||||||
|
this.apiURL = apiURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDeliveryTime() {
|
||||||
|
return deliveryTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeliveryTime(int deliveryTime) {
|
||||||
this.deliveryTime = deliveryTime;
|
this.deliveryTime = deliveryTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Address getCompanyAddress() {
|
||||||
|
return companyAddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompanyAddress(Address companyAddress) {
|
||||||
|
this.companyAddress = companyAddress;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.hso.ecommerce.components;
|
package org.hso.ecommerce.components;
|
||||||
|
|
||||||
|
import org.hso.ecommerce.app.config.AppSettings;
|
||||||
import org.hso.ecommerce.entities.warehouse.Slot;
|
import org.hso.ecommerce.entities.warehouse.Slot;
|
||||||
import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
import org.hso.ecommerce.repos.warehouse.SlotRepository;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -13,8 +14,7 @@ public class SlotInitializer {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private final SlotRepository slotRepository = null;
|
private final SlotRepository slotRepository = null;
|
||||||
|
|
||||||
// TODO: use values form cfg.
|
private final int NUM_SLOTS = AppSettings.getNumberOfStorageSpaces();
|
||||||
CodeSteak
commented
Muss in init() eingelesen werden wegen obigen Problem Muss in init() eingelesen werden wegen obigen Problem
|
|||||||
private final int NUM_SLOTS = 50;
|
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void init() {
|
public void init() {
|
||||||
|
Vlcht besser als private/public static final String in der Klasse.
wollen wir wirklich "./eCommerce_config.yml" als Dateinamen? Hat merkwürdiges Caseing (underscore und Groß/klein-schreibung.).