1
|
package eu.dnetlib.repo.manager.controllers;
|
2
|
|
3
|
import eu.dnetlib.repo.manager.domain.BrokerException;
|
4
|
import eu.dnetlib.repo.manager.domain.Term;
|
5
|
import eu.dnetlib.repo.manager.domain.broker.*;
|
6
|
import eu.dnetlib.repo.manager.service.BrokerServiceImpl;
|
7
|
import io.swagger.annotations.Api;
|
8
|
import io.swagger.annotations.ApiParam;
|
9
|
import org.json.JSONException;
|
10
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.http.MediaType;
|
13
|
import org.springframework.http.ResponseEntity;
|
14
|
import org.springframework.security.access.prepost.PreAuthorize;
|
15
|
import org.springframework.security.core.context.SecurityContextHolder;
|
16
|
import org.springframework.web.bind.annotation.*;
|
17
|
|
18
|
import java.io.IOException;
|
19
|
import java.util.List;
|
20
|
import java.util.Map;
|
21
|
|
22
|
@RestController
|
23
|
@RequestMapping(value = "/broker")
|
24
|
@Api(description = "Broker API", tags = {"broker"})
|
25
|
public class BrokerController{
|
26
|
|
27
|
@Autowired
|
28
|
private BrokerServiceImpl brokerService;
|
29
|
|
30
|
@RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
|
31
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
32
|
@ResponseBody
|
33
|
@PreAuthorize("hasRole('ROLE_USER')")
|
34
|
public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
|
35
|
@ApiParam(value = "User email", required = true) String user,
|
36
|
@RequestParam("includeShared")
|
37
|
@ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
|
38
|
@RequestParam("includeByOthers")
|
39
|
@ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
|
40
|
user = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
41
|
return brokerService.getDatasourcesOfUser(user, includeShared, includeByOthers);
|
42
|
}
|
43
|
|
44
|
@RequestMapping(value = "/getTopicsForDatasource/{datasourceName:.+}" ,
|
45
|
method = RequestMethod.GET,
|
46
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
47
|
@ResponseBody
|
48
|
public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName") String datasourceName) throws BrokerException{
|
49
|
return brokerService.getTopicsForDatasource(datasourceName);
|
50
|
}
|
51
|
|
52
|
@RequestMapping(value = "/advancedShowEvents/{page}/{size}" ,
|
53
|
method = RequestMethod.POST,
|
54
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
55
|
@ResponseBody
|
56
|
@PreAuthorize("hasRole('ROLE_USER')")
|
57
|
public EventsPage advancedShowEvents(@PathVariable("page") String page,
|
58
|
@PathVariable("size") String size,
|
59
|
@RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{
|
60
|
return brokerService.advancedShowEvents(page, size, advQueryObject);
|
61
|
}
|
62
|
|
63
|
@RequestMapping(value = "/showEvents/{datasourceName:.+}/{topic}/{page}" ,
|
64
|
method = RequestMethod.GET,
|
65
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
66
|
@ResponseBody
|
67
|
@PreAuthorize("hasRole('ROLE_USER')")
|
68
|
public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
|
69
|
@RequestParam("topic") String topic,
|
70
|
@RequestParam("page") String page,
|
71
|
@RequestParam("size") String size) throws BrokerException, JSONException{
|
72
|
return brokerService.showEvents(datasourceName, topic, page, size);
|
73
|
}
|
74
|
|
75
|
@RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" ,
|
76
|
method = RequestMethod.GET,
|
77
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
78
|
@ResponseBody
|
79
|
@PreAuthorize("hasRole('ROLE_USER')")
|
80
|
public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail") String userEmail) throws BrokerException{
|
81
|
userEmail = ((OIDCAuthenticationToken) SecurityContextHolder.getContext().getAuthentication()).getUserInfo().getEmail();
|
82
|
return brokerService.getSimpleSubscriptionsOfUser(userEmail);
|
83
|
}
|
84
|
|
85
|
@RequestMapping(value = "/subscribe" , method = RequestMethod.POST,
|
86
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
87
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
88
|
@ResponseBody
|
89
|
@PreAuthorize("hasRole('ROLE_USER') ")
|
90
|
public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{
|
91
|
return brokerService.subscribe(obj);
|
92
|
}
|
93
|
|
94
|
@RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,
|
95
|
consumes = MediaType.APPLICATION_JSON_VALUE,
|
96
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
97
|
@ResponseBody
|
98
|
@PreAuthorize("hasRole('ROLE_USER')")
|
99
|
public ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
|
100
|
return brokerService.unsubscribe(subscriptionId);
|
101
|
}
|
102
|
|
103
|
@RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,
|
104
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
105
|
@ResponseBody
|
106
|
@PreAuthorize("hasRole('ROLE_USER')")
|
107
|
public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
|
108
|
return brokerService.getSubscription(subscriptionId);
|
109
|
}
|
110
|
|
111
|
|
112
|
@RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,
|
113
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
114
|
@ResponseBody
|
115
|
public Map<String, Term> getDnetTopics() throws BrokerException{
|
116
|
return brokerService.getDnetTopics();
|
117
|
}
|
118
|
|
119
|
@RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
|
120
|
,produces = MediaType.APPLICATION_JSON_VALUE)
|
121
|
@ResponseBody
|
122
|
@PreAuthorize("hasRole('ROLE_USER')")
|
123
|
public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
|
124
|
@PathVariable("page") String page,
|
125
|
@PathVariable("size") String size) throws BrokerException{
|
126
|
return brokerService.getNotificationsBySubscriptionId(subscriptionId, page, size);
|
127
|
}
|
128
|
|
129
|
}
|