Revize f31ea2fe
Přidáno uživatelem Jiri Trefil před téměř 2 roky(ů)
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 cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.*; |
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.ConfigRepository; |
|
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository.UserConfigurationJoinRepository; |
|
6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.ConfigurationService; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.ConfigService; |
|
7 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.utils.JSONBuilder; |
8 | 6 |
import org.springframework.beans.factory.annotation.Autowired; |
9 | 7 |
import org.springframework.http.HttpStatus; |
... | ... | |
22 | 20 |
@RequestMapping("v2/configuration") |
23 | 21 |
public class ConfigurationController { |
24 | 22 |
@Autowired |
25 |
private ConfigurationService configurationService;
|
|
23 |
private ConfigService configurationService; |
|
26 | 24 |
|
27 | 25 |
@PostMapping(value="/upload_configuration") |
28 | 26 |
public ResponseEntity<String> test(@RequestBody UserConfiguration userConfiguration) { |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/DetectController.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.detecting.AntiPatternManager; |
|
4 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
6 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Query; |
8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.QueryResult; |
|
7 | 9 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.AntiPatternService; |
10 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ConfigurationService; |
|
8 | 11 |
import cz.zcu.fav.kiv.antipatterndetectionapp.service.ProjectService; |
12 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserDetectionDto; |
|
13 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.service.DetectionService; |
|
9 | 14 |
import org.springframework.beans.factory.annotation.Autowired; |
10 | 15 |
import org.springframework.http.HttpStatus; |
11 | 16 |
import org.springframework.http.ResponseEntity; |
12 |
import org.springframework.web.bind.annotation.GetMapping; |
|
13 |
import org.springframework.web.bind.annotation.RequestMapping; |
|
14 |
import org.springframework.web.bind.annotation.RestController; |
|
17 |
import org.springframework.web.bind.annotation.*; |
|
15 | 18 |
|
16 | 19 |
import java.util.List; |
20 |
import java.util.Map; |
|
17 | 21 |
|
18 | 22 |
@RestController |
19 | 23 |
@RequestMapping("v2/detect") |
20 | 24 |
public class DetectController { |
21 | 25 |
@Autowired |
22 |
private ProjectService projectService; |
|
23 |
|
|
24 |
@Autowired |
|
25 |
private AntiPatternService antiPatternService; |
|
26 |
DetectionService detectionService; |
|
26 | 27 |
|
27 | 28 |
@GetMapping("/list") |
28 | 29 |
public ResponseEntity<String> getAntipatternsAndProjects(){ |
29 | 30 |
//List<Project> projects = projectService.getAllProjects(); |
30 | 31 |
//List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()); |
31 | 32 |
//List<AntiPattern> antiPatterns = antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns()); |
32 |
return ResponseEntity.ok(new Gson().toJson( new Query(projectService.getAllProjects(), antiPatternService.antiPatternsToModel(antiPatternService.getAllAntiPatterns())))); |
|
33 |
Query query = detectionService.getAllProjectsAndAntipatterns(); |
|
34 |
return ResponseEntity.ok(new Gson().toJson(query)); |
|
33 | 35 |
} |
34 | 36 |
|
37 |
@PostMapping("/analyze") |
|
38 |
public ResponseEntity<String> detect(@RequestBody UserDetectionDto detectionRequest) { |
|
39 |
|
|
40 |
List<QueryResult> results = detectionService.analyze(detectionRequest); |
|
41 |
//Map<String, Map<String, String>> currentConfiguration = configurationService.getConfigurationByName(); |
|
42 |
return ResponseEntity.ok(new Gson().toJson(results)); |
|
43 |
|
|
44 |
} |
|
45 |
|
|
46 |
|
|
35 | 47 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java | ||
---|---|---|
24 | 24 |
"or config.id in (select userconfig.id.userId from UserConfigurationJoin userconfig where userconfig.id.userId = ?1)") |
25 | 25 |
List<Configuration> getAllUserConfigurations(int userId); |
26 | 26 |
|
27 |
|
|
28 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2 ")
|
|
27 |
//todo default user id parametrem |
|
28 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2") |
|
29 | 29 |
List<String> getAllUserConfigurationNames(int userId); |
30 | 30 |
|
31 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id = ?1") |
|
32 |
String findConfigurationByCompoundKey(UserConfigKey key); |
|
33 |
|
|
34 |
|
|
31 | 35 |
|
32 | 36 |
|
33 | 37 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigService.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service; |
|
2 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfiguration; |
|
5 |
import org.springframework.http.ResponseEntity; |
|
6 |
import java.util.List; |
|
7 |
public interface ConfigService { |
|
8 |
//upload configuration |
|
9 |
ResponseEntity<String> addConfiguration(Configuration cfg); |
|
10 |
ResponseEntity<String> addConfiguration(UserConfiguration cfg); |
|
11 |
|
|
12 |
ResponseEntity<String> pairConfigurationWithUser(User user, Configuration configuration); |
|
13 |
//get all configurations available to user |
|
14 |
ResponseEntity<String> getUserConfigurations(User user); |
|
15 |
|
|
16 |
List<String> getConfigurationNames(User user); |
|
17 |
|
|
18 |
Configuration getConfigurationById(int id); |
|
19 |
String getConfigurationName(int userId, int configurationId); |
|
20 |
|
|
21 |
|
|
22 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationService.java | ||
---|---|---|
1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.service; |
|
2 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
|
3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
|
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfiguration; |
|
5 |
import org.springframework.http.ResponseEntity; |
|
6 |
import java.util.List; |
|
7 |
public interface ConfigurationService { |
|
8 |
//upload configuration |
|
9 |
ResponseEntity<String> addConfiguration(Configuration cfg); |
|
10 |
ResponseEntity<String> addConfiguration(UserConfiguration cfg); |
|
11 |
|
|
12 |
ResponseEntity<String> pairConfigurationWithUser(User user, Configuration configuration); |
|
13 |
//get all configurations available to user |
|
14 |
ResponseEntity<String> getUserConfigurations(User user); |
|
15 |
|
|
16 |
List<String> getConfigurationNames(User user); |
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java | ||
---|---|---|
15 | 15 |
import java.util.Map; |
16 | 16 |
|
17 | 17 |
@Service |
18 |
public class ConfigurationServiceImplementation implements ConfigurationService{
|
|
18 |
public class ConfigurationServiceImplementation implements ConfigService {
|
|
19 | 19 |
//repository which represents connection to database and the configuration table in particular |
20 | 20 |
@Autowired |
21 | 21 |
private ConfigRepository configurationRepository; |
... | ... | |
133 | 133 |
List<String> configurationNames = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId()); |
134 | 134 |
return configurationNames; |
135 | 135 |
} |
136 |
|
|
137 |
@Override |
|
138 |
public Configuration getConfigurationById(int id) { |
|
139 |
return this.configurationRepository.findConfigurationById(id); |
|
140 |
} |
|
141 |
|
|
142 |
@Override |
|
143 |
public String getConfigurationName(int userId, int configurationId) { |
|
144 |
return this.configurationRepository.findConfigurationByCompoundKey(new UserConfigKey(userId, configurationId)); |
|
145 |
} |
|
136 | 146 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/utils/JSONBuilder.java | ||
---|---|---|
74 | 74 |
return json; |
75 | 75 |
} |
76 | 76 |
|
77 |
public static Map<String, Map<String, String>> createMapFromString(String jsonContent){ |
|
78 |
|
|
79 |
ConfigurationDto cfgDto = new Gson().fromJson(jsonContent, ConfigurationDto.class); |
|
80 |
|
|
81 |
Map<String, Map<String, String>> newAntiPatternMap = new HashMap<>(); |
|
82 |
|
|
83 |
for (AntiPatternDto antiPatternDto : cfgDto.getConfiguration()) { |
|
84 |
|
|
85 |
String antiPatternName = antiPatternDto.getAntiPattern(); |
|
86 |
|
|
87 |
Map<String, String> newThresholds = new HashMap<String, String>(); |
|
88 |
|
|
89 |
for (ThresholdDto thresholdDto : antiPatternDto.getThresholds()) { |
|
90 |
|
|
91 |
String thresholdName = thresholdDto.getThresholdName(); |
|
92 |
String value = thresholdDto.getValue(); |
|
93 |
|
|
94 |
newThresholds.put(thresholdName, value); |
|
95 |
} |
|
96 |
newAntiPatternMap.put(antiPatternName, newThresholds); |
|
97 |
|
|
98 |
} |
|
99 |
|
|
100 |
return newAntiPatternMap; |
|
101 |
} |
|
102 |
|
|
77 | 103 |
|
78 | 104 |
|
79 | 105 |
|
Také k dispozici: Unified diff
#10621 posílání výsledků detekce zpět na klienta