better handling of non existing profiles

This commit is contained in:
Milos Kozak 2016-12-10 18:14:12 +01:00
parent 8c00e08574
commit 82f4c8ffac

View file

@ -26,7 +26,18 @@ public class NSProfile {
public NSProfile(JSONObject json, String activeProfile) {
this.json = json;
this.activeProfile = null;
JSONObject store;
try {
store = json.getJSONObject("store");
if (activeProfile != null && store.has(activeProfile)) {
this.activeProfile = activeProfile;
} else {
log.error("Active profile not found in store");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public JSONObject getDefaultProfile() {
@ -346,7 +357,22 @@ public class NSProfile {
}
public String getActiveProfile() {
if (activeProfile != null)
return activeProfile;
else {
try {
JSONObject store = json.getJSONObject("store");
String defaultProfileName = (String) json.get("defaultProfile");
if (store.has(defaultProfileName)) {
return defaultProfileName;
}
log.error("Default profile not found");
return null;
} catch (JSONException e) {
e.printStackTrace();
}
}
return null;
}
public void setActiveProfile(String newProfile) {