Revision 50686
Added by Panagiotis Kanakakis about 6 years ago
BrokerApiImpl.java | ||
---|---|---|
7 | 7 |
import eu.dnetlib.repo.manager.shared.Term; |
8 | 8 |
import eu.dnetlib.repo.manager.shared.Tuple; |
9 | 9 |
import eu.dnetlib.repo.manager.shared.broker.*; |
10 |
import io.swagger.annotations.ApiParam; |
|
10 | 11 |
import org.json.JSONException; |
11 | 12 |
import org.json.JSONObject; |
12 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
21 | 22 |
import org.springframework.util.LinkedMultiValueMap; |
22 | 23 |
import org.springframework.util.MultiValueMap; |
23 | 24 |
import org.springframework.web.bind.annotation.PathVariable; |
25 |
import org.springframework.web.bind.annotation.RequestParam; |
|
24 | 26 |
import org.springframework.web.client.RestClientException; |
25 | 27 |
import org.springframework.web.client.RestTemplate; |
26 | 28 |
import org.springframework.web.util.UriComponents; |
... | ... | |
83 | 85 |
|
84 | 86 |
|
85 | 87 |
@Override |
86 |
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException { |
|
87 |
JSONObject json_params = new JSONObject(params); |
|
88 |
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user") @ApiParam(value = "User email", required = true) String user, |
|
89 |
@RequestParam("includeShared") |
|
90 |
@ApiParam(value = "Include shared datasources", required = true) String includeShared, |
|
91 |
@RequestParam("includeByOthers") @ApiParam(value = "Include datasources of other", required = true) String includeByOthers) throws JSONException { |
|
92 |
|
|
88 | 93 |
DatasourcesBroker ret = new DatasourcesBroker(); |
89 |
|
|
90 |
String userEmail = json_params.getString("userEmail"); |
|
91 |
boolean includeShared = Boolean.parseBoolean( json_params.getString("includeShared") ); |
|
92 |
boolean includeByOthers = Boolean.parseBoolean( json_params.getString("includeByOthers") ); |
|
93 |
|
|
94 | 94 |
try { |
95 |
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
|
|
96 |
if (includeShared) {
|
|
95 |
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user))); |
|
96 |
if (Boolean.parseBoolean(includeShared)) {
|
|
97 | 97 |
//TODO whatever nikonas was saying |
98 | 98 |
List<String> sharedDatasourceIds = new ArrayList<String>(); |
99 | 99 |
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds))); |
100 | 100 |
} |
101 | 101 |
|
102 |
if (includeByOthers) {
|
|
103 |
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
|
|
102 |
if (Boolean.parseBoolean(includeByOthers)) {
|
|
103 |
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user))); |
|
104 | 104 |
} |
105 | 105 |
} catch (BrokerException e) { |
106 | 106 |
e.printStackTrace(); |
... | ... | |
251 | 251 |
} |
252 | 252 |
|
253 | 253 |
@Override |
254 |
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException { |
|
254 |
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser( String userEmail) |
|
255 |
throws BrokerException { |
|
255 | 256 |
|
256 | 257 |
final String service = "/subscriptions"; |
257 | 258 |
|
258 |
//build the uri params |
|
259 | 259 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) |
260 | 260 |
.queryParam("email", userEmail); |
261 | 261 |
|
262 |
//create new template engine
|
|
262 |
LOGGER.debug(builder.build().encode().toUri());
|
|
263 | 263 |
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp; |
264 | 264 |
try { |
265 |
//communicate with endpoint |
|
266 | 265 |
resp = restTemplate.exchange( |
267 | 266 |
builder.build().encode().toUri(), |
268 | 267 |
HttpMethod.GET, |
Also available in: Unified diff
1. Add swagger explanation for broker/validator paramaters
2. Change subscribe/unsubcribe methods of broker from GET to POST