Revision 50862
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; |
|
11 | 10 |
import org.json.JSONException; |
12 | 11 |
import org.json.JSONObject; |
13 | 12 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
22 | 21 |
import org.springframework.util.LinkedMultiValueMap; |
23 | 22 |
import org.springframework.util.MultiValueMap; |
24 | 23 |
import org.springframework.web.bind.annotation.PathVariable; |
25 |
import org.springframework.web.bind.annotation.RequestBody; |
|
26 |
import org.springframework.web.bind.annotation.RequestParam; |
|
27 | 24 |
import org.springframework.web.client.RestClientException; |
28 | 25 |
import org.springframework.web.client.RestTemplate; |
29 | 26 |
import org.springframework.web.util.UriComponents; |
... | ... | |
86 | 83 |
|
87 | 84 |
|
88 | 85 |
@Override |
89 |
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user") |
|
90 |
@ApiParam(value = "User email", required = true) String user, |
|
91 |
@RequestParam("includeShared") |
|
92 |
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared, |
|
93 |
@RequestParam("includeByOthers") |
|
94 |
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException { |
|
86 |
public DatasourcesBroker getDatasourcesOfUser(String params) throws JSONException { |
|
87 |
JSONObject json_params = new JSONObject(params); |
|
88 |
DatasourcesBroker ret = new DatasourcesBroker(); |
|
95 | 89 |
|
96 |
DatasourcesBroker ret = new DatasourcesBroker(); |
|
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 |
|
|
97 | 94 |
try { |
98 |
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(user))); |
|
99 |
//TODO fix bug when values are true
|
|
100 |
if (Boolean.parseBoolean(includeShared)) {
|
|
95 |
ret.setDatasourcesOfUser(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
|
|
96 |
if (includeShared) {
|
|
97 |
//TODO whatever nikonas was saying
|
|
101 | 98 |
List<String> sharedDatasourceIds = new ArrayList<String>(); |
102 | 99 |
ret.setSharedDatasources(getDatasourcesOfUserType(getRepositoriesByIds(sharedDatasourceIds))); |
103 | 100 |
} |
104 | 101 |
|
105 |
if (Boolean.parseBoolean(includeByOthers)) {
|
|
106 |
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(user))); |
|
102 |
if (includeByOthers) {
|
|
103 |
ret.setDatasourcesOfOthers(getDatasourcesOfUserType(getRepositoriesOfUser(userEmail)));
|
|
107 | 104 |
} |
108 | 105 |
} catch (BrokerException e) { |
109 | 106 |
e.printStackTrace(); |
... | ... | |
135 | 132 |
} |
136 | 133 |
|
137 | 134 |
@Override |
138 |
public EventsPage advancedShowEvents(@PathVariable("page") String page, |
|
139 |
@PathVariable("size") String size, |
|
140 |
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException { |
|
135 |
public EventsPage advancedShowEvents(String params) throws BrokerException, JSONException ,IOException { |
|
136 |
JSONObject json_params = new JSONObject(params); |
|
141 | 137 |
|
138 |
String page = json_params.getString("page"); |
|
139 |
String pagesize = json_params.getString("pagesize"); |
|
140 |
String json_advQueryObject = json_params.getString("advQueryObject"); |
|
141 |
|
|
142 |
ObjectMapper mapper = new ObjectMapper(); |
|
143 |
AdvQueryObject advQueryObject = mapper.readValue(json_advQueryObject, AdvQueryObject.class); |
|
144 |
|
|
142 | 145 |
final String service = "/events/{page}/{pageSize}"; |
143 | 146 |
|
144 | 147 |
Map<String, Long> uriParams = new HashMap<>(); |
145 | 148 |
uriParams.put("page", Long.parseLong(page)); |
146 |
uriParams.put("pageSize", Long.parseLong(size)); |
|
149 |
uriParams.put("pageSize", Long.parseLong(pagesize));
|
|
147 | 150 |
|
148 | 151 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service); |
149 | 152 |
|
150 | 153 |
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>(); |
154 |
headers.add("Content-Type", "application/json"); |
|
155 |
|
|
151 | 156 |
advQueryObject.setPage(Long.parseLong(page)); |
152 |
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, httpHeaders); |
|
157 |
|
|
158 |
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers); |
|
159 |
|
|
153 | 160 |
ResponseEntity<EventsPage> resp; |
154 | 161 |
try { |
155 | 162 |
resp = restTemplate.exchange( |
... | ... | |
216 | 223 |
} |
217 | 224 |
|
218 | 225 |
@Override |
219 |
public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName, |
|
220 |
@RequestParam("topic") String topic, |
|
221 |
@RequestParam("page") String page, |
|
222 |
@RequestParam("size") String size) throws BrokerException, JSONException { |
|
226 |
public EventsPage showEvents(String params) throws BrokerException, JSONException { |
|
223 | 227 |
|
224 |
final String service = "/events";
|
|
228 |
JSONObject json_params = new JSONObject(params);
|
|
225 | 229 |
|
230 |
String datasourceName = json_params.getString("datasourceName"); |
|
231 |
String topic = json_params.getString("topic"); |
|
232 |
String page = json_params.getString("page"); |
|
233 |
|
|
234 |
final String service = "/showEvents"; |
|
235 |
|
|
236 |
//build the uri params |
|
226 | 237 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) |
227 | 238 |
.queryParam("ds", datasourceName) |
228 | 239 |
.queryParam("topic", topic) |
229 |
.path("/{page}/{size}/");
|
|
240 |
.queryParam("page", page);
|
|
230 | 241 |
|
231 | 242 |
ResponseEntity<EventsPage> resp; |
232 | 243 |
try { |
244 |
//communicate with endpoint |
|
233 | 245 |
resp = restTemplate.exchange( |
234 |
builder.build().expand(page, size).encode().toUri(),
|
|
246 |
builder.build().encode().toUri(), |
|
235 | 247 |
HttpMethod.GET, |
236 | 248 |
null, |
237 | 249 |
new ParameterizedTypeReference<EventsPage>() { |
... | ... | |
243 | 255 |
} |
244 | 256 |
|
245 | 257 |
@Override |
246 |
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) |
|
247 |
throws BrokerException { |
|
258 |
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException { |
|
248 | 259 |
|
249 | 260 |
final String service = "/subscriptions"; |
250 | 261 |
|
262 |
//build the uri params |
|
251 | 263 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service) |
252 | 264 |
.queryParam("email", userEmail); |
253 | 265 |
|
254 |
LOGGER.debug(builder.build().encode().toUri());
|
|
266 |
//create new template engine
|
|
255 | 267 |
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp; |
256 | 268 |
try { |
269 |
//communicate with endpoint |
|
257 | 270 |
resp = restTemplate.exchange( |
258 | 271 |
builder.build().encode().toUri(), |
259 | 272 |
HttpMethod.GET, |
... | ... | |
268 | 281 |
} |
269 | 282 |
|
270 | 283 |
@Override |
271 |
public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException {
|
|
284 |
public Subscription subscribe(OpenaireSubscription obj) throws BrokerException { |
|
272 | 285 |
final String service = "/subscribe"; |
273 | 286 |
|
274 | 287 |
//build the uri params |
Also available in: Unified diff
Moving branch folders to trunk.