Skip to content

Commit e4135e2

Browse files
author
Anders Breid
authored
Primary version fetched from pom not application.properties
Improvements: * Now fetches version and application name from pom.xml * New default-application.properties contains properties that should not be changed after release. * build.version property in application.properties may be set but should be empty by default, will render an extra version after the primary version within () Minor fixes to responses when adding back-end instances.
1 parent 9692deb commit e4135e2

File tree

10 files changed

+98
-73
lines changed

10 files changed

+98
-73
lines changed

pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,22 @@
133133
</dependencies>
134134

135135
<build>
136+
<resources>
137+
<resource>
138+
<directory>src/main/resources</directory>
139+
<filtering>true</filtering>
140+
<includes>
141+
<include>**/default-application.properties</include>
142+
</includes>
143+
</resource>
144+
<resource>
145+
<directory>src/main/resources</directory>
146+
<filtering>false</filtering>
147+
<excludes>
148+
<exclude>**/default-application.properties</exclude>
149+
</excludes>
150+
</resource>
151+
</resources>
136152
<plugins>
137153
<plugin>
138154
<groupId>org.springframework.boot</groupId>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public String testRules(Model model) {
5454
@RequestMapping("/eiInfo.html")
5555
public String eiInfo(Model model, HttpServletRequest request) {
5656
model.addAttribute("frontendServiceUrl", frontEndUtils.getFrontEndServiceUrl());
57-
model.addAttribute("frontendServiceVersion", frontEndUtils.getVersion());
57+
model.addAttribute("version", frontEndUtils.getVersion());
58+
model.addAttribute("applicationPropertiesVersion", frontEndUtils.getApplicationPropertiesVersion());
5859
model.addAttribute("frontendAppName", frontEndUtils.getApplicationName());
5960
model.addAttribute("backendServerUrl", frontEndUtils.getBackEndServiceUrl(request.getSession()));
6061
return "eiInfo";

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import org.springframework.beans.factory.annotation.Value;
1515
import org.springframework.stereotype.Component;
1616

17-
import com.ericsson.ei.frontend.model.BackEndInformation;
1817
import com.google.gson.JsonArray;
1918
import com.google.gson.JsonElement;
2019
import com.google.gson.JsonObject;
@@ -57,7 +56,7 @@ public void init() throws IOException {
5756
if (!eiHomeExists) {
5857
createEiHomeFolder(eiHome);
5958
}
60-
59+
6160
Path eiInstancesListFilePath = Paths.get(eiHome, BACKEND_INSTANCES_DEFAULT_FILENAME);
6261
setEiInstancesPath(eiInstancesListFilePath.toString());
6362
File eiInstancesListFile = new File(eiInstancesListFilePath.toString());
@@ -94,7 +93,7 @@ public void init() throws IOException {
9493
/**
9594
* Parses Ei Instances list from backendInstancesListJsonContent property and
9695
* sets default EI-Backend instance.
97-
*
96+
*
9897
*/
9998
private void parseAndSetEiInstancesList() {
10099
JsonArray parsedBackendInstancesListJsonArray = null;
@@ -111,7 +110,7 @@ private void parseAndSetEiInstancesList() {
111110

112111
/**
113112
* Parses Ei Instances list from backendInstancesListJsonContent property.
114-
*
113+
*
115114
* @return JsonArray
116115
*/
117116
private JsonArray parseEiInstancesListJsonObject() {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.slf4j.Logger;
2424
import org.slf4j.LoggerFactory;
2525
import org.springframework.beans.factory.annotation.Autowired;
26-
import org.springframework.beans.factory.annotation.Value;
2726
import org.springframework.stereotype.Component;
2827

2928
import com.ericsson.ei.frontend.model.BackEndInformation;

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

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

19+
import java.io.IOException;
20+
import java.util.Properties;
21+
22+
import javax.annotation.PostConstruct;
1923
import javax.servlet.http.HttpSession;
2024

2125
import org.springframework.beans.factory.annotation.Autowired;
@@ -36,30 +40,39 @@
3640
@AllArgsConstructor
3741
public class WebControllerUtils {
3842

39-
@Value("${ei.frontendServiceHost}")
43+
@Value("${ei.frontendServiceHost:#{null}}")
4044
private String frontendServiceHost;
4145

42-
@Value("${ei.frontendServicePort}")
46+
@Value("${ei.frontendServicePort:#{null}}")
4347
private int frontendServicePort;
4448

45-
@Value("${ei.frontendContextPath}")
49+
@Value("${ei.frontendContextPath:#{null}}")
4650
private String frontendContextPath;
4751

48-
@Value("${ei.useSecureHttpFrontend}")
52+
@Value("${ei.useSecureHttpFrontend:#{null}}")
4953
private boolean useSecureHttpFrontend;
5054

51-
@Value("${ei.eiffelDocumentationUrls}")
55+
@Value("${ei.eiffelDocumentationUrls:#{null}}")
5256
private String eiffelDocumentationUrls;
5357

54-
@Value("${spring.application.name}")
55-
private String applicationName;
58+
@Value("${build.version:#{null}}")
59+
private String applicationPropertiesVersion;
5660

57-
@Value("${build.version}")
5861
private String version;
5962

63+
private String applicationName;
64+
6065
@Autowired
6166
private BackEndInstancesUtils backEndInstancesUtils;
6267

68+
@PostConstruct
69+
public void init() throws IOException {
70+
Properties properties = new Properties();
71+
properties.load(WebControllerUtils.class.getResourceAsStream("/default-application.properties"));
72+
version = properties.getProperty("version");
73+
applicationName = properties.getProperty("artifactId");
74+
}
75+
6376
/**
6477
* Formats the parameters in the class to an URL as String.
6578
*

src/main/resources/application.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# REST api returns json in pretty format with jackson
22
spring.jackson.default-property-inclusion=non_null
33

4-
spring.application.name=ei-frontend
5-
#${project.artifactId}
6-
build.version=@project.version@
4+
# An extra optional version tag, version will be added after github release version
5+
# Example if build.version=1.2.3-internal becomes Version 0.0.18 (1.2.3-internal)
6+
build.version=
77

88
server.port=8080
99
#server.ssl.key-store: <keystore.p12>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
artifactId=@project.artifactId@
2+
version=@project.version@

src/main/resources/static/js/eiInfo.js

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
jQuery(document).ready(function() {
22
// Fetch injected URL from DOM
3-
var frontendServiceUrl = $('#frontendServiceUrl').text();
4-
var backendServerUrl = $('#backendServerUrl').text();
3+
var frontEndServiceUrl = $('#frontendServiceUrl').text();
4+
var frontEndVersion = $('#frontEndVersion').text();
5+
var frontEndApplicationPropertiesVersion = $('#frontEndApplicationPropertiesVersion').text();
6+
var frontEndAppName = $('#frontendAppName').text();
7+
8+
var backEndServerUrl = $('#backendServerUrl').text();
59

610
var body = document.getElementById('eiPageFrame');
11+
var generalEIInfoLabel = "General Eiffel Intelligence Information";
12+
var generalEIFrontEndInfoLabel = "General Eiffel Intelligence Front-End Information";
713

814
function createTable() {
915
var tbl = document.createElement('table');
@@ -25,24 +31,47 @@ jQuery(document).ready(function() {
2531
return element;
2632
}
2733

28-
function generateGeneralEiInfo(data) {
29-
var tbdy = document.createElement('tbody');
34+
function createFrontEndGeneralInfo() {
35+
if (frontEndApplicationPropertiesVersion) {
36+
frontEndVersion = frontEndVersion + " (" + frontEndApplicationPropertiesVersion + ")";
37+
}
38+
var tableContent = [
39+
{ key: 'Application Name', value: frontEndAppName },
40+
{ key: 'Version', value: frontEndVersion },
41+
{ key: 'EI Front-End URL', value: frontEndServiceUrl }
42+
];
3043

31-
var label = createLabel('General Eiffel Intelligence Information');
32-
body.appendChild(label);
44+
generateGeneralInfo(tableContent, generalEIFrontEndInfoLabel);
45+
}
3346

34-
var div = document.createElement('div');
35-
div.setAttribute('class','table-responsive');
47+
function createGeneralEIInfo(data) {
3648

37-
var tbl = createTable();
49+
if (data.applicationPropertiesVersion) {
50+
data.version = data.version + " (" + data.applicationPropertiesVersion + ")";
51+
}
3852

3953
var tableContent = [
4054
{ key: 'Application Name', value: data.applicationName },
4155
{ key: 'Version', value: data.version },
42-
{ key: 'EI Backend Connected Server', value: backendServerUrl },
43-
{ key: 'EI Test Rules functionality enabled', value: data.testRulesEnabled },
56+
{ key: 'Rules File Path', value: data.rulesPath },
57+
{ key: 'EI Back-End Connected Server', value: backEndServerUrl },
58+
{ key: 'EI Test Rules functionality enabled', value: data.testRulesEnabled }
4459
];
4560

61+
generateGeneralInfo(tableContent, generalEIInfoLabel);
62+
}
63+
64+
function generateGeneralInfo(tableContent, labelText) {
65+
var tbdy = document.createElement('tbody');
66+
67+
var label = createLabel(labelText);
68+
body.appendChild(label);
69+
70+
var div = document.createElement('div');
71+
div.setAttribute('class','table-responsive');
72+
73+
var tbl = createTable();
74+
4675
for (i = 0; i < tableContent.length; i++) {
4776
key = tableContent[i].key;
4877
value = tableContent[i].value;
@@ -96,24 +125,19 @@ jQuery(document).ready(function() {
96125

97126
function getInstanceInfo() {
98127
$.ajax({
99-
url: frontendServiceUrl + "/information",
128+
url: frontEndServiceUrl + "/information",
100129
contentType : 'application/json;charset=UTF-8',
101130
type: 'GET',
102131
error : function (XMLHttpRequest, textStatus, errorThrown) {
103-
var label = createLabel('General Eiffel Intelligence Information');
132+
var label = createLabel(generalEIInfoLabel);
104133
body.appendChild(label);
105-
if (XMLHttpRequest.responseText == "") {
106-
var element = createErrorMessage('<strong>Error</strong> There is no response from backend!');
107-
body.appendChild(element);
108-
} else {
109-
var element = createErrorMessage('Error: ' + XMLHttpRequest.responseText + '!');
110-
body.appendChild(element);
111-
}
134+
var element = createErrorMessage('<strong>Error:</strong> Could not fetch information from back-end!');
135+
body.appendChild(element);
112136
},
113137
success : function (data, textStatus, xhr) {
114138
var eiInfoContainer = document.getElementById('eiInfoContainer');
115139
var data = JSON.parse(xhr.responseText);
116-
generateGeneralEiInfo(data);
140+
createGeneralEIInfo(data);
117141
generateEIInformationBasedOnList(data.rabbitmq, "Eiffel Intelligence Connected RabbitMq Instances");
118142
generateEIInformationBasedOnList(data.mongodb, "Eiffel Intelligence Connected MongoDb Instances");
119143
generateEIInformationBasedOnList(data.threads, "Eiffel Intelligence Backend Java Threads Settings");
@@ -130,6 +154,7 @@ jQuery(document).ready(function() {
130154
});
131155
}
132156

157+
createFrontEndGeneralInfo();
133158
getInstanceInfo();
134159

135160
});

src/main/resources/templates/eiInfo.html

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,12 @@
1010

1111
<body class="nav-link">
1212
<div class="d-none" id="frontendServiceUrl" th:text="${frontendServiceUrl}"></div>
13-
<div class="d-none" id="frontendServiceVersion" th:text="${frontendServiceVersion}"></div>
13+
<div class="d-none" id="frontEndVersion" th:text="${version}"></div>
14+
<div class="d-none" id="frontEndApplicationPropertiesVersion" th:text="${applicationPropertiesVersion}"></div>
15+
<div class="d-none" id="frontendAppName" th:text="${frontendAppName}"></div>
1416
<div class="d-none" id="backendServerUrl" th:text="${backendServerUrl}"></div>
1517

16-
<div class="col-12" id="eiPageFrame">
17-
<p class="section-p-text table-text-setting">General Eiffel Intelligence Front End Information</p>
18-
<div class="table-responsive">
19-
<table class="table table-bordered table-striped dataTable table-text-setting">
20-
<tbody>
21-
<tr>
22-
<td class="left-table-pane">
23-
Application Name
24-
</td>
25-
<td>
26-
<span th:text="${frontendAppName}"></span>
27-
</td>
28-
</tr>
29-
<tr>
30-
<td class="left-table-pane">
31-
Application Version
32-
</td>
33-
<td>
34-
<span th:text="${frontendServiceVersion}"></span>
35-
</td>
36-
</tr>
37-
<tr>
38-
<td class="left-table-pane">
39-
Application URL
40-
</td>
41-
<td>
42-
<span th:text="${frontendServiceUrl}"></span>
43-
</td>
44-
</tr>
45-
</tbody>
46-
</table>
47-
</div>
48-
</div>
18+
<div class="col-12" id="eiPageFrame"></div>
4919

5020
<script type="text/javascript" src="js/eiInfo.js"></script>
5121

src/test/java/com/ericsson/ei/frontend/WebControllerUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class WebControllerUtilsTest {
3535
@Test
3636
public void testGetFrontEndServiceUrl() throws Exception {
3737
String expectedUrl = String.format("http://%s:%s%s", HOST, PORT, CONTEXT_PATH);
38-
controllerUtils = new WebControllerUtils(HOST, PORT, CONTEXT_PATH, false, null, null, null, null);
38+
controllerUtils = new WebControllerUtils(HOST, PORT, CONTEXT_PATH, false, null, null, null, null, null);
3939
assertEquals(expectedUrl, controllerUtils.getFrontEndServiceUrl());
4040
}
4141

0 commit comments

Comments
 (0)