13 |
13 |
import org.springframework.beans.factory.annotation.Value;
|
14 |
14 |
import org.springframework.core.ParameterizedTypeReference;
|
15 |
15 |
import org.springframework.http.HttpEntity;
|
|
16 |
import org.springframework.http.HttpHeaders;
|
16 |
17 |
import org.springframework.http.HttpMethod;
|
17 |
18 |
import org.springframework.http.ResponseEntity;
|
18 |
19 |
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
|
... | ... | |
22 |
23 |
import org.springframework.web.bind.annotation.PathVariable;
|
23 |
24 |
import org.springframework.web.client.RestClientException;
|
24 |
25 |
import org.springframework.web.client.RestTemplate;
|
|
26 |
import org.springframework.web.util.UriComponents;
|
25 |
27 |
import org.springframework.web.util.UriComponentsBuilder;
|
26 |
28 |
|
27 |
29 |
import javax.annotation.PostConstruct;
|
... | ... | |
45 |
47 |
private static final org.apache.log4j.Logger LOGGER = org.apache.log4j.Logger
|
46 |
48 |
.getLogger(BrokerApiImpl.class);
|
47 |
49 |
|
|
50 |
private RestTemplate restTemplate = null;
|
48 |
51 |
|
|
52 |
private HttpHeaders httpHeaders;
|
|
53 |
|
49 |
54 |
private HashMap<String,Term> topics = new HashMap<String, Term>();
|
50 |
55 |
|
51 |
56 |
@PostConstruct
|
52 |
57 |
private void initDnetTopicsMap() {
|
53 |
58 |
|
|
59 |
restTemplate = new RestTemplate();
|
|
60 |
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
|
61 |
|
|
62 |
httpHeaders = new HttpHeaders();
|
|
63 |
httpHeaders.set("Content-Type", "application/json");
|
|
64 |
|
54 |
65 |
LOGGER.debug("Init dnet topics!");
|
55 |
66 |
InputStream is = null;
|
56 |
67 |
try {
|
... | ... | |
104 |
115 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service)
|
105 |
116 |
.queryParam("ds", datasourceName);
|
106 |
117 |
|
107 |
|
RestTemplate template = new RestTemplate();
|
108 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
109 |
118 |
ResponseEntity<List<BrowseEntry>> resp;
|
110 |
119 |
try {
|
111 |
|
resp = template.exchange(
|
|
120 |
resp = restTemplate.exchange(
|
112 |
121 |
builder.build().encode().toUri(),
|
113 |
122 |
HttpMethod.GET,
|
114 |
123 |
null,
|
... | ... | |
147 |
156 |
|
148 |
157 |
HttpEntity<AdvQueryObject> entity = new HttpEntity<>(advQueryObject, headers);
|
149 |
158 |
|
150 |
|
RestTemplate template = new RestTemplate();
|
151 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
152 |
159 |
ResponseEntity<EventsPage> resp;
|
153 |
160 |
try {
|
154 |
|
resp = template.exchange(
|
|
161 |
resp = restTemplate.exchange(
|
155 |
162 |
builder.buildAndExpand(uriParams).encode().toUri(),
|
156 |
163 |
HttpMethod.POST,
|
157 |
164 |
entity,
|
... | ... | |
231 |
238 |
.queryParam("topic", topic)
|
232 |
239 |
.queryParam("page", page);
|
233 |
240 |
|
234 |
|
//create new template engine
|
235 |
|
RestTemplate template = new RestTemplate();
|
236 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
237 |
241 |
ResponseEntity<EventsPage> resp;
|
238 |
242 |
try {
|
239 |
243 |
//communicate with endpoint
|
240 |
|
resp = template.exchange(
|
|
244 |
resp = restTemplate.exchange(
|
241 |
245 |
builder.build().encode().toUri(),
|
242 |
246 |
HttpMethod.GET,
|
243 |
247 |
null,
|
... | ... | |
259 |
263 |
.queryParam("email", userEmail);
|
260 |
264 |
|
261 |
265 |
//create new template engine
|
262 |
|
RestTemplate template = new RestTemplate();
|
263 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
264 |
266 |
ResponseEntity<Map<String, List<SimpleSubscriptionDesc>>> resp;
|
265 |
267 |
try {
|
266 |
268 |
//communicate with endpoint
|
267 |
|
resp = template.exchange(
|
|
269 |
resp = restTemplate.exchange(
|
268 |
270 |
builder.build().encode().toUri(),
|
269 |
271 |
HttpMethod.GET,
|
270 |
272 |
null,
|
... | ... | |
284 |
286 |
//build the uri params
|
285 |
287 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(openairePath + service);
|
286 |
288 |
|
287 |
|
//Header info
|
288 |
|
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
|
289 |
|
headers.add("Content-Type", "application/json");
|
290 |
|
HttpEntity<OpenaireSubscription> entity = new HttpEntity<>(obj, headers);
|
|
289 |
HttpEntity<OpenaireSubscription> entity = new HttpEntity<>(obj, httpHeaders);
|
291 |
290 |
|
292 |
291 |
//create new template engine
|
293 |
292 |
RestTemplate template = new RestTemplate();
|
... | ... | |
295 |
294 |
ResponseEntity<Subscription> resp;
|
296 |
295 |
try {
|
297 |
296 |
//communicate with endpoint
|
298 |
|
resp = template.exchange(
|
|
297 |
resp = restTemplate.exchange(
|
299 |
298 |
builder.build().encode().toUri(),
|
300 |
299 |
HttpMethod.POST,
|
301 |
300 |
entity,
|
... | ... | |
315 |
314 |
//build the uri params
|
316 |
315 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
|
317 |
316 |
|
318 |
|
//create new template engine
|
319 |
|
RestTemplate template = new RestTemplate();
|
320 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
321 |
317 |
try {
|
322 |
318 |
//communicate with endpoint
|
323 |
|
template.exchange(
|
|
319 |
restTemplate.exchange(
|
324 |
320 |
builder.build().encode().toUri(),
|
325 |
321 |
HttpMethod.DELETE,
|
326 |
322 |
null,
|
... | ... | |
338 |
334 |
//build the uri params
|
339 |
335 |
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(apiPath + service);
|
340 |
336 |
|
341 |
|
//create new template engine
|
342 |
|
RestTemplate template = new RestTemplate();
|
343 |
|
template.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
|
344 |
337 |
ResponseEntity<Subscription> resp;
|
345 |
338 |
try {
|
346 |
339 |
//communicate with endpoint
|
347 |
|
resp = template.exchange(
|
|
340 |
resp = restTemplate.exchange(
|
348 |
341 |
builder.build().encode().toUri(),
|
349 |
342 |
HttpMethod.GET,
|
350 |
343 |
null,
|
... | ... | |
361 |
354 |
return topics;
|
362 |
355 |
}
|
363 |
356 |
|
|
357 |
@Override
|
|
358 |
public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
|
|
359 |
@PathVariable("page") String page,
|
|
360 |
@PathVariable("size") String size
|
|
361 |
) throws BrokerException {
|
364 |
362 |
|
|
363 |
UriComponents uriComponents = UriComponentsBuilder
|
|
364 |
.fromHttpUrl(apiPath + "/openaireBroker/notifications/")
|
|
365 |
.path("/{id}/{page}/{size}/")
|
|
366 |
.build().expand(subscriptionId,page, size).encode();
|
|
367 |
|
|
368 |
ResponseEntity<EventsPage> resp;
|
|
369 |
try {
|
|
370 |
resp = restTemplate.exchange(
|
|
371 |
uriComponents.toUri(),
|
|
372 |
HttpMethod.GET,
|
|
373 |
null,
|
|
374 |
new ParameterizedTypeReference<EventsPage>() {
|
|
375 |
});
|
|
376 |
} catch (RestClientException e) {
|
|
377 |
throw new BrokerException(e);
|
|
378 |
}
|
|
379 |
return resp.getBody();
|
|
380 |
}
|
|
381 |
|
|
382 |
|
365 |
383 |
}
|
1. Add a get notifications method by subscription id