Revize 2cb88500
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 | ||
---|---|---|
8 | 8 |
import org.springframework.http.ResponseEntity; |
9 | 9 |
import org.springframework.web.bind.annotation.*; |
10 | 10 |
|
11 |
import java.util.ArrayList; |
|
11 | 12 |
import java.util.HashMap; |
12 | 13 |
import java.util.List; |
13 | 14 |
import java.util.Map; |
... | ... | |
37 | 38 |
@PostMapping(value="/configuration_name") |
38 | 39 |
public ResponseEntity<String> getConfigurationNames(@RequestBody User user) { |
39 | 40 |
Map<String, Object> json = new HashMap<>(); |
40 |
List<String> configuration = this.configurationService.getConfigurationNames(user);
|
|
41 |
List<Object[]> configuration = this.configurationService.getConfigurationNamesAndIds(user);
|
|
41 | 42 |
if(configuration == null) { |
42 | 43 |
json.put("message", "internal sever error"); |
43 | 44 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
44 | 45 |
} |
46 |
List<String> configurationNames = new ArrayList<>(); |
|
47 |
List<Integer> configurationIds = new ArrayList<>(); |
|
48 |
for(Object[] o : configuration){ |
|
49 |
String name = (String) o[0]; |
|
50 |
int id = (int) o[1]; |
|
51 |
configurationNames.add(name); |
|
52 |
configurationIds.add(id); |
|
53 |
} |
|
45 | 54 |
json.put("message", "ok"); |
46 |
json.put("configuration_names", configuration); |
|
55 |
json.put("configuration_names", configurationNames); |
|
56 |
json.put("configuration_ids", configurationIds); |
|
57 |
|
|
47 | 58 |
String jsonString = JSONBuilder.buildJSON(json); |
48 | 59 |
return new ResponseEntity<>(jsonString, HttpStatus.OK); |
49 | 60 |
} |
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 com.google.gson.JsonElement; |
|
5 |
import com.google.gson.JsonObject; |
|
4 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.detecting.AntiPatternManager; |
5 | 7 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.AntiPattern; |
6 | 8 |
import cz.zcu.fav.kiv.antipatterndetectionapp.model.Project; |
... | ... | |
16 | 18 |
import org.springframework.http.ResponseEntity; |
17 | 19 |
import org.springframework.web.bind.annotation.*; |
18 | 20 |
|
21 |
import java.util.HashMap; |
|
19 | 22 |
import java.util.List; |
20 | 23 |
import java.util.Map; |
21 | 24 |
|
... | ... | |
36 | 39 |
|
37 | 40 |
@PostMapping("/analyze") |
38 | 41 |
public ResponseEntity<String> detect(@RequestBody UserDetectionDto detectionRequest) { |
39 |
|
|
42 |
final String[] projects = detectionRequest.getSelectedProjects(); |
|
43 |
if(projects == null ||projects.length == 0){ |
|
44 |
return sendDetectionBadRequest("No projects provided in request"); |
|
45 |
} |
|
46 |
final String[] patterns = detectionRequest.getSelectedAntipatterns(); |
|
47 |
if(patterns == null ||patterns.length == 0){ |
|
48 |
return sendDetectionBadRequest("No antipatterns provided in request"); |
|
49 |
} |
|
40 | 50 |
List<QueryResult> results = detectionService.analyze(detectionRequest); |
41 | 51 |
//Map<String, Map<String, String>> currentConfiguration = configurationService.getConfigurationByName(); |
42 | 52 |
return ResponseEntity.ok(new Gson().toJson(results)); |
53 |
} |
|
54 |
|
|
43 | 55 |
|
56 |
private ResponseEntity<String> sendDetectionBadRequest(String message){ |
|
57 |
Map<String,String> error = new HashMap<>(); |
|
58 |
error.put("message",message); |
|
59 |
return new ResponseEntity<>(new Gson().toJson(error), HttpStatus.BAD_REQUEST); |
|
44 | 60 |
} |
45 | 61 |
|
46 | 62 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfigurationJoin.java | ||
---|---|---|
20 | 20 |
public UserConfigurationJoin(){ |
21 | 21 |
} |
22 | 22 |
|
23 |
|
|
24 | 23 |
public UserConfigurationJoin(UserConfigKey id, String configurationName){ |
25 | 24 |
this.configurationName = configurationName; |
26 | 25 |
this.id = id; |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java | ||
---|---|---|
2 | 2 |
|
3 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
4 | 4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigKey; |
5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigurationJoin; |
|
5 | 6 |
import org.springframework.beans.factory.annotation.Value; |
6 | 7 |
import org.springframework.data.jpa.repository.JpaRepository; |
7 | 8 |
import org.springframework.data.jpa.repository.Modifying; |
... | ... | |
25 | 26 |
List<Configuration> getAllUserConfigurations(int userId); |
26 | 27 |
|
27 | 28 |
//todo default user id parametrem |
28 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2") |
|
29 |
List<String> getAllUserConfigurationNames(int userId);
|
|
29 |
@Query("select userconfig.configurationName,userconfig.id.configId from UserConfigurationJoin userconfig where userconfig.id.userId = ?1 or userconfig.id.userId=2")
|
|
30 |
List<Object[]> getAllUserConfigurationNames(int userId);
|
|
30 | 31 |
|
31 | 32 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id = ?1") |
32 | 33 |
String findConfigurationByCompoundKey(UserConfigKey key); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigService.java | ||
---|---|---|
13 | 13 |
//get all configurations available to user |
14 | 14 |
ResponseEntity<String> getUserConfigurations(User user); |
15 | 15 |
|
16 |
List<String> getConfigurationNames(User user);
|
|
16 |
List<Object[]> getConfigurationNamesAndIds(User user);
|
|
17 | 17 |
|
18 | 18 |
Configuration getConfigurationById(int id); |
19 | 19 |
String getConfigurationName(int userId, int configurationId); |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/ConfigurationServiceImplementation.java | ||
---|---|---|
121 | 121 |
} |
122 | 122 |
|
123 | 123 |
@Override |
124 |
public List<String> getConfigurationNames(User user) {
|
|
124 |
public List<Object[]> getConfigurationNamesAndIds(User user) {
|
|
125 | 125 |
final String userName = user.getName(); |
126 | 126 |
if(userName == null){ |
127 | 127 |
return null; |
... | ... | |
130 | 130 |
User userInfo = this.userService.getUserByName(userName); |
131 | 131 |
//fetch all configurations this particular user can see |
132 | 132 |
//ie all public configs + configurations uploaded by this particular user |
133 |
List<String> configurationNames = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId());
|
|
134 |
return configurationNames;
|
|
133 |
List<Object[]> configurations = this.configurationRepository.getAllUserConfigurationNames(userInfo.getId());
|
|
134 |
return configurations; |
|
135 | 135 |
} |
136 | 136 |
|
137 | 137 |
@Override |
Také k dispozici: Unified diff
#10621 osetreni empty array z detekce