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