Skip to content

Commit 710124f

Browse files
OndrejVaneppicha
authored andcommitted
#2 Implement check of used vs. set parameters
- added functionality that checks if the thresholds have changed - if the thresholds have changed, the user is informed - added button for recalculation values
1 parent 23722b9 commit 710124f

6 files changed

Lines changed: 191 additions & 4 deletions

File tree

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager;
55
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
66
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
7+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
78
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService;
89
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
910
import org.slf4j.Logger;
@@ -14,6 +15,8 @@
1415
import org.springframework.web.bind.annotation.*;
1516
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
1617

18+
import java.time.LocalTime;
19+
import java.time.format.DateTimeFormatter;
1720
import java.util.List;
1821

1922
@Controller
@@ -74,8 +77,47 @@ public String analyze(Model model,
7477
return "index";
7578
}
7679

77-
model.addAttribute("queryResults", antiPatternManager.analyze(selectedProjects, selectedAntiPatterns));
80+
List<QueryResult> results = antiPatternManager.analyze(selectedProjects, selectedAntiPatterns);
81+
antiPatternService.saveAnalyzedProjects(selectedProjects, selectedAntiPatterns);
82+
antiPatternService.saveResults(results);
83+
antiPatternService.setConfigurationChanged(false);
7884

85+
model.addAttribute("queryResults", results);
86+
model.addAttribute("recalculationTime", DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));
87+
88+
return "result";
89+
}
90+
91+
92+
@GetMapping("/analyze")
93+
public String analyzeGet(Model model) {
94+
if (antiPatternService.isConfigurationChanged()) {
95+
model.addAttribute("isConfigurationChanged", true);
96+
}
97+
antiPatternService.setConfigurationChanged(false);
98+
99+
model.addAttribute("queryResults", antiPatternService.getResults());
100+
model.addAttribute("recalculationTime", DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));
101+
102+
return "result";
103+
}
104+
105+
@GetMapping("/recalculate")
106+
public String recalculateGet(Model model) {
107+
return analyzeGet(model);
108+
}
109+
110+
@PostMapping("/recalculate")
111+
public String resultRecalculate(Model model) {
112+
113+
List<QueryResult> results = antiPatternManager.analyze(antiPatternService.getAnalyzedProjects(),
114+
antiPatternService.getAnalyzedAntiPatterns());
115+
116+
antiPatternService.saveResults(results);
117+
antiPatternService.setConfigurationChanged(false);
118+
119+
model.addAttribute("queryResults", results);
120+
model.addAttribute("recalculationTime", DateTimeFormatter.ofPattern("HH:mm:ss").format(LocalTime.now()));
79121
return "result";
80122
}
81123

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/AntiPatternManager.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting;
22

33

4-
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
54
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
65

76
import java.util.List;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package cz.zcu.fav.kiv.antipatterndetectionapp.model;
2+
3+
import java.util.List;
4+
5+
public class CacheablesValues {
6+
7+
// these values ​​store information about currently processed projects and anti-patterns
8+
private String[] analyzedProjects;
9+
private String[] analyzedAntiPatterns;
10+
11+
// this value indicate if configuration values have changed
12+
private boolean configurationChanged = false;
13+
private List<QueryResult> results;
14+
15+
public String[] getAnalyzedProjects() {
16+
return analyzedProjects;
17+
}
18+
19+
public void setAnalyzedProjects(String[] analyzedProjects) {
20+
this.analyzedProjects = analyzedProjects;
21+
}
22+
23+
public String[] getAnalyzedAntiPatterns() {
24+
return analyzedAntiPatterns;
25+
}
26+
27+
public void setAnalyzedAntiPatterns(String[] analyzedAntiPatterns) {
28+
this.analyzedAntiPatterns = analyzedAntiPatterns;
29+
}
30+
31+
public boolean isConfigurationChanged() {
32+
return configurationChanged;
33+
}
34+
35+
public void setConfigurationChanged(boolean configurationChanged) {
36+
this.configurationChanged = configurationChanged;
37+
}
38+
39+
public List<QueryResult> getResults() {
40+
return results;
41+
}
42+
43+
public void setResults(List<QueryResult> results) {
44+
this.results = results;
45+
}
46+
}

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
56

67
import java.util.List;
78

@@ -18,4 +19,19 @@ public interface AntiPatternService {
1819
List<AntiPatternDetector> getAllAntiPatternsForGivenIds(Long[] ids);
1920

2021
boolean saveNewConfiguration(String[] configNames, String[] configValues);
22+
23+
void saveAnalyzedProjects(String[] selectedProjects, String[] selectedAntiPatterns);
24+
25+
String[] getAnalyzedProjects();
26+
27+
String[] getAnalyzedAntiPatterns();
28+
29+
boolean isConfigurationChanged();
30+
31+
void setConfigurationChanged(boolean configurationChanged);
32+
33+
void saveResults(List<QueryResult> results);
34+
35+
List<QueryResult> getResults();
36+
2137
}

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector;
44
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.CacheablesValues;
6+
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
57
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
68
import org.springframework.beans.factory.annotation.Autowired;
79
import org.springframework.stereotype.Service;
@@ -17,6 +19,9 @@ public class AntiPatternServiceImpl implements AntiPatternService {
1719
@Autowired
1820
private AntiPatternRepository antiPatternRepository;
1921

22+
// class that stores cached values
23+
private CacheablesValues cacheablesValues = new CacheablesValues();
24+
2025
@Override
2126
public List<AntiPatternDetector> getAllAntiPatterns() {
2227
return antiPatternRepository.getAllAntiPatterns();
@@ -66,19 +71,22 @@ public boolean saveNewConfiguration(String[] configNames, String[] configValues)
6671
if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Integer.class) {
6772
try {
6873
antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Integer.parseInt(configValues[i])));
74+
setConfigurationChanged(true);
6975
} catch (NumberFormatException e) {
7076
return false;
7177
}
7278

7379
} else if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Float.class) {
7480
try {
7581
antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Float.parseFloat(configValues[i])));
82+
setConfigurationChanged(true);
7683
} catch (NumberFormatException e) {
7784
return false;
7885
}
7986
} else if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Double.class) {
8087
try {
8188
antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Double.parseDouble(configValues[i])));
89+
setConfigurationChanged(true);
8290
} catch (NumberFormatException e) {
8391
return false;
8492
}
@@ -88,4 +96,40 @@ public boolean saveNewConfiguration(String[] configNames, String[] configValues)
8896
}
8997
return true;
9098
}
99+
100+
@Override
101+
public void saveAnalyzedProjects(String[] selectedProjects, String[] selectedAntiPatterns) {
102+
this.cacheablesValues.setAnalyzedProjects(selectedProjects);
103+
this.cacheablesValues.setAnalyzedAntiPatterns(selectedAntiPatterns);
104+
}
105+
106+
@Override
107+
public String[] getAnalyzedProjects() {
108+
return this.cacheablesValues.getAnalyzedProjects();
109+
}
110+
111+
@Override
112+
public String[] getAnalyzedAntiPatterns() {
113+
return this.cacheablesValues.getAnalyzedAntiPatterns();
114+
}
115+
116+
@Override
117+
public void setConfigurationChanged(boolean configurationChanged) {
118+
this.cacheablesValues.setConfigurationChanged(configurationChanged);
119+
}
120+
121+
@Override
122+
public boolean isConfigurationChanged() {
123+
return this.cacheablesValues.isConfigurationChanged();
124+
}
125+
126+
@Override
127+
public void saveResults(List<QueryResult> results) {
128+
this.cacheablesValues.setResults(results);
129+
}
130+
131+
@Override
132+
public List<QueryResult> getResults() {
133+
return this.cacheablesValues.getResults();
134+
}
91135
}

src/main/webapp/WEB-INF/templates/result.html

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
.icon-style {
2222
border-radius: 30px;
2323
}
24+
25+
input, button, submit {
26+
border: none;
27+
}
2428
</style>
2529

2630
</head>
@@ -31,6 +35,20 @@
3135

3236
<!-- Result table container -->
3337
<div class="container">
38+
<!-- Container for show success message -->
39+
<div class="container">
40+
<div th:if="${isConfigurationChanged}" class="alert alert-warning" role="alert">
41+
Configuration values have changed! Would you like to
42+
<form action="#" th:action="@{/recalculate}" method="post" style="display: inline-block">
43+
<button type="submit"
44+
style="display: inline-block;background-color: #FEF3CD; color: #167AF6; text-decoration: underline;">
45+
recalculate
46+
</button>
47+
</form>
48+
the results?
49+
</div>
50+
</div>
51+
<!-- ./Container for show success message -->
3452
<h1>Results</h1>
3553
<table class="table table-bordered table-hover">
3654
<!-- Result table header -->
@@ -91,6 +109,7 @@ <h1>Results</h1>
91109
</tbody>
92110
<!-- ./Result table content -->
93111
</table>
112+
<p><small th:text="@{Last recalculated at &#160;} + ${ recalculationTime}"></small></p>
94113

95114
<!-- Table legend -->
96115
<h6>Legend:</h6>
@@ -114,13 +133,34 @@ <h6>Legend:</h6>
114133
</div>
115134
<!-- ./Result table container -->
116135

117-
<!-- Script to popover -->
136+
<!-- Scripts -->
118137
<script>
138+
// script to popover
119139
$(document).ready(function () {
120140
$('[data-toggle="popover"]').popover();
121141
});
142+
143+
// this code handling back browser button to result page
144+
window.onload = function () {
145+
if (typeof history.pushState === "function") {
146+
history.pushState("jibberish", null, null);
147+
window.onpopstate = function () {
148+
history.pushState('newjibberish', null, null);
149+
};
150+
} else {
151+
var ignoreHashChange = true;
152+
window.onhashchange = function () {
153+
if (!ignoreHashChange) {
154+
ignoreHashChange = true;
155+
window.location.hash = Math.random();
156+
} else {
157+
ignoreHashChange = false;
158+
}
159+
};
160+
}
161+
}
122162
</script>
123-
<!-- ./Script to popover -->
163+
<!-- ./Scripts -->
124164

125165
</body>
126166
</html>

0 commit comments

Comments
 (0)