Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 31e75674

Přidáno uživatelem stepanekp před asi 3 roky(ů)

#14 Saving configuration threshold values added

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java
234 234
    @PostMapping("/configuration")
235 235
    public String configurationPost(Model model,
236 236
                                    @RequestParam(value = "thresholdValues", required = false) String[] thresholdValues,
237
                                    @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames) {
237
                                    @RequestParam(value = "thresholdNames", required = false) String[] thresholdNames,
238
                                    @RequestParam(value = "antiPatternNames", required = false) String[] antiPatternNames,
239
                                    HttpSession session) {
240

  
241
        String currentConfigurationName = configurationGetFromSession(session);
238 242

  
239 243
        List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns());
240
        List<String> wrongParameters = antiPatternService.saveNewConfiguration(thresholdNames, thresholdValues);
244

  
245
        List<String> wrongParameters = configurationService.saveNewConfiguration(antiPatterns, currentConfigurationName, antiPatternNames, thresholdNames, thresholdValues);
241 246

  
242 247
        if (wrongParameters.isEmpty()) {
243 248
            model.addAttribute("successMessage", "All configuration values has been successfully saved.");
......
247 252
        }
248 253

  
249 254
        model.addAttribute("antiPatterns", antiPatterns);
255
        model.addAttribute("configurations", configurationService.getConfigurationByName(currentConfigurationName));
250 256
        return "configuration";
251 257
    }
252 258

  
......
268 274
                                   RedirectAttributes redirectAttrs) {
269 275

  
270 276
        AntiPattern antiPattern = antiPatternService.antiPatternToModel(antiPatternService.getAntiPatternById(id));
271
        List<String> wrongParameters = antiPatternService.saveNewConfiguration(thresholdNames, thresholdValues);
277
        //List<String> wrongParameters = antiPatternService.saveNewConfiguration(thresholdNames, thresholdValues);
278
        List<String> wrongParameters = new ArrayList<>(); //TODO
272 279

  
273 280
        if (wrongParameters.isEmpty()) {
274 281
            redirectAttrs.addFlashAttribute("successMessage", "All threshold values has been successfully saved.");
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternService.java
18 18

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

  
21
    List<String> saveNewConfiguration(String[] configNames, String[] configValues);
22

  
23 21
    void saveAnalyzedProjects(String[] selectedProjects, String[] selectedAntiPatterns);
24 22

  
25 23
    String[] getAnalyzedProjects();
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/AntiPatternServiceImpl.java
78 78
        return antiPatternDetectors;
79 79
    }
80 80

  
81
    public List<String> saveNewConfiguration(String[] thresholdNames, String[] thresholdValues) {
82
        List<AntiPatternDetector> antiPatternDetectors = antiPatternRepository.getAllAntiPatterns();
83
        List<String> incorrectParameters = new ArrayList<>();
84

  
85
        for (AntiPatternDetector antiPatternDetector : antiPatternDetectors) {
86
            // not every anti-pattern should have thresholds
87
            if (antiPatternDetector.getAntiPatternModel().getThresholds() == null) {
88
                continue;
89
            }
90
            for (int i = 0; i < thresholdNames.length; i++) {
91
                if (antiPatternDetector.getAntiPatternModel().getThresholds().containsKey(thresholdNames[i])) {
92

  
93
                    if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == Integer.class) {
94
                        try {
95
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((Integer.parseInt(thresholdValues[i])));
96
                            setConfigurationChanged(true);
97
                        } catch (NumberFormatException e) {
98
                            incorrectParameters.add(thresholdNames[i]);
99
                        }
100

  
101
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == Percentage.class) {
102
                        try {
103
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((Percentage.parsePercentage(thresholdValues[i])));
104
                            setConfigurationChanged(true);
105
                        } catch (NumberFormatException e) {
106
                            incorrectParameters.add(thresholdNames[i]);
107
                        }
108
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == PositiveInteger.class) {
109
                        try {
110
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((PositiveInteger.parsePositiveInteger(thresholdValues[i])));
111
                            setConfigurationChanged(true);
112
                        } catch (NumberFormatException e) {
113
                            incorrectParameters.add(thresholdNames[i]);
114
                        }
115
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == PositiveFloat.class) {
116
                        try {
117
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((PositiveFloat.parsePositiveFloat(thresholdValues[i])));
118
                            setConfigurationChanged(true);
119
                        } catch (NumberFormatException e) {
120
                            incorrectParameters.add(thresholdNames[i]);
121
                        }
122
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == Float.class) {
123
                        try {
124
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((Float.parseFloat(thresholdValues[i])));
125
                            setConfigurationChanged(true);
126
                        } catch (NumberFormatException e) {
127
                            incorrectParameters.add(thresholdNames[i]);
128
                        }
129
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == Double.class) {
130
                        try {
131
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((Double.parseDouble(thresholdValues[i])));
132
                            setConfigurationChanged(true);
133
                        } catch (NumberFormatException e) {
134
                            incorrectParameters.add(thresholdNames[i]);
135
                        }
136
                    } else if (antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).getValue().getClass() == String.class) {
137
                        if (Utils.checkStringSubstrings(thresholdValues[i])) {
138
                            antiPatternDetector.getAntiPatternModel().getThresholds().get(thresholdNames[i]).setValue((thresholdValues[i]));
139
                            setConfigurationChanged(true);
140

  
141
                        } else {
142
                            incorrectParameters.add(thresholdNames[i]);
143
                        }
144
                    }
145
                }
146
            }
147
        }
148
        return incorrectParameters;
149
    }
150

  
151 81
    @Override
152 82
    public void saveAnalyzedProjects(String[] selectedProjects, String[] selectedAntiPatterns) {
153 83
        this.cacheablesValues.setAnalyzedProjects(selectedProjects);
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ConfigurationService.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.service;
2 2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
4

  
3 5
import java.util.HashMap;
4 6
import java.util.List;
5 7
import java.util.Map;
......
11 13
    List<String> getDefaultConfigurationNames();
12 14

  
13 15
    Map<String, Map<String, String>> getConfigurationByName(String configurationName);
16

  
17
    List<String> saveNewConfiguration(List<AntiPattern> antiPatterns, String configurationName, String[] antiPatternNames, String[] thresholdNames, String[] thresholdValues);
14 18
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ConfigurationServiceImpl.java
1 1
package cz.zcu.fav.kiv.antipatterndetectionapp.service;
2 2

  
3
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
4
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage;
5
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveFloat;
6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
3 7
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.ConfigurationRepository;
8
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
4 9
import org.springframework.beans.factory.annotation.Autowired;
5 10
import org.springframework.stereotype.Service;
6 11

  
7 12
import java.util.ArrayList;
13
import java.util.HashMap;
8 14
import java.util.List;
9 15
import java.util.Map;
10 16

  
......
40 46
    public Map<String, Map<String, String>> getConfigurationByName(String configurationName) {
41 47
        return configurationRepository.allConfigurations.get(configurationName);
42 48
    }
49

  
50
    @Override
51
    public List<String> saveNewConfiguration(List<AntiPattern> antiPatterns, String configurationName, String[] antiPatternNames, String[] thresholdNames, String[] thresholdValues){
52
        Map<String, Map<String, String>> newConfiguration = new HashMap<>();
53
        List<String> incorrectParameters = new ArrayList<>();
54

  
55
        for(AntiPattern antiPattern : antiPatterns){
56
            if(antiPattern.getThresholds() == null)
57
                continue;
58

  
59
            for(int i = 0; i < thresholdNames.length; i++){
60
                if(antiPattern.getThresholds().containsKey(thresholdNames[i])){
61
                    if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == Integer.class){
62
                        try {
63
                            Integer.parseInt(thresholdValues[i]);
64
                        }
65
                        catch(NumberFormatException e){
66
                            incorrectParameters.add(thresholdNames[i]);
67
                        }
68
                    }
69
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == Percentage.class){
70
                        try {
71
                            Percentage.parsePercentage(thresholdValues[i]);
72
                        }
73
                        catch(NumberFormatException e){
74
                            incorrectParameters.add(thresholdNames[i]);
75
                        }
76
                    }
77
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == PositiveInteger.class){
78
                        try {
79
                            PositiveInteger.parsePositiveInteger(thresholdValues[i]);
80
                        }
81
                        catch(NumberFormatException e){
82
                            incorrectParameters.add(thresholdNames[i]);
83
                        }
84
                    }
85
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == PositiveFloat.class){
86
                        try {
87
                            PositiveFloat.parsePositiveFloat(thresholdValues[i]);
88
                        }
89
                        catch(NumberFormatException e){
90
                            incorrectParameters.add(thresholdNames[i]);
91
                        }
92
                    }
93
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == Float.class){
94
                        try {
95
                            Float.parseFloat(thresholdValues[i]);
96
                        }
97
                        catch(NumberFormatException e){
98
                            incorrectParameters.add(thresholdNames[i]);
99
                        }
100
                    }
101
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == Double.class){
102
                        try {
103
                            Double.parseDouble(thresholdValues[i]);
104
                        }
105
                        catch(NumberFormatException e){
106
                            incorrectParameters.add(thresholdNames[i]);
107
                        }
108
                    }
109
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getValue().getClass() == String.class){
110
                        if (Utils.checkStringSubstrings(thresholdValues[i]) == false) {
111
                            incorrectParameters.add(thresholdNames[i]);
112
                        }
113
                    }
114
                }
115
            }
116
        }
117

  
118
        if(incorrectParameters.size() != 0)
119
            return incorrectParameters;
120

  
121
        for(int i = 0; i < antiPatternNames.length; i++){
122
            if(newConfiguration.get(antiPatternNames[i]) == null)
123
                newConfiguration.put(antiPatternNames[i], new HashMap<>());
124

  
125
            newConfiguration.get(antiPatternNames[i]).put(thresholdNames[i], thresholdValues[i]);
126
        }
127

  
128
        if(configurationRepository.allConfigurations.get(configurationName) == null)
129
            configurationRepository.allConfigurations.put(configurationName, newConfiguration);
130
        else
131
            configurationRepository.allConfigurations.replace(configurationName, newConfiguration);
132

  
133
        return incorrectParameters;
134
    }
43 135
}
src/main/webapp/WEB-INF/templates/configuration.html
55 55
                                           name="thresholdValues">
56 56
                                    <input th:value="${threshold.value.name}" style="display: none" class="form-control"
57 57
                                           name="thresholdNames">
58
                                    <input th:value="${antiPattern.name}" style="display: none" class="form-control"
59
                                           name="antiPatternNames">
58 60
                                </div>
59 61
                                <div th:if="${#strings.contains(threshold.value.name,'Substrings')}" id="second"
60 62
                                     style="margin: 10px; padding-left: 10px">

Také k dispozici: Unified diff