Revize b84f8085
Přidáno uživatelem Václav Hrabík před více než 1 rok
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/controller/ConfigurationController.java | ||
---|---|---|
49 | 49 |
* 500 if db server died or no default configurations are present in the database |
50 | 50 |
*/ |
51 | 51 |
@PostMapping(value="/configuration") |
52 |
public ResponseEntity<String> getUserConfigurations(@RequestBody User user) {
|
|
52 |
public ResponseEntity<String> getConfiguration(@RequestBody UserConfiguration userConfiguration) {
|
|
53 | 53 |
Map<String, Object> json = new HashMap<>(); |
54 |
List<Configuration> configuration = this.configurationService.getUserConfigurations(user); |
|
55 |
//this can only happen if db server is offline |
|
56 |
//or no default configuration exists in database |
|
57 |
if(configuration == null) { |
|
54 |
// Configuration config = this.configurationService.getConfigurationById(Integer.parseInt(userConfiguration.getId())); |
|
55 |
|
|
56 |
Configuration config = this.configurationService.getConfiguration(userConfiguration.getUser().getName(), Integer.parseInt(userConfiguration.getId())); |
|
57 |
|
|
58 |
if(config == null) { |
|
58 | 59 |
json.put("message", "internal sever error"); |
59 | 60 |
return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
60 | 61 |
} |
61 |
//list of configuration definitions |
|
62 |
List<String> configurationDefinition = new ArrayList<>(); |
|
63 |
//and their names |
|
64 |
List<String> configurationNames = new ArrayList<>(); |
|
65 |
//hipster syntax for Petr |
|
66 |
configuration.forEach(cfg -> { |
|
67 |
configurationDefinition.add(cfg.getConfig()); |
|
68 |
configurationNames.add(cfg.getConfigurationName()); |
|
69 |
}); |
|
70 |
json.put("configuration",configurationDefinition); |
|
71 |
json.put("configuration_names",configurationNames); |
|
62 |
|
|
63 |
json.put("configuration", config.getConfig()); |
|
72 | 64 |
|
73 | 65 |
return new ResponseEntity<>(new Gson().toJson(json),HttpStatus.OK); |
66 |
|
|
67 |
// List<Configuration> configuration = this.configurationService.getUserConfigurations(user); |
|
68 |
// //this can only happen if db server is offline |
|
69 |
// //or no default configuration exists in database |
|
70 |
// if(configuration == null) { |
|
71 |
// json.put("message", "internal sever error"); |
|
72 |
// return new ResponseEntity<>(JSONBuilder.buildJSON(json), HttpStatus.INTERNAL_SERVER_ERROR); |
|
73 |
// } |
|
74 |
// //list of configuration definitions |
|
75 |
// List<String> configurationDefinition = new ArrayList<>(); |
|
76 |
// //and their names |
|
77 |
// List<String> configurationNames = new ArrayList<>(); |
|
78 |
// //hipster syntax for Petr |
|
79 |
// configuration.forEach(cfg -> { |
|
80 |
// configurationDefinition.add(cfg.getConfig()); |
|
81 |
// configurationNames.add(cfg.getConfigurationName()); |
|
82 |
// }); |
|
83 |
// json.put("configuration",configurationDefinition); |
|
84 |
// json.put("configuration_names",configurationNames); |
|
85 |
// |
|
86 |
// return new ResponseEntity<>(new Gson().toJson(json),HttpStatus.OK); |
|
74 | 87 |
} |
75 | 88 |
|
76 | 89 |
/** |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/Configuration.java | ||
---|---|---|
35 | 35 |
this.id = id; |
36 | 36 |
} |
37 | 37 |
|
38 |
public Configuration(String config) { |
|
39 |
this.config = config; |
|
40 |
} |
|
41 |
|
|
38 | 42 |
public Configuration(String config, String isDefault, String configurationName, String defaultConfigName) { |
39 | 43 |
this.config = config; |
40 | 44 |
this.configHash = null; |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/model/UserConfiguration.java | ||
---|---|---|
11 | 11 |
private String isDefault; |
12 | 12 |
private String configurationName; |
13 | 13 |
|
14 |
private String id; |
|
15 |
|
|
14 | 16 |
public UserConfiguration(User user, ConfigurationDto configuration, String isDefault, String configurationName) { |
15 | 17 |
this.user = user; |
16 | 18 |
this.configuration = configuration; |
17 | 19 |
this.isDefault = isDefault; |
18 | 20 |
this.configurationName = configurationName; |
21 |
this.id = null; |
|
19 | 22 |
} |
20 | 23 |
public UserConfiguration(){} |
21 | 24 |
|
25 |
public UserConfiguration(User user, String id) { |
|
26 |
this.user = user; |
|
27 |
this.configuration = null; |
|
28 |
this.configurationName = null; |
|
29 |
this.isDefault = null; |
|
30 |
this.id = id; |
|
31 |
} |
|
32 |
|
|
22 | 33 |
|
23 | 34 |
public User getUser() { |
24 | 35 |
return this.user; |
... | ... | |
51 | 62 |
public void setConfigurationName(String configurationName) { |
52 | 63 |
this.configurationName = configurationName; |
53 | 64 |
} |
65 |
|
|
66 |
public String getId() { |
|
67 |
return id; |
|
68 |
} |
|
69 |
|
|
70 |
public void setId(String id) { |
|
71 |
this.id = id; |
|
72 |
} |
|
54 | 73 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/repository/ConfigRepository.java | ||
---|---|---|
1 | 1 |
package cz.zcu.fav.kiv.antipatterndetectionapp.v2.repository; |
2 | 2 |
|
3 | 3 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.Configuration; |
4 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.User; |
|
4 | 5 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigKey; |
5 | 6 |
import cz.zcu.fav.kiv.antipatterndetectionapp.v2.model.UserConfigurationJoin; |
6 | 7 |
import org.springframework.beans.factory.annotation.Value; |
... | ... | |
28 | 29 |
|
29 | 30 |
@Query("select userconfig.configurationName from UserConfigurationJoin userconfig where userconfig.id = ?1") |
30 | 31 |
String findConfigurationByCompoundKey(UserConfigKey key); |
32 |
|
|
33 |
@Query("SELECT \n" + |
|
34 |
"cfg.config \n" + |
|
35 |
"FROM \n" + |
|
36 |
"UserConfigurationJoin userconfig INNER JOIN Configuration cfg \n" + |
|
37 |
"ON userconfig.id.configId = cfg.id\n" + |
|
38 |
"WHERE\n" + |
|
39 |
"userconfig.id = ?1") |
|
40 |
Configuration findConfigurationByUserNameAndID(UserConfigKey key); |
|
31 | 41 |
} |
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigService.java | ||
---|---|---|
16 | 16 |
List<Configuration> getUserConfigurations(User user); |
17 | 17 |
|
18 | 18 |
Configuration getConfigurationById(int id); |
19 |
|
|
20 |
public Configuration getConfiguration(String userName, int id); |
|
19 | 21 |
String getConfigurationName(int userId, int configurationId); |
20 | 22 |
|
21 | 23 |
|
src/main/java/cz/zcu/fav/kiv/antipatterndetectionapp/v2/service/configuration/ConfigurationServiceImplementation.java | ||
---|---|---|
153 | 153 |
return this.configurationRepository.findConfigurationById(id); |
154 | 154 |
} |
155 | 155 |
|
156 |
public Configuration getConfiguration(String userName, int id) { |
|
157 |
User user = this.userService.getUserByName(userName); |
|
158 |
UserConfigKey key = new UserConfigKey(user.getId(), id); |
|
159 |
Configuration configuration = this.configurationRepository.findConfigurationByUserNameAndID(key); |
|
160 |
return configuration; |
|
161 |
} |
|
162 |
|
|
156 | 163 |
@Override |
157 | 164 |
public String getConfigurationName(int userId, int configurationId) { |
158 | 165 |
return this.configurationRepository.findConfigurationByCompoundKey(new UserConfigKey(userId, configurationId)); |
Také k dispozici: Unified diff
https://kivprogrammers.atlassian.net/browse/TSP2-30 připrava backendu stránky configuration