Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 710124fa

Přidáno uživatelem Ondřej Váně před téměř 3 roky(ů)

#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

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
4 4
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager;
5 5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
6 6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
7
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
7 8
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService;
8 9
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService;
9 10
import org.slf4j.Logger;
......
14 15
import org.springframework.web.bind.annotation.*;
15 16
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
16 17

  
18
import java.time.LocalTime;
19
import java.time.format.DateTimeFormatter;
17 20
import java.util.List;
18 21

  
19 22
@Controller
......
74 77
            return "index";
75 78
        }
76 79

  
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);
78 84

  
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()));
79 121
        return "result";
80 122
    }
81 123

  
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/detecting/AntiPatternManager.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.detecting;
2 2

  
3 3

  
4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query;
5 4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
6 5

  
7 6
import java.util.List;
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/model/CacheablesValues.java
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
2 2

  
3 3
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector;
4 4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult;
5 6

  
6 7
import java.util.List;
7 8

  
......
18 19
    List<AntiPatternDetector> getAllAntiPatternsForGivenIds(Long[] ids);
19 20

  
20 21
    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

  
21 37
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java
2 2

  
3 3
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.detectors.AntiPatternDetector;
4 4
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;
5 7
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository;
6 8
import org.springframework.beans.factory.annotation.Autowired;
7 9
import org.springframework.stereotype.Service;
......
17 19
    @Autowired
18 20
    private AntiPatternRepository antiPatternRepository;
19 21

  
22
    // class that stores cached values
23
    private CacheablesValues cacheablesValues = new CacheablesValues();
24

  
20 25
    @Override
21 26
    public List<AntiPatternDetector> getAllAntiPatterns() {
22 27
        return antiPatternRepository.getAllAntiPatterns();
......
66 71
                    if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Integer.class) {
67 72
                        try {
68 73
                            antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Integer.parseInt(configValues[i])));
74
                            setConfigurationChanged(true);
69 75
                        } catch (NumberFormatException e) {
70 76
                            return false;
71 77
                        }
......
73 79
                    } else if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Float.class) {
74 80
                        try {
75 81
                            antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Float.parseFloat(configValues[i])));
82
                            setConfigurationChanged(true);
76 83
                        } catch (NumberFormatException e) {
77 84
                            return false;
78 85
                        }
79 86
                    } else if (antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).getValue().getClass() == Double.class) {
80 87
                        try {
81 88
                            antiPatternDetector.getAntiPatternModel().getConfigurations().get(configNames[i]).setValue((Double.parseDouble(configValues[i])));
89
                            setConfigurationChanged(true);
82 90
                        } catch (NumberFormatException e) {
83 91
                            return false;
84 92
                        }
......
88 96
        }
89 97
        return true;
90 98
    }
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
    }
91 135
}
src/main/webapp/WEB-INF/templates/result.html
21 21
        .icon-style {
22 22
            border-radius: 30px;
23 23
        }
24

  
25
        input, button, submit {
26
            border: none;
27
        }
24 28
    </style>
25 29

  
26 30
</head>
......
31 35

  
32 36
<!-- Result table container -->
33 37
<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 -->
34 52
    <h1>Results</h1>
35 53
    <table class="table table-bordered table-hover">
36 54
        <!-- Result table header -->
......
91 109
        </tbody>
92 110
        <!-- ./Result table content -->
93 111
    </table>
112
    <p><small th:text="@{Last recalculated at &#160;} + ${ recalculationTime}"></small></p>
94 113

  
95 114
    <!-- Table legend -->
96 115
    <h6>Legend:</h6>
......
114 133
</div>
115 134
<!-- ./Result table container -->
116 135

  
117
<!-- Script to popover -->
136
<!-- Scripts -->
118 137
<script>
138
    // script to popover
119 139
    $(document).ready(function () {
120 140
        $('[data-toggle="popover"]').popover();
121 141
    });
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
    }
122 162
</script>
123
<!-- ./Script to popover -->
163
<!-- ./Scripts -->
124 164

  
125 165
</body>
126 166
</html>

Také k dispozici: Unified diff