Skip to content

Commit dc774a0

Browse files
author
eznedan
committed
formatted
1 parent 4c8338a commit dc774a0

File tree

2 files changed

+46
-41
lines changed

2 files changed

+46
-41
lines changed

src/main/java/com/ericsson/ei/frontend/utils/BackEndInstancesUtils.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@
4444
public class BackEndInstancesUtils {
4545

4646
private static final Logger LOG = LoggerFactory.getLogger(BackEndInstancesUtils.class);
47-
private static final String PATH = "src/main/resources/EIBackendInstancesInformation.json";
47+
private static final String PATH_TO_WRITE = "src/main/resources/EIBackendInstancesInformation.json";
48+
private static final String NAME = "name";
49+
private static final String HOST = "host";
50+
private static final String PORT = "port";
51+
private static final String PATH = "path";
52+
private static final String HTTPS = "https";
53+
private static final String ACTIVE = "active";
4854

4955
@Value("${ei.backendServerHost}")
5056
private String host;
@@ -74,19 +80,19 @@ public void init() {
7480
instances.add(getCurrentInstance());
7581
}
7682
if (eiInstancesPath.equals("")) {
77-
setEiInstancesPath(PATH);
83+
setEiInstancesPath(PATH_TO_WRITE);
7884
}
7985
writeIntoFile();
8086
}
8187

8288
private JsonObject getCurrentInstance() {
8389
JsonObject instance = new JsonObject();
84-
instance.addProperty("name", "core");
85-
instance.addProperty("host", host);
86-
instance.addProperty("port", port);
87-
instance.addProperty("path", path);
88-
instance.addProperty("https", https);
89-
instance.addProperty("active", true);
90+
instance.addProperty(NAME, "core");
91+
instance.addProperty(HOST, host);
92+
instance.addProperty(PORT, port);
93+
instance.addProperty(PATH, path);
94+
instance.addProperty(HTTPS, https);
95+
instance.addProperty(ACTIVE, true);
9096
return instance;
9197
}
9298

@@ -100,9 +106,9 @@ public void setBackEndProperties(BackEndInformation properties) {
100106

101107
public boolean checkIfInstanceAlreadyExist(JsonObject instance) {
102108
for (JsonElement element : instances) {
103-
if (element.getAsJsonObject().get("host").equals(instance.get("host")) &&
104-
element.getAsJsonObject().get("port").equals(instance.get("port")) &&
105-
element.getAsJsonObject().get("path").equals(instance.get("path"))) {
109+
if (element.getAsJsonObject().get(HOST).equals(instance.get(HOST)) &&
110+
element.getAsJsonObject().get(PORT).equals(instance.get(PORT)) &&
111+
element.getAsJsonObject().get(PATH).equals(instance.get(PATH))) {
106112
return true;
107113
}
108114
}

src/main/resources/static/js/switch-instances.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ function multipleInstancesModel(data) {
1818
}
1919
self.removeInstance = function() {
2020
self.instances.remove(this);
21-
$.ajax({
22-
url: "/switch-backend",
23-
type: "DELETE",
24-
data: ko.toJSON(self.instances),
25-
contentType: 'application/json; charset=utf-8',
26-
cache: false,
27-
error: function (XMLHttpRequest, textStatus, errorThrown) {
28-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
29-
},
30-
success: function (responseData, textStatus) {
31-
$.jGrowl("Backend instance was deleted", {sticky: false, theme: 'Notify'});
32-
$("#mainFrame").load("switch-backend.html");
33-
}
34-
});
21+
$.ajax({
22+
url: "/switch-backend",
23+
type: "DELETE",
24+
data: ko.toJSON(self.instances),
25+
contentType: 'application/json; charset=utf-8',
26+
cache: false,
27+
error: function (XMLHttpRequest, textStatus, errorThrown) {
28+
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
29+
},
30+
success: function (responseData, textStatus) {
31+
$.jGrowl("Backend instance was deleted", {sticky: false, theme: 'Notify'});
32+
$("#mainFrame").load("switch-backend.html");
33+
}
34+
});
3535
}
3636
self.submit = function(instances) {
3737
var count = 0;
@@ -59,22 +59,21 @@ function multipleInstancesModel(data) {
5959
});
6060
} else {
6161
$.jGrowl("Please choose one backend instance", {sticky: false, theme: 'Error'});
62-
}
62+
}
6363
}
6464
}
65-
$.ajax({
66-
url: "/get-instances",
67-
type: "GET",
68-
contentType: 'application/json; charset=utf-8',
69-
cache: false,
70-
error: function (XMLHttpRequest, textStatus, errorThrown) {
71-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
72-
},
73-
success: function (responseData, textStatus) {
74-
var observableObject = $("#instancesModel")[0];
75-
ko.cleanNode(observableObject);
76-
ko.applyBindings(new multipleInstancesModel(responseData), observableObject);
77-
78-
}
79-
})
65+
$.ajax({
66+
url: "/get-instances",
67+
type: "GET",
68+
contentType: 'application/json; charset=utf-8',
69+
cache: false,
70+
error: function (XMLHttpRequest, textStatus, errorThrown) {
71+
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
72+
},
73+
success: function (responseData, textStatus) {
74+
var observableObject = $("#instancesModel")[0];
75+
ko.cleanNode(observableObject);
76+
ko.applyBindings(new multipleInstancesModel(responseData), observableObject);
77+
}
78+
})
8079
});

0 commit comments

Comments
 (0)