1
|
package eu.dnetlib.repo.manager.controllers;
|
2
|
|
3
|
import eu.dnetlib.domain.data.Repository;
|
4
|
import eu.dnetlib.domain.data.RepositoryInterface;
|
5
|
import eu.dnetlib.repo.manager.domain.RepositorySnippet;
|
6
|
import eu.dnetlib.repo.manager.exception.ResourceNotFoundException;
|
7
|
import eu.dnetlib.repo.manager.service.RepositoryApiImpl;
|
8
|
import eu.dnetlib.repo.manager.shared.*;
|
9
|
import io.swagger.annotations.Api;
|
10
|
import org.json.JSONException;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
12
|
import org.springframework.http.MediaType;
|
13
|
import org.springframework.security.access.prepost.PreAuthorize;
|
14
|
import org.springframework.security.core.Authentication;
|
15
|
import org.springframework.web.bind.annotation.*;
|
16
|
|
17
|
import java.io.IOException;
|
18
|
import java.util.List;
|
19
|
import java.util.Map;
|
20
|
|
21
|
@RestController
|
22
|
@RequestMapping(value = "/repository")
|
23
|
@Api(description = "Repository API", tags = {"repository"})
|
24
|
public class RepositoryController {
|
25
|
|
26
|
@Autowired
|
27
|
RepositoryApiImpl repositoryApi;
|
28
|
|
29
|
@RequestMapping(value = "/getCountries", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
30
|
@ResponseBody
|
31
|
public Country[] getCountries() {
|
32
|
return repositoryApi.getCountries();
|
33
|
}
|
34
|
|
35
|
@RequestMapping(value = "/getRepositoriesByCountry/{country}/{mode}", method = RequestMethod.GET,
|
36
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
37
|
@ResponseBody
|
38
|
public List<RepositorySnippet> getRepositoriesByCountry(@PathVariable("country") String country,
|
39
|
@PathVariable("mode") String mode,
|
40
|
@RequestParam(value = "managed",required=false) Boolean managed) throws JSONException, IOException {
|
41
|
return repositoryApi.getRepositoriesByCountry(country, mode, managed);
|
42
|
}
|
43
|
|
44
|
@RequestMapping(value = "/getRepositoriesOfUser/{userEmail}/{page}/{size}",method = RequestMethod.GET,
|
45
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
46
|
@ResponseBody
|
47
|
@PreAuthorize("hasRole('ROLE_USER')")
|
48
|
public List<Repository> getRepositoriesOfUser(@PathVariable("userEmail") String userEmail,
|
49
|
@PathVariable("page") String page,
|
50
|
@PathVariable("size") String size) throws JSONException {
|
51
|
return repositoryApi.getRepositoriesOfUser(userEmail, page, size);
|
52
|
}
|
53
|
|
54
|
@RequestMapping(value = "/getRepositoryById/{id}", method = RequestMethod.GET,
|
55
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
56
|
@ResponseBody
|
57
|
public Repository getRepositoryById(@PathVariable("id") String id) throws JSONException,ResourceNotFoundException {
|
58
|
return repositoryApi.getRepositoryById(id);
|
59
|
}
|
60
|
|
61
|
@RequestMapping(value = "/getRepositoryAggregations/{id}", method = RequestMethod.GET,
|
62
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
63
|
@ResponseBody
|
64
|
public List<AggregationDetails> getRepositoryAggregations(@PathVariable("id") String id) throws JSONException {
|
65
|
return repositoryApi.getRepositoryAggregations(id);
|
66
|
}
|
67
|
|
68
|
@RequestMapping(value = "/getRepositoryAggregationsByYear/{id}", method = RequestMethod.GET,
|
69
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
70
|
@ResponseBody
|
71
|
public Map<String, List<AggregationDetails>> getRepositoryAggregationsByYear(@PathVariable("id") String id) throws JSONException {
|
72
|
return repositoryApi.getRepositoryAggregationsByYear(id);
|
73
|
}
|
74
|
|
75
|
@RequestMapping(value = "/getRepositoriesByName/{name:.+}/{page}/{size}/", method = RequestMethod.GET,
|
76
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
77
|
@ResponseBody
|
78
|
public List<Repository> getRepositoriesByName(@PathVariable("name") String name,
|
79
|
@PathVariable("page") String page,
|
80
|
@PathVariable("size") String size) throws JSONException {
|
81
|
return repositoryApi.getRepositoriesByName(name, page, size);
|
82
|
}
|
83
|
|
84
|
@RequestMapping(value = "/getRepositoryInterface/{id}", method = RequestMethod.GET,
|
85
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
86
|
@ResponseBody
|
87
|
public List<RepositoryInterface> getRepositoryInterface(@PathVariable("id") String id) throws JSONException {
|
88
|
return repositoryApi.getRepositoryInterface(id);
|
89
|
}
|
90
|
|
91
|
@RequestMapping(value = "/addRepository", method = RequestMethod.POST,
|
92
|
consumes = MediaType.APPLICATION_JSON_VALUE)
|
93
|
@ResponseBody
|
94
|
@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
|
95
|
public Repository addRepository(@RequestParam("datatype") String datatype,
|
96
|
@RequestBody Repository repository) throws Exception {
|
97
|
|
98
|
return repositoryApi.addRepository(datatype, repository);
|
99
|
}
|
100
|
|
101
|
@RequestMapping(value = "/getDnetCountries", method = RequestMethod.GET,
|
102
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
103
|
@ResponseBody
|
104
|
List<String> getDnetCountries(){
|
105
|
return repositoryApi.getDnetCountries();
|
106
|
}
|
107
|
|
108
|
@RequestMapping(value = "/getTypologies", method = RequestMethod.GET,
|
109
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
110
|
@ResponseBody
|
111
|
List<String> getTypologies(){
|
112
|
return repositoryApi.getTypologies();
|
113
|
}
|
114
|
|
115
|
@RequestMapping(value = "/getTimezones", method = RequestMethod.GET,
|
116
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
117
|
@ResponseBody
|
118
|
List<Timezone> getTimezones(){
|
119
|
return repositoryApi.getTimezones();
|
120
|
}
|
121
|
|
122
|
@RequestMapping(value = "/updateRepository", method = RequestMethod.POST,
|
123
|
consumes = MediaType.APPLICATION_JSON_VALUE)
|
124
|
@ResponseBody
|
125
|
//@PreAuthorize("hasRole('ROLE_USER') and #repository.registeredBy == authentication.userInfo.email")
|
126
|
public Repository updateRepository(@RequestBody Repository repository,Authentication authentication) throws Exception {
|
127
|
return repositoryApi.updateRepository(repository, authentication);
|
128
|
}
|
129
|
|
130
|
@RequestMapping(value = "/deleteInterface/", method = RequestMethod.DELETE)
|
131
|
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
|
132
|
public void deleteRepositoryInterface(@RequestParam("id") String id ,
|
133
|
@RequestParam("registeredBy") String registeredBy){
|
134
|
repositoryApi.deleteRepositoryInterface(id, registeredBy);
|
135
|
}
|
136
|
|
137
|
@RequestMapping(value = "/addInterface", method = RequestMethod.POST,
|
138
|
consumes = MediaType.APPLICATION_JSON_VALUE)
|
139
|
@ResponseBody
|
140
|
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
|
141
|
public RepositoryInterface addRepositoryInterface(@RequestParam("datatype") String datatype,
|
142
|
@RequestParam("repoId") String repoId,
|
143
|
@RequestParam("registeredBy") String registeredBy,
|
144
|
@RequestBody RepositoryInterface repositoryInterface) throws JSONException,ResourceNotFoundException {
|
145
|
return repositoryApi.addRepositoryInterface(datatype, repoId, registeredBy, repositoryInterface);
|
146
|
}
|
147
|
|
148
|
@RequestMapping(value = "/getUrlsOfUserRepos/{user_email}/{page}/{size}/",method = RequestMethod.GET,
|
149
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
150
|
@ResponseBody
|
151
|
@PreAuthorize("hasRole('ROLE_USER')")
|
152
|
public List<String> getUrlsOfUserRepos(@PathVariable("user_email") String userEmail,
|
153
|
@PathVariable("page") String page,
|
154
|
@PathVariable("size") String size) throws JSONException {
|
155
|
return repositoryApi.getUrlsOfUserRepos(userEmail, page, size);
|
156
|
}
|
157
|
|
158
|
@RequestMapping(value = "/getDatasourceVocabularies/{mode}",method = RequestMethod.GET,
|
159
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
160
|
@ResponseBody
|
161
|
public List<String> getDatasourceVocabularies(@PathVariable("mode") String mode) {
|
162
|
return repositoryApi.getDatasourceVocabularies(mode);
|
163
|
}
|
164
|
|
165
|
@RequestMapping(value = "/getCompatibilityClasses/{mode}",method = RequestMethod.GET,
|
166
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
167
|
@ResponseBody
|
168
|
public Map<String, String> getCompatibilityClasses(@PathVariable("mode") String mode) {
|
169
|
|
170
|
return repositoryApi.getCompatibilityClasses(mode);
|
171
|
}
|
172
|
|
173
|
@RequestMapping(value = "/getDatasourceClasses/{mode}",method = RequestMethod.GET,
|
174
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
175
|
@ResponseBody
|
176
|
public Map<String, String> getDatasourceClasses(@PathVariable("mode") String mode) {
|
177
|
return repositoryApi.getDatasourceClasses(mode);
|
178
|
}
|
179
|
|
180
|
@RequestMapping(value = "/getMetricsInfoForRepository/{repoId}",method = RequestMethod.GET,
|
181
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
182
|
@ResponseBody
|
183
|
public MetricsInfo getMetricsInfoForRepository(@PathVariable("repoId") String repoId) throws RepositoryServiceException {
|
184
|
return repositoryApi.getMetricsInfoForRepository(repoId);
|
185
|
}
|
186
|
|
187
|
@RequestMapping(value = "/getListLatestUpdate/{mode}",method = RequestMethod.GET,
|
188
|
produces = MediaType.APPLICATION_JSON_VALUE)
|
189
|
@ResponseBody
|
190
|
public Map<String, String> getListLatestUpdate(@PathVariable("mode") String mode) throws JSONException {
|
191
|
return repositoryApi.getListLatestUpdate(mode);
|
192
|
}
|
193
|
|
194
|
@RequestMapping(value = "/updateRepositoryInterface", method = RequestMethod.POST,
|
195
|
consumes = MediaType.APPLICATION_JSON_VALUE)
|
196
|
@ResponseBody
|
197
|
@PreAuthorize("hasRole('ROLE_USER') and #registeredBy == authentication.userInfo.email")
|
198
|
public RepositoryInterface updateRepositoryInterface(@RequestParam("repoId") String repoId,
|
199
|
@RequestParam("registeredBy") String registeredBy,
|
200
|
@RequestBody RepositoryInterface repositoryInterface) throws JSONException {
|
201
|
return repositoryApi.updateRepositoryInterface(repoId, registeredBy, repositoryInterface);
|
202
|
}
|
203
|
}
|