Revize e72cefc2
Přidáno uživatelem stepanekp před asi 3 roky(ů)
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/controller/AppController.java | ||
---|---|---|
231 | 231 |
* @param thresholdNames changed configuration names |
232 | 232 |
* @return html file name for thymeleaf template |
233 | 233 |
*/ |
234 |
@PostMapping("/configuration")
|
|
234 |
@PostMapping(value = "/configuration", params = "configuration-save-button")
|
|
235 | 235 |
public String configurationPost(Model model, |
236 | 236 |
@RequestParam(value = "thresholdValues", required = false) String[] thresholdValues, |
237 | 237 |
@RequestParam(value = "thresholdNames", required = false) String[] thresholdNames, |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/ConfigurationRepository.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.repository; |
2 | 2 |
|
3 | 3 |
import com.fasterxml.jackson.databind.JsonNode; |
4 |
import com.fasterxml.jackson.databind.node.ArrayNode; |
|
5 |
import com.fasterxml.jackson.databind.node.ObjectNode; |
|
4 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.utils.JsonParser; |
5 | 7 |
import org.slf4j.Logger; |
6 | 8 |
import org.slf4j.LoggerFactory; |
... | ... | |
10 | 12 |
import javax.servlet.ServletContext; |
11 | 13 |
import java.io.*; |
12 | 14 |
import java.net.URL; |
15 |
import java.nio.file.Paths; |
|
16 |
import java.util.ArrayList; |
|
13 | 17 |
import java.util.HashMap; |
18 |
import java.util.List; |
|
14 | 19 |
import java.util.Map; |
15 | 20 |
|
16 | 21 |
@Component |
... | ... | |
109 | 114 |
|
110 | 115 |
LOGGER.info("-------FINISHED READING CONFIGURATIONS FROM FILES-------"); |
111 | 116 |
} |
117 |
|
|
118 |
public void saveConfigurationToFile(String configurationName, Map<String, Map <String, String>> newConfiguration){ |
|
119 |
ObjectNode root = JsonParser.getObjectMapper().createObjectNode(); |
|
120 |
|
|
121 |
ArrayNode array = JsonParser.getObjectMapper().createArrayNode(); |
|
122 |
|
|
123 |
for(String antiPatternName : newConfiguration.keySet()){ |
|
124 |
ObjectNode antiPattern = JsonParser.getObjectMapper().createObjectNode(); |
|
125 |
antiPattern.put("antiPattern", antiPatternName); |
|
126 |
|
|
127 |
ArrayNode thresholdsArray = JsonParser.getObjectMapper().createArrayNode(); |
|
128 |
|
|
129 |
for(String thresholdName : newConfiguration.get(antiPatternName).keySet()){ |
|
130 |
ObjectNode threshold = JsonParser.getObjectMapper().createObjectNode(); |
|
131 |
threshold.put("thresholdName", thresholdName); |
|
132 |
threshold.put("value", newConfiguration.get(antiPatternName).get(thresholdName)); |
|
133 |
thresholdsArray.add(threshold); |
|
134 |
} |
|
135 |
|
|
136 |
antiPattern.set("thresholds", thresholdsArray); |
|
137 |
array.add(antiPattern); |
|
138 |
} |
|
139 |
|
|
140 |
root.set("configuration", array); |
|
141 |
|
|
142 |
try { |
|
143 |
URL url = servletContext.getResource(CONFIGURATION_DIR + configurationName + ".json"); |
|
144 |
JsonParser.getObjectWriter().writeValue(Paths.get(url.toURI()).toFile(), root); |
|
145 |
} catch (Exception e) { |
|
146 |
LOGGER.error("Cannot write configuration to the file"); |
|
147 |
} |
|
148 |
|
|
149 |
} |
|
112 | 150 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/service/ConfigurationServiceImpl.java | ||
---|---|---|
130 | 130 |
else |
131 | 131 |
configurationRepository.allConfigurations.replace(configurationName, newConfiguration); |
132 | 132 |
|
133 |
configurationRepository.saveConfigurationToFile(configurationName, newConfiguration); |
|
134 |
|
|
133 | 135 |
return incorrectParameters; |
134 | 136 |
} |
135 | 137 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/utils/JsonParser.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.utils; |
2 | 2 |
|
3 |
import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; |
|
3 | 4 |
import com.fasterxml.jackson.databind.JsonNode; |
4 | 5 |
import com.fasterxml.jackson.databind.ObjectMapper; |
6 |
import com.fasterxml.jackson.databind.ObjectWriter; |
|
5 | 7 |
|
6 | 8 |
import java.io.IOException; |
7 | 9 |
|
... | ... | |
20 | 22 |
public static JsonNode parse(String src) throws IOException { |
21 | 23 |
return objectMapper.readTree(src); |
22 | 24 |
} |
25 |
|
|
26 |
public static ObjectWriter getObjectWriter() { |
|
27 |
ObjectWriter writer = objectMapper.writer(new DefaultPrettyPrinter()); |
|
28 |
return writer; |
|
29 |
} |
|
30 |
|
|
31 |
public static ObjectMapper getObjectMapper(){ |
|
32 |
return objectMapper; |
|
33 |
} |
|
23 | 34 |
} |
src/main/webapp/WEB-INF/templates/configuration.html | ||
---|---|---|
88 | 88 |
|
89 | 89 |
<!-- Submit button to save configuration --> |
90 | 90 |
<div class="save-configuration-button-container"> |
91 |
<button type="submit" class="btn btn-primary btn-lg custom-button" id="configuration-save-button" hidden>Save</button> |
|
92 |
<button type="submit" class="btn btn-outline-primary btn-lg custom-button" id="configuration-save-as-button" hidden>Save as</button> |
|
91 |
<button type="submit" class="btn btn-primary btn-lg custom-button" id="configuration-save-button" name="configuration-save-button" hidden>Save</button>
|
|
92 |
<button type="submit" class="btn btn-outline-primary btn-lg custom-button" id="configuration-save-as-button" name="configuration-save-as-button" hidden>Save as</button>
|
|
93 | 93 |
</div> |
94 | 94 |
<!-- ./Submit button to save configuration --> |
95 | 95 |
</form> |
Také k dispozici: Unified diff
#14 Saving configurations to files added