Skip to content

Commit ac6f51c

Browse files
author
eznedan
committed
FIX: review comments and checkbox issue
1 parent ec07857 commit ac6f51c

File tree

9 files changed

+68
-37
lines changed

9 files changed

+68
-37
lines changed

src/main/java/com/ericsson/ei/frontend/BackEndInformationController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import javax.servlet.http.HttpServletRequest;
2626

2727
@RestController
28-
@RequestMapping
2928
public interface BackEndInformationController {
3029

3130
@RequestMapping(value = "/get-instances", method = RequestMethod.GET)

src/main/java/com/ericsson/ei/frontend/BackEndInformationControllerImpl.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ public ResponseEntity<String> deleteBackEndInstance(Model model, HttpServletRequ
6464
String body = request.getReader().lines().collect(Collectors.joining(System.lineSeparator()));
6565
utils.setInstances(new JSONArray(body));
6666
utils.writeIntoFile();
67-
utils.parseBackEndInstancesFile();
6867
return new ResponseEntity<>(HttpStatus.OK);
6968
} catch (Exception e) {
7069
return new ResponseEntity<>("Internal error", HttpStatus.INTERNAL_SERVER_ERROR);

src/main/java/com/ericsson/ei/frontend/EIRequestsController.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public ResponseEntity<String> getAuthRequests(Model model, HttpServletRequest re
8484
@RequestMapping(value = {"/subscriptions", "/subscriptions/*", "/information",
8585
"/download/subscriptiontemplate"}, method = RequestMethod.GET)
8686
public ResponseEntity<String> getRequests(Model model, HttpServletRequest request) {
87+
LOG.info("------------------------------------------>"+backEndInformation.getHost()+backEndInformation.getPort());
8788
String eiBackendAddressSuffix = request.getServletPath();
8889
String newRequestUrl = getEIBackendSubscriptionAddress() + eiBackendAddressSuffix;
8990
LOG.info("Got HTTP Request with method GET.\nUrlSuffix: " + eiBackendAddressSuffix

src/main/java/com/ericsson/ei/frontend/WebController.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,6 @@ public String login(Model model) {
9494
return "login";
9595
}
9696

97-
@RequestMapping("/register.html")
98-
public String register(Model model) {
99-
return "register";
100-
}
101-
102-
@RequestMapping("/forgot-password.html")
103-
public String forgotPassword(Model model) {
104-
return "forgot-password";
105-
}
106-
10797
// Added documentation for JMESPath rules usage
10898
@RequestMapping("/jmesPathRulesSetUp.html")
10999
public String jmesPathRulesSetUp(Model model) {

src/main/java/com/ericsson/ei/frontend/model/BackEndInformation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package com.ericsson.ei.frontend.model;
1818

19-
import com.fasterxml.jackson.annotation.JsonIgnore;
2019
import com.fasterxml.jackson.annotation.JsonProperty;
2120
import lombok.*;
2221
import org.springframework.beans.factory.annotation.Value;
@@ -44,7 +43,9 @@ public class BackEndInformation {
4443

4544
@JsonProperty("port")
4645
@Value("${ei.backendServerPort}")
47-
@NotNull @Min(1) @Max(65535)
46+
@NotNull
47+
@Min(1)
48+
@Max(65535)
4849
private int port;
4950

5051
@JsonProperty("path")
@@ -55,6 +56,5 @@ public class BackEndInformation {
5556
@Value("${ei.useSecureHttp}")
5657
private boolean https;
5758

58-
@JsonIgnore
5959
private boolean checked;
6060
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
public class BackEndInstancesUtils {
4343

4444
private static final Logger LOG = LoggerFactory.getLogger(BackEndInstancesUtils.class);
45+
private static final String PATH = "src/main/resources/EIBackendInstancesExample.json";
4546

4647
@Value("${ei.backendServerHost}")
4748
private String host;
@@ -71,6 +72,9 @@ public void init() {
7172
instances.put(getCurrentInstance());
7273
}
7374
writeIntoFile();
75+
if (eiInstancesPath.equals("")) {
76+
setEiInstancesPath(PATH);
77+
}
7478
}
7579

7680
private JSONObject getCurrentInstance() {
@@ -118,13 +122,13 @@ public void writeIntoFile() {
118122
public void parseBackEndInstancesFile() {
119123
if (eiInstancesPath != null) {
120124
try {
125+
information.clear();
126+
instances = new JSONArray();
121127
JSONArray inputBackEndInstances = new JSONArray(new String(Files.readAllBytes(Paths.get(eiInstancesPath))));
122128
for (Object o : inputBackEndInstances) {
123129
JSONObject instance = (JSONObject) o;
124-
if (!checkIfInstanceAlreadyExist(instance)) {
125-
information.add(new ObjectMapper().readValue(instance.toString(), BackEndInformation.class));
126-
instances.put(instance);
127-
}
130+
information.add(new ObjectMapper().readValue(instance.toString(), BackEndInformation.class));
131+
instances.put(instance);
128132
}
129133
} catch (IOException e) {
130134
LOG.error("Failure when try to parse json file" + e.getMessage());
Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,26 @@
1-
[{"path":"","port":8091,"name":"core","host":"localhost","checked":false,"https":false},{"path":"/eiffel","port":8080,"name":"test","host":"localhost23","checked":true,"https":false}]
1+
[
2+
{
3+
"path": "",
4+
"port": 8090,
5+
"name": "core",
6+
"host": "localhost",
7+
"checked": false,
8+
"https": false
9+
},
10+
{
11+
"path": "",
12+
"port": "8091",
13+
"name": "test",
14+
"host": "localhost",
15+
"checked": false,
16+
"https": false
17+
},
18+
{
19+
"path": "/eiffel",
20+
"port": "8091",
21+
"name": "source",
22+
"host": "localhost",
23+
"checked": false,
24+
"https": false
25+
}
26+
]

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function instanceModel() {
3131
}
3232
}
3333
}
34-
var observableObject = $("#instanceModel")[0];
35-
ko.cleanNode(observableObject);
36-
ko.applyBindings(new instanceModel(), observableObject);
34+
var observableObject = $("#instanceModel")[0];
35+
ko.cleanNode(observableObject);
36+
ko.applyBindings(new instanceModel(), observableObject);
3737
});

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,35 @@ function multipleInstancesModel(data) {
3434
});
3535
}
3636
self.submit = function(instances) {
37-
$.ajax({
38-
url: "/switch-backend",
39-
type: "POST",
40-
data: ko.toJSON(instances),
41-
contentType: 'application/json; charset=utf-8',
42-
cache: false,
43-
error: function (XMLHttpRequest, textStatus, errorThrown) {
44-
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
45-
},
46-
success: function (responseData, textStatus) {
47-
$.jGrowl("Backend instance was switched", {sticky: false, theme: 'Notify'});
48-
$("#mainFrame").load("subscriptionpage.html");
49-
}
37+
var count = 0;
38+
var json = JSON.parse(ko.toJSON(instances));
39+
console.log(json);
40+
for(var i = 0; i < json.length; i++){
41+
var obj = json[i];
42+
if(obj.checked == true){
43+
count++;
44+
}
45+
}
46+
if(count == 1){
47+
$.ajax({
48+
url: "/switch-backend",
49+
type: "POST",
50+
data: ko.toJSON(instances),
51+
contentType: 'application/json; charset=utf-8',
52+
cache: false,
53+
error: function (XMLHttpRequest, textStatus, errorThrown) {
54+
$.jGrowl(XMLHttpRequest.responseText, {sticky: false, theme: 'Error'});
55+
},
56+
success: function (responseData, textStatus) {
57+
$.jGrowl("Backend instance was switched", {sticky: false, theme: 'Notify'});
58+
$("#mainFrame").load("subscriptionpage.html");
59+
}
5060
});
51-
}
61+
} else {
62+
$.jGrowl("Please choose one backend instance", {sticky: false, theme: 'Error'});
63+
}
5264
}
65+
}
5366
$.ajax({
5467
url: "/get-instances",
5568
type: "GET",

0 commit comments

Comments
 (0)