Revize 031c4f3c
Přidáno uživatelem Václav Hrabík před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/repository/AntiPatternRepository.java | ||
---|---|---|
137 | 137 |
* @param jsonFileName Name of the file |
138 | 138 |
* @return AntiPattern object |
139 | 139 |
*/ |
140 |
private AntiPattern getAntiPatternFromJsonFile(String jsonFileName){
|
|
140 |
public AntiPattern getAntiPatternFromJsonFile(String jsonFileName){
|
|
141 | 141 |
String json = ""; // json configuration file content as string |
142 | 142 |
|
143 | 143 |
LOGGER.info("Reading anti-pattern from json file " + jsonFileName); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.controller; |
2 | 2 |
|
3 | 3 |
import com.google.gson.Gson; |
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository; |
|
4 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes; |
5 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*; |
6 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration.ConfigService; |
... | ... | |
41 | 43 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json),HttpStatus.valueOf(returnCode.getStatusCode())); |
42 | 44 |
} |
43 | 45 |
|
44 |
/** |
|
45 |
* Endpoint returns the definitions of configurations (ie the json objects) and their names |
|
46 |
* @param user User querying the configurations |
|
47 |
* @return ResponseEntity with json body appropriate status code indicating result of the operation |
|
48 |
* 200 with requested body if everything is okay |
|
49 |
* 500 if db server died or no default configurations are present in the database |
|
50 |
*/ |
|
46 |
|
|
51 | 47 |
@PostMapping(value="/configuration") |
52 | 48 |
public ResponseEntity<String> getConfiguration(@RequestBody UserConfiguration userConfiguration) { |
53 | 49 |
Map<String, Object> json = new HashMap<>(); |
... | ... | |
55 | 51 |
|
56 | 52 |
Configuration config = this.configurationService.getConfiguration(userConfiguration.getUser().getName(), Integer.parseInt(userConfiguration.getId())); |
57 | 53 |
|
58 |
if(config == null) { |
|
54 |
Map<String, AntiPattern> antiPatterns = this.configurationService.getAntiPatterns(); |
|
55 |
|
|
56 |
if (config == null) { |
|
57 |
json.put("message", "internal sever error"); |
|
58 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
|
59 |
} |
|
60 |
|
|
61 |
if (antiPatterns == null) { |
|
59 | 62 |
json.put("message", "internal sever error"); |
60 | 63 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
61 | 64 |
} |
62 | 65 |
|
63 | 66 |
json.put("configuration", config.getConfig()); |
67 |
json.put("antiPatterns", antiPatterns); |
|
64 | 68 |
|
65 | 69 |
return new ResponseEntity<>(new Gson().toJson(json),HttpStatus.OK); |
66 | 70 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration; |
2 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
|
2 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes; |
3 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
4 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfiguration; |
6 | 7 |
|
7 | 8 |
import java.util.List; |
9 |
import java.util.Map; |
|
10 |
|
|
8 | 11 |
public interface ConfigService { |
9 | 12 |
//upload configuration |
10 | 13 |
ConfigurationControllerStatusCodes addConfiguration(Configuration cfg); |
... | ... | |
20 | 23 |
public Configuration getConfiguration(String userName, int id); |
21 | 24 |
String getConfigurationName(int userId, int configurationId); |
22 | 25 |
|
23 |
|
|
26 |
Map<String, AntiPattern> getAntiPatterns(); |
|
24 | 27 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.configuration; |
2 | 2 |
|
3 | 3 |
import com.google.gson.Gson; |
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.repository.AntiPatternRepository; |
|
4 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.dials.ConfigurationControllerStatusCodes; |
5 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*; |
6 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository; |
... | ... | |
11 | 13 |
import org.springframework.stereotype.Service; |
12 | 14 |
|
13 | 15 |
import java.util.ArrayList; |
16 |
import java.util.HashMap; |
|
14 | 17 |
import java.util.List; |
18 |
import java.util.Map; |
|
15 | 19 |
|
16 | 20 |
@Service |
17 | 21 |
public class ConfigurationServiceImplementation implements ConfigService { |
... | ... | |
21 | 25 |
//repository for Join table, necessary to add associations between users and configurations |
22 | 26 |
@Autowired |
23 | 27 |
private UserConfigurationJoinRepository userConfigurationJoinRepository; |
28 |
|
|
29 |
@Autowired |
|
30 |
private AntiPatternRepository antiPatternRepository; |
|
31 |
|
|
32 |
private String[] configJsonFileNames = {"BusinessAsUsual.json", "BystanderApathy.json", "LongOrNonExistentFeedbackLoops.json", |
|
33 |
"NinetyNinetyRule.json", "RoadToNowhere.json", "SpecifyNothing.json", "TooLongSprint.json", "UnknownPoster.json", |
|
34 |
"VaryingSprintLength.json", "YetAnotherProgrammer.json"}; |
|
35 |
|
|
36 |
|
|
24 | 37 |
//user service is also necessary for retrieving information about users (primarily database query for fetching id) |
25 | 38 |
@Autowired |
26 | 39 |
private UserService userService; |
... | ... | |
164 | 177 |
public String getConfigurationName(int userId, int configurationId) { |
165 | 178 |
return this.configurationRepository.findConfigurationByCompoundKey(new UserConfigKey(userId, configurationId)); |
166 | 179 |
} |
180 |
|
|
181 |
@Override |
|
182 |
public Map<String, AntiPattern> getAntiPatterns() { |
|
183 |
Map<String, AntiPattern> antiPatterns = new HashMap<>(); |
|
184 |
AntiPattern tmp = null; |
|
185 |
for (int i = 0; i < this.configJsonFileNames.length; i++) { |
|
186 |
tmp = this.antiPatternRepository.getAntiPatternFromJsonFile(configJsonFileNames[i]); |
|
187 |
antiPatterns.put(tmp.getName(), tmp); |
|
188 |
} |
|
189 |
return antiPatterns; |
|
190 |
} |
|
167 | 191 |
} |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-30 přidání posílání antiPatternů