better handling of non existing profiles
This commit is contained in:
parent
8c00e08574
commit
82f4c8ffac
1 changed files with 28 additions and 2 deletions
|
@ -26,7 +26,18 @@ public class NSProfile {
|
||||||
|
|
||||||
public NSProfile(JSONObject json, String activeProfile) {
|
public NSProfile(JSONObject json, String activeProfile) {
|
||||||
this.json = json;
|
this.json = json;
|
||||||
this.activeProfile = activeProfile;
|
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() {
|
public JSONObject getDefaultProfile() {
|
||||||
|
@ -346,7 +357,22 @@ public class NSProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getActiveProfile() {
|
public String getActiveProfile() {
|
||||||
return activeProfile;
|
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) {
|
public void setActiveProfile(String newProfile) {
|
||||||
|
|
Loading…
Reference in a new issue