1 |
48332
|
claudio.at
|
package eu.dnetlib.openaire.exporter.datasource;
|
2 |
44743
|
claudio.at
|
|
3 |
46876
|
claudio.at
|
import java.util.List;
|
4 |
|
|
|
5 |
44743
|
claudio.at
|
import eu.dnetlib.common.rmi.DNetRestDocumentation;
|
6 |
48617
|
claudio.at
|
import eu.dnetlib.openaire.exporter.AbstractExporterController;
|
7 |
48332
|
claudio.at
|
import eu.dnetlib.openaire.exporter.datasource.clients.DatasourceDao;
|
8 |
|
|
import eu.dnetlib.openaire.exporter.model.datasource.BrowseTerm;
|
9 |
|
|
import eu.dnetlib.openaire.exporter.model.datasource.DatasourceResponse;
|
10 |
49887
|
claudio.at
|
import eu.dnetlib.openaire.exporter.model.datasource.Response;
|
11 |
48332
|
claudio.at
|
import eu.dnetlib.openaire.exporter.model.datasource.db.Api;
|
12 |
|
|
import eu.dnetlib.openaire.exporter.model.datasource.db.Datasource;
|
13 |
|
|
import eu.dnetlib.openaire.exporter.model.datasource.db.SearchInterfacesEntry;
|
14 |
48975
|
claudio.at
|
import eu.dnetlib.openaire.exporter.vocabularies.Country;
|
15 |
49534
|
claudio.at
|
import io.swagger.annotations.ApiOperation;
|
16 |
|
|
import io.swagger.annotations.ApiResponse;
|
17 |
|
|
import io.swagger.annotations.ApiResponses;
|
18 |
47676
|
claudio.at
|
import org.apache.commons.lang.StringUtils;
|
19 |
49887
|
claudio.at
|
import org.apache.commons.lang3.time.StopWatch;
|
20 |
44743
|
claudio.at
|
import org.apache.commons.logging.Log;
|
21 |
|
|
import org.apache.commons.logging.LogFactory;
|
22 |
47193
|
claudio.at
|
import org.apache.http.HttpStatus;
|
23 |
44743
|
claudio.at
|
import org.springframework.beans.factory.annotation.Autowired;
|
24 |
46876
|
claudio.at
|
import org.springframework.data.domain.PageRequest;
|
25 |
|
|
import org.springframework.web.bind.annotation.*;
|
26 |
44743
|
claudio.at
|
|
27 |
46876
|
claudio.at
|
@RestController
|
28 |
44743
|
claudio.at
|
@DNetRestDocumentation
|
29 |
48617
|
claudio.at
|
public class DatasourcesApiController extends AbstractExporterController implements DatasourcesApi {
|
30 |
44743
|
claudio.at
|
|
31 |
|
|
private static final Log log = LogFactory.getLog(DatasourcesApiController.class);
|
32 |
|
|
|
33 |
|
|
@Autowired
|
34 |
47676
|
claudio.at
|
private DatasourceDao dsDao;
|
35 |
44743
|
claudio.at
|
|
36 |
44765
|
claudio.at
|
@Override
|
37 |
46876
|
claudio.at
|
@RequestMapping(value = "/ds/list/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
38 |
|
|
public List<String> listIds(@PathVariable int page, @PathVariable int size) throws ApiException {
|
39 |
47676
|
claudio.at
|
return dsDao.listIds(new PageRequest(page, size));
|
40 |
44743
|
claudio.at
|
}
|
41 |
|
|
|
42 |
44765
|
claudio.at
|
@Override
|
43 |
46876
|
claudio.at
|
@RequestMapping(value = "/ds/get/{id}", produces = { "application/json" }, method = RequestMethod.GET)
|
44 |
|
|
public DatasourceResponse getDs(@PathVariable final String id) {
|
45 |
44743
|
claudio.at
|
|
46 |
|
|
if (log.isDebugEnabled()) {
|
47 |
|
|
log.debug(String.format("getDatasourceInfo(dsId = %s)", id));
|
48 |
|
|
}
|
49 |
49887
|
claudio.at
|
final StopWatch stop = StopWatch.createStarted();
|
50 |
|
|
final Response rsp = dsDao.getDsById(id);
|
51 |
|
|
rsp.getHeader().setTime(stop.getTime());
|
52 |
|
|
if (log.isDebugEnabled()) {
|
53 |
|
|
log.debug("getDs by id: " + rsp.getHeader().toJson());
|
54 |
|
|
}
|
55 |
|
|
return rsp.getDatasourceResponse().get(0);
|
56 |
44743
|
claudio.at
|
}
|
57 |
|
|
|
58 |
46876
|
claudio.at
|
@Override
|
59 |
47193
|
claudio.at
|
@RequestMapping(value = "/ds/search/name/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
60 |
|
|
public List<DatasourceResponse> searchByName(
|
61 |
|
|
@RequestParam final String name, @PathVariable final int page, @PathVariable final int size) {
|
62 |
49887
|
claudio.at
|
final StopWatch stop = StopWatch.createStarted();
|
63 |
|
|
final Response rsp = dsDao.searchByName(name, new PageRequest(page, size));
|
64 |
|
|
rsp.getHeader().setTime(stop.getTime());
|
65 |
|
|
if (log.isDebugEnabled()) {
|
66 |
|
|
log.debug("searchByName: " + rsp.getHeader().toJson());
|
67 |
|
|
}
|
68 |
|
|
return rsp.getDatasourceResponse();
|
69 |
47193
|
claudio.at
|
}
|
70 |
|
|
|
71 |
|
|
@Override
|
72 |
|
|
@RequestMapping(value = "/ds/search/email/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
73 |
|
|
public List<DatasourceResponse> searchByContactemail(
|
74 |
|
|
@RequestParam final String contactemail, @PathVariable final int page, @PathVariable final int size) {
|
75 |
49887
|
claudio.at
|
final StopWatch stop = StopWatch.createStarted();
|
76 |
|
|
final Response rsp = dsDao.searchByContactemail(contactemail, new PageRequest(page, size));
|
77 |
|
|
rsp.getHeader().setTime(stop.getTime());
|
78 |
|
|
if (log.isDebugEnabled()) {
|
79 |
|
|
log.debug("searchByContactemail: " + rsp.getHeader().toJson());
|
80 |
|
|
}
|
81 |
|
|
return rsp.getDatasourceResponse();
|
82 |
47193
|
claudio.at
|
}
|
83 |
|
|
|
84 |
|
|
@Override
|
85 |
|
|
@RequestMapping(value = "/ds/search/country/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
86 |
|
|
public List<DatasourceResponse> searchByCountry(
|
87 |
|
|
@RequestParam final String country, @PathVariable final int page, @PathVariable final int size) {
|
88 |
49887
|
claudio.at
|
final StopWatch stop = StopWatch.createStarted();
|
89 |
|
|
final Response rsp = dsDao.searchByCountry(country, new PageRequest(page, size));
|
90 |
|
|
rsp.getHeader().setTime(stop.getTime());
|
91 |
|
|
if (log.isDebugEnabled()) {
|
92 |
|
|
log.debug("searchByCountry: " + rsp.getHeader().toJson());
|
93 |
|
|
}
|
94 |
|
|
return rsp.getDatasourceResponse();
|
95 |
47193
|
claudio.at
|
}
|
96 |
|
|
|
97 |
|
|
@Override
|
98 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/search/registeredby/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
99 |
|
|
public List<DatasourceResponse> searchByRegisteringUser(final String registeredBy, final int page, final int size) {
|
100 |
|
|
final StopWatch stop = StopWatch.createStarted();
|
101 |
|
|
final Response rsp = dsDao.searchByRegisteringUser(registeredBy, new PageRequest(page, size));
|
102 |
|
|
rsp.getHeader().setTime(stop.getTime());
|
103 |
|
|
if (log.isDebugEnabled()) {
|
104 |
|
|
log.debug("searchByRegisteringUser: " + rsp.getHeader().toJson());
|
105 |
|
|
}
|
106 |
|
|
return rsp.getDatasourceResponse();
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
@Override
|
110 |
46876
|
claudio.at
|
@RequestMapping(value = "/api/search/{field}", produces = { "application/json" }, method = RequestMethod.GET)
|
111 |
|
|
public List<SearchInterfacesEntry> searchInterface(@PathVariable final String field, @RequestParam final String value) {
|
112 |
47676
|
claudio.at
|
return dsDao.searchInterface(field, value);
|
113 |
44743
|
claudio.at
|
}
|
114 |
|
|
|
115 |
47193
|
claudio.at
|
@Override
|
116 |
49608
|
claudio.at
|
@RequestMapping(value = "/api/baseurl/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
117 |
49612
|
claudio.at
|
public List<String> searchBaseUrls(@RequestParam final String userEmail, @RequestParam(required = false) final Boolean managed, @PathVariable final int page, @PathVariable final int size) throws ApiException {
|
118 |
49608
|
claudio.at
|
return dsDao.findBaseURLs(userEmail, managed, new PageRequest(page, size));
|
119 |
|
|
}
|
120 |
|
|
|
121 |
|
|
@Override
|
122 |
47193
|
claudio.at
|
@RequestMapping(value = "/api/browse/{field}", produces = { "application/json" }, method = RequestMethod.GET)
|
123 |
|
|
public List<? extends BrowseTerm> browseField(@PathVariable final String field) throws ApiException {
|
124 |
|
|
switch (field) {
|
125 |
|
|
case "country":
|
126 |
47676
|
claudio.at
|
return dsDao.browseCountries();
|
127 |
47193
|
claudio.at
|
case "typology":
|
128 |
47676
|
claudio.at
|
return dsDao.browseTypologies();
|
129 |
47193
|
claudio.at
|
case "protocol":
|
130 |
47676
|
claudio.at
|
return dsDao.browseProtocols();
|
131 |
47193
|
claudio.at
|
case "compatibility":
|
132 |
47676
|
claudio.at
|
return dsDao.browseCompatibility();
|
133 |
47193
|
claudio.at
|
case "activation":
|
134 |
47676
|
claudio.at
|
return dsDao.browseActivation();
|
135 |
47193
|
claudio.at
|
default:
|
136 |
|
|
throw new ApiException(HttpStatus.SC_BAD_REQUEST, String.format("unsupported browse field '%s'", field));
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
@Override
|
141 |
48970
|
claudio.at
|
@RequestMapping(value = "/ds/countries", produces = { "application/json" }, method = RequestMethod.GET)
|
142 |
48975
|
claudio.at
|
public List<Country> listCountries() throws ApiException {
|
143 |
|
|
return dsDao.listCountries();
|
144 |
48970
|
claudio.at
|
}
|
145 |
|
|
|
146 |
|
|
@Override
|
147 |
47676
|
claudio.at
|
@RequestMapping(value = "/ds/api/{dsId}", produces = { "application/json" }, method = RequestMethod.GET)
|
148 |
|
|
public List<Api> getApi(@PathVariable final String dsId) throws ApiException {
|
149 |
|
|
return dsDao.getApi(dsId);
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
@Override
|
153 |
|
|
@RequestMapping(value = "/ds/api/{dsId}", method = RequestMethod.DELETE)
|
154 |
|
|
public void deleteApi(@PathVariable final String apiId) throws ApiException {
|
155 |
|
|
dsDao.deleteApi(apiId);
|
156 |
|
|
}
|
157 |
|
|
|
158 |
|
|
@Override
|
159 |
|
|
@RequestMapping(value = "/ds/api/add", method = RequestMethod.POST)
|
160 |
|
|
public void addApi(@RequestParam final Api api) throws ApiException {
|
161 |
|
|
if (StringUtils.isBlank(api.getDatasource())) {
|
162 |
|
|
throw new ApiException(HttpStatus.SC_BAD_REQUEST, "missing datasource id");
|
163 |
|
|
}
|
164 |
|
|
dsDao.addApi(api);
|
165 |
|
|
}
|
166 |
|
|
|
167 |
|
|
@Override
|
168 |
47193
|
claudio.at
|
@RequestMapping(value = "/ds/manage", method = RequestMethod.POST)
|
169 |
|
|
public void setManaged(@RequestParam final String id, @RequestParam final boolean managed) {
|
170 |
47676
|
claudio.at
|
dsDao.setManaged(id, managed);
|
171 |
47193
|
claudio.at
|
}
|
172 |
|
|
|
173 |
47676
|
claudio.at
|
@Override
|
174 |
|
|
@RequestMapping(value = "/ds/add", method = RequestMethod.POST)
|
175 |
|
|
public void saveDatasource(@RequestBody final Datasource datasource) throws ApiException {
|
176 |
|
|
if (dsDao.exist(datasource)) { //TODO further check that the DS doesn't have any API
|
177 |
|
|
throw new ApiException(HttpStatus.SC_CONFLICT, String.format("cannot already defined '%s'", datasource.getId()));
|
178 |
|
|
}
|
179 |
|
|
dsDao.save(datasource);
|
180 |
|
|
}
|
181 |
|
|
|
182 |
|
|
@Override
|
183 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/officialname", method = RequestMethod.POST)
|
184 |
47676
|
claudio.at
|
public void updateOfficialname(@RequestParam final String dsId, @RequestParam final String officialname) throws ApiException {
|
185 |
|
|
dsDao.updateOfficialName(dsId, officialname);
|
186 |
|
|
}
|
187 |
|
|
|
188 |
|
|
@Override
|
189 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/englishname", method = RequestMethod.POST)
|
190 |
47676
|
claudio.at
|
public void updateEnglishname(@RequestParam final String dsId, @RequestParam final String englishname) throws ApiException {
|
191 |
|
|
dsDao.updateEnglishName(dsId, englishname);
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
@Override
|
195 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/latitude", method = RequestMethod.POST)
|
196 |
49966
|
claudio.at
|
public void updateLatitude(@RequestParam final String dsId, @RequestParam final Double latitude) throws ApiException {
|
197 |
47676
|
claudio.at
|
dsDao.updateLatitude(dsId, latitude);
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
@Override
|
201 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/longitude", method = RequestMethod.POST)
|
202 |
49966
|
claudio.at
|
public void updateLongitude(@RequestParam final String dsId, @RequestParam final Double longitude) throws ApiException {
|
203 |
47676
|
claudio.at
|
dsDao.updateLongitude(dsId, longitude);
|
204 |
|
|
}
|
205 |
|
|
|
206 |
49887
|
claudio.at
|
@Override
|
207 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/logourl", method = RequestMethod.POST)
|
208 |
49966
|
claudio.at
|
public void updateLogourl(@RequestParam final String dsId, @RequestParam final String logourl) throws ApiException {
|
209 |
49887
|
claudio.at
|
dsDao.updateLogourl(dsId, logourl);
|
210 |
|
|
}
|
211 |
|
|
|
212 |
|
|
@Override
|
213 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/timezone", method = RequestMethod.POST)
|
214 |
49966
|
claudio.at
|
public void updateTimezone(@RequestParam final String dsId, @RequestParam final String timezone) throws ApiException {
|
215 |
49887
|
claudio.at
|
dsDao.updateTimezone(dsId, timezone);
|
216 |
|
|
}
|
217 |
|
|
|
218 |
|
|
@Override
|
219 |
49965
|
claudio.at
|
@RequestMapping(value = "/ds/typology", method = RequestMethod.POST)
|
220 |
49966
|
claudio.at
|
public void updateTypology(@RequestParam final String dsId, @RequestParam final String typology) throws ApiException {
|
221 |
49887
|
claudio.at
|
dsDao.updateDatasourceTypology(dsId, typology);
|
222 |
|
|
}
|
223 |
|
|
|
224 |
49965
|
claudio.at
|
@Override
|
225 |
|
|
@RequestMapping(value = "/ds/registeredby", method = RequestMethod.POST)
|
226 |
49966
|
claudio.at
|
public void updateRegisteringUser(@RequestParam final String dsId, @RequestParam final String registeredBy) throws ApiException {
|
227 |
49965
|
claudio.at
|
dsDao.updateDatasourceRegisteringUser(dsId, registeredBy);
|
228 |
|
|
}
|
229 |
|
|
|
230 |
49534
|
claudio.at
|
@ApiOperation(value = "drop the datasource manager caches", notes = "drop the datasource manager caches", httpMethod = "GET")
|
231 |
|
|
@ApiResponses(value = {
|
232 |
|
|
@ApiResponse(code = 200, message = "OK"),
|
233 |
|
|
@ApiResponse(code = 500, message = "unexpected error") })
|
234 |
|
|
@RequestMapping(value = "/ds/dropcache.do", method = RequestMethod.GET)
|
235 |
|
|
public void dropDsCaches() {
|
236 |
|
|
dsDao.dropCaches();
|
237 |
|
|
}
|
238 |
|
|
|
239 |
|
|
|
240 |
44743
|
claudio.at
|
}
|