exit if the settings file has not been found
* use a final variable for the settings file name
This commit is contained in:
		@ -15,6 +15,7 @@ import javax.annotation.PostConstruct;
 | 
			
		||||
public class AppSettings {
 | 
			
		||||
 | 
			
		||||
	private YAMLData data;
 | 
			
		||||
	private final String configFile = "eCommerce_config.yml";
 | 
			
		||||
 | 
			
		||||
	private String installationName;
 | 
			
		||||
	private String companyName;
 | 
			
		||||
@ -90,7 +91,7 @@ public class AppSettings {
 | 
			
		||||
		data.setParcelServiceName("DHL International GmbH");
 | 
			
		||||
		data.setParcelServiceApiURL("https://dhl.api.ecommerce.mosad.xyz");
 | 
			
		||||
 | 
			
		||||
		try (FileWriter writer = new FileWriter("./eCommerce_config.yml")) {
 | 
			
		||||
		try (FileWriter writer = new FileWriter("./" + configFile)) {
 | 
			
		||||
			Yaml yaml = new Yaml();
 | 
			
		||||
			yaml.dump(data, writer);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
@ -106,14 +107,16 @@ public class AppSettings {
 | 
			
		||||
	public YAMLData readConfig() {
 | 
			
		||||
		YAMLData data = new YAMLData();
 | 
			
		||||
 | 
			
		||||
		try (InputStream inputStream = new FileInputStream("./eCommerce_config.yml")) {
 | 
			
		||||
		try (InputStream inputStream = new FileInputStream("./" + configFile)) {
 | 
			
		||||
			Yaml yaml = new Yaml(new Constructor(YAMLData.class));
 | 
			
		||||
			data = yaml.load(inputStream);
 | 
			
		||||
		} catch (FileNotFoundException e) {
 | 
			
		||||
			System.err.println("The file \"eCommerce_config.yml\" has not been found, please create a valid Configuration file.");
 | 
			
		||||
			System.err.println("The file \"" + configFile + "\" has not been found, please create a valid Configuration file.");
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			System.exit(1);
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
			System.exit(1);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return data;
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user