Project

General

Profile

1
package eu.dnetlib.repo.manager.controllers;
2

    
3
import eu.dnetlib.repo.manager.service.BrokerServiceImpl;
4
import eu.dnetlib.repo.manager.domain.BrokerException;
5
import eu.dnetlib.repo.manager.domain.Term;
6
import eu.dnetlib.repo.manager.domain.broker.*;
7
import io.swagger.annotations.Api;
8
import io.swagger.annotations.ApiParam;
9
import org.json.JSONException;
10
import org.springframework.beans.factory.annotation.Autowired;
11
import org.springframework.http.MediaType;
12
import org.springframework.http.ResponseEntity;
13
import org.springframework.security.access.prepost.PreAuthorize;
14
import org.springframework.web.bind.annotation.*;
15

    
16
import java.io.IOException;
17
import java.util.List;
18
import java.util.Map;
19

    
20
@RestController
21
@RequestMapping(value = "/broker")
22
@Api(description = "Broker API",  tags = {"broker"})
23
public class BrokerController{
24

    
25
    @Autowired
26
    private BrokerServiceImpl brokerService;
27

    
28
    @RequestMapping(value = "/getDatasourcesOfUser" , method = RequestMethod.GET,
29
            produces = MediaType.APPLICATION_JSON_VALUE)
30
    @ResponseBody
31
    @PreAuthorize("hasRole('ROLE_USER')")
32
    public DatasourcesBroker getDatasourcesOfUser(@RequestParam("user")
33
                                           @ApiParam(value = "User email", required = true) String user,
34
                                           @RequestParam("includeShared")
35
                                           @ApiParam(value = "Include shared datasources", required = true , defaultValue = "false") String includeShared,
36
                                           @RequestParam("includeByOthers")
37
                                           @ApiParam(value = "Include datasources of other", required = true,defaultValue = "false") String includeByOthers) throws JSONException {
38
        return brokerService.getDatasourcesOfUser(user, includeShared, includeByOthers);
39
    }
40

    
41
    @RequestMapping(value = "/getTopicsForDatasource/{datasourceName:.+}" ,
42
            method = RequestMethod.GET,
43
            produces = MediaType.APPLICATION_JSON_VALUE)
44
    @ResponseBody
45
    public List<BrowseEntry> getTopicsForDatasource(@PathVariable("datasourceName")  String datasourceName) throws BrokerException{
46
        return brokerService.getTopicsForDatasource(datasourceName);
47
    }
48

    
49
    @RequestMapping(value = "/advancedShowEvents/{page}/{size}" ,
50
            method = RequestMethod.POST,
51
            produces = MediaType.APPLICATION_JSON_VALUE)
52
    @ResponseBody
53
    @PreAuthorize("hasRole('ROLE_USER')")
54
    public EventsPage advancedShowEvents(@PathVariable("page") String page,
55
                                  @PathVariable("size") String size,
56
                                  @RequestBody AdvQueryObject advQueryObject) throws BrokerException, JSONException ,IOException{
57
        return brokerService.advancedShowEvents(page, size, advQueryObject);
58
    }
59

    
60
    @RequestMapping(value = "/showEvents/{datasourceName:.+}/{topic}/{page}" ,
61
            method = RequestMethod.GET,
62
            produces = MediaType.APPLICATION_JSON_VALUE)
63
    @ResponseBody
64
    @PreAuthorize("hasRole('ROLE_USER')")
65
    public EventsPage showEvents(@RequestParam("datasourceName") String datasourceName,
66
                          @RequestParam("topic") String topic,
67
                          @RequestParam("page") String page,
68
                          @RequestParam("size") String size) throws BrokerException, JSONException{
69
        return brokerService.showEvents(datasourceName, topic, page, size);
70
    }
71

    
72
    @RequestMapping(value = "/getSimpleSubscriptionsOfUser/{userEmail}" ,
73
            method = RequestMethod.GET,
74
            produces = MediaType.APPLICATION_JSON_VALUE)
75
    @ResponseBody
76
    @PreAuthorize("hasRole('ROLE_USER')")
77
    public Map<String, List<SimpleSubscriptionDesc>> getSimpleSubscriptionsOfUser(@PathVariable("userEmail")  String userEmail) throws BrokerException{
78
        return brokerService.getSimpleSubscriptionsOfUser(userEmail);
79
    }
80

    
81
    @RequestMapping(value = "/subscribe" , method = RequestMethod.POST,
82
            consumes = MediaType.APPLICATION_JSON_VALUE,
83
            produces = MediaType.APPLICATION_JSON_VALUE)
84
    @ResponseBody
85
    @PreAuthorize("hasRole('ROLE_USER') ")
86
    public Subscription subscribe(@RequestBody OpenaireSubscription obj) throws BrokerException{
87
        return brokerService.subscribe(obj);
88
    }
89

    
90
    @RequestMapping(value = "/unsubscribe/{subscriptionId}" , method = RequestMethod.POST,
91
            consumes = MediaType.APPLICATION_JSON_VALUE,
92
            produces = MediaType.APPLICATION_JSON_VALUE)
93
    @ResponseBody
94
    @PreAuthorize("hasRole('ROLE_USER')")
95
    public ResponseEntity<Object> unsubscribe(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
96
        return brokerService.unsubscribe(subscriptionId);
97
    }
98

    
99
    @RequestMapping(value = "/getSubscription/{subscriptionId}" , method = RequestMethod.GET,
100
            produces = MediaType.APPLICATION_JSON_VALUE)
101
    @ResponseBody
102
    @PreAuthorize("hasRole('ROLE_USER')")
103
    public Subscription getSubscription(@PathVariable("subscriptionId") String subscriptionId) throws BrokerException{
104
        return brokerService.getSubscription(subscriptionId);
105
    }
106

    
107

    
108
    @RequestMapping(value = "/getDnetTopics" , method = RequestMethod.GET,
109
            produces = MediaType.APPLICATION_JSON_VALUE)
110
    @ResponseBody
111
    public Map<String, Term> getDnetTopics() throws BrokerException{
112
        return brokerService.getDnetTopics();
113
    }
114

    
115
    @RequestMapping(value = "/getNotificationsBySubscriptionId/{subscriptionId}/{page}/{size}" , method = RequestMethod.GET
116
            ,produces = MediaType.APPLICATION_JSON_VALUE)
117
    @ResponseBody
118
    @PreAuthorize("hasRole('ROLE_USER')")
119
    public EventsPage getNotificationsBySubscriptionId(@PathVariable("subscriptionId") String subscriptionId,
120
                                                @PathVariable("page") String page,
121
                                                @PathVariable("size") String size) throws BrokerException{
122
        return brokerService.getNotificationsBySubscriptionId(subscriptionId, page, size);
123
    }
124

    
125
}
(1-1/11)