Projekt

Obecné

Profil

« Předchozí | Další » 

Revize b9635ea8

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

#14 Saving function moved

Zobrazit rozdíly:

src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java
3 3
import com.fasterxml.jackson.databind.JsonNode;
4 4
import com.fasterxml.jackson.databind.node.ArrayNode;
5 5
import com.fasterxml.jackson.databind.node.ObjectNode;
6
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern;
7
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.Percentage;
8
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveFloat;
9
import cz.zcu.fav.kiv.antipatterndetectionapp.model.types.PositiveInteger;
6 10
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.JsonParser;
11
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.Utils;
7 12
import org.slf4j.Logger;
8 13
import org.slf4j.LoggerFactory;
9 14
import org.springframework.stereotype.Component;
......
13 18
import java.io.*;
14 19
import java.net.URL;
15 20
import java.nio.file.Paths;
21
import java.util.ArrayList;
16 22
import java.util.HashMap;
23
import java.util.List;
17 24
import java.util.Map;
18 25

  
19 26
@Component
......
146 153
        }
147 154

  
148 155
    }
156

  
157
    public List<String> saveNewConfiguration(List<AntiPattern> antiPatterns, String configurationName, String[] antiPatternNames, String[] thresholdNames, String[] thresholdValues, boolean fullNewConfiguration){
158
        Map<String, Map<String, String>> newConfiguration = new HashMap<>();
159
        List<String> incorrectParameters = new ArrayList<>();
160

  
161
        for(AntiPattern antiPattern : antiPatterns){
162
            if(antiPattern.getThresholds() == null)
163
                continue;
164

  
165
            for(int i = 0; i < thresholdNames.length; i++){
166
                if(antiPattern.getThresholds().containsKey(thresholdNames[i])){
167
                    if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Integer")){
168
                        try {
169
                            Integer.parseInt(thresholdValues[i]);
170
                        }
171
                        catch(NumberFormatException e){
172
                            incorrectParameters.add(thresholdNames[i]);
173
                        }
174
                    }
175
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Percentage")){
176
                        try {
177
                            Percentage.parsePercentage(thresholdValues[i]);
178
                        }
179
                        catch(NumberFormatException e){
180
                            incorrectParameters.add(thresholdNames[i]);
181
                        }
182
                    }
183
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("PositiveInteger")){
184
                        try {
185
                            PositiveInteger.parsePositiveInteger(thresholdValues[i]);
186
                        }
187
                        catch(NumberFormatException e){
188
                            incorrectParameters.add(thresholdNames[i]);
189
                        }
190
                    }
191
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("PositiveFloat")){
192
                        try {
193
                            PositiveFloat.parsePositiveFloat(thresholdValues[i]);
194
                        }
195
                        catch(NumberFormatException e){
196
                            incorrectParameters.add(thresholdNames[i]);
197
                        }
198
                    }
199
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Float")){
200
                        try {
201
                            Float.parseFloat(thresholdValues[i]);
202
                        }
203
                        catch(NumberFormatException e){
204
                            incorrectParameters.add(thresholdNames[i]);
205
                        }
206
                    }
207
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("Double")){
208
                        try {
209
                            Double.parseDouble(thresholdValues[i]);
210
                        }
211
                        catch(NumberFormatException e){
212
                            incorrectParameters.add(thresholdNames[i]);
213
                        }
214
                    }
215
                    else if(antiPattern.getThresholds().get(thresholdNames[i]).getType().equals("String")){
216
                        if (Utils.checkStringSubstrings(thresholdValues[i]) == false) {
217
                            incorrectParameters.add(thresholdNames[i]);
218
                        }
219
                    }
220
                }
221
            }
222
        }
223

  
224
        if(incorrectParameters.size() != 0)
225
            return incorrectParameters;
226

  
227
        if(fullNewConfiguration) { // creating full new configuration as we have all thresholds for all anti-patterns
228
            for (int i = 0; i < antiPatternNames.length; i++) {
229
                if (newConfiguration.get(antiPatternNames[i]) == null)
230
                    newConfiguration.put(antiPatternNames[i], new HashMap<>());
231

  
232
                newConfiguration.get(antiPatternNames[i]).put(thresholdNames[i], thresholdValues[i]);
233
            }
234
        }
235
        else{   // updating only some thresholds in current configuration
236
            newConfiguration = this.allConfigurations.get(configurationName);
237
            for(int i = 0; i < thresholdNames.length; i++) {
238
                newConfiguration.get(antiPatternNames[i]).replace(thresholdNames[i], thresholdValues[i]);
239
            }
240
        }
241

  
242

  
243
        if(this.allConfigurations.get(configurationName) == null)
244
            this.allConfigurations.put(configurationName, newConfiguration);
245
        else
246
            this.allConfigurations.replace(configurationName, newConfiguration);
247

  
248
        this.saveConfigurationToFile(configurationName, newConfiguration);
249

  
250
        return incorrectParameters;
251
    }
149 252
}
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ConfigurationServiceImpl.java
10 10
import org.springframework.stereotype.Service;
11 11

  
12 12
import java.util.ArrayList;
13
import java.util.HashMap;
14 13
import java.util.List;
15 14
import java.util.Map;
16 15

  
......
49 48

  
50 49
    @Override
51 50
    public List<String> saveNewConfiguration(List<AntiPattern> antiPatterns, String configurationName, String[] antiPatternNames, String[] thresholdNames, String[] thresholdValues, boolean fullNewConfiguration){
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]).getType().equals("Integer")){
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]).getType().equals("Percentage")){
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]).getType().equals("PositiveInteger")){
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]).getType().equals("PositiveFloat")){
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]).getType().equals("Float")){
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]).getType().equals("Double")){
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]).getType().equals("String")){
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
        if(fullNewConfiguration) { // creating full new configuration as we have all thresholds for all anti-patterns
122
            for (int i = 0; i < antiPatternNames.length; i++) {
123
                if (newConfiguration.get(antiPatternNames[i]) == null)
124
                    newConfiguration.put(antiPatternNames[i], new HashMap<>());
125

  
126
                newConfiguration.get(antiPatternNames[i]).put(thresholdNames[i], thresholdValues[i]);
127
            }
128
        }
129
        else{   // updating only some thresholds in current configuration
130
            newConfiguration = configurationRepository.allConfigurations.get(configurationName);
131
            for(int i = 0; i < thresholdNames.length; i++) {
132
                newConfiguration.get(antiPatternNames[i]).replace(thresholdNames[i], thresholdValues[i]);
133
            }
134
        }
135

  
136

  
137
        if(configurationRepository.allConfigurations.get(configurationName) == null)
138
            configurationRepository.allConfigurations.put(configurationName, newConfiguration);
139
        else
140
            configurationRepository.allConfigurations.replace(configurationName, newConfiguration);
141

  
142
        configurationRepository.saveConfigurationToFile(configurationName, newConfiguration);
143

  
144
        return incorrectParameters;
51
        return configurationRepository.saveNewConfiguration(antiPatterns, configurationName, antiPatternNames, thresholdNames, thresholdValues, fullNewConfiguration);
145 52
    }
146 53
}

Také k dispozici: Unified diff