1
|
package eu.dnetlib.datasource.publisher;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import eu.dnetlib.common.rmi.DNetRestDocumentation;
|
6
|
import eu.dnetlib.datasource.publisher.clients.ClientResponse;
|
7
|
import eu.dnetlib.datasource.publisher.clients.DatasourceInfoRetriever;
|
8
|
import eu.dnetlib.datasource.publisher.model.DatasourceResponse;
|
9
|
import eu.dnetlib.datasource.publisher.model.db.SearchInterfacesEntry;
|
10
|
import org.apache.commons.logging.Log;
|
11
|
import org.apache.commons.logging.LogFactory;
|
12
|
import org.springframework.beans.factory.annotation.Autowired;
|
13
|
import org.springframework.data.domain.PageRequest;
|
14
|
import org.springframework.web.bind.annotation.*;
|
15
|
|
16
|
@RestController
|
17
|
@DNetRestDocumentation
|
18
|
public class DatasourcesApiController implements DatasourcesApi {
|
19
|
|
20
|
private static final Log log = LogFactory.getLog(DatasourcesApiController.class);
|
21
|
|
22
|
@Autowired
|
23
|
private DatasourceInfoRetriever dsInfoRetriever;
|
24
|
|
25
|
@Override
|
26
|
@RequestMapping(value = "/ds/list/{page}/{size}", produces = { "application/json" }, method = RequestMethod.GET)
|
27
|
public List<String> listIds(@PathVariable int page, @PathVariable int size) throws ApiException {
|
28
|
return dsInfoRetriever.listIds(new PageRequest(page, size));
|
29
|
}
|
30
|
|
31
|
@Override
|
32
|
@RequestMapping(value = "/ds/get/{id}", produces = { "application/json" }, method = RequestMethod.GET)
|
33
|
public DatasourceResponse getDs(@PathVariable final String id) {
|
34
|
|
35
|
if (log.isDebugEnabled()) {
|
36
|
log.debug(String.format("getDatasourceInfo(dsId = %s)", id));
|
37
|
}
|
38
|
|
39
|
final ClientResponse clientResponse = dsInfoRetriever.getInfo(id);
|
40
|
return clientResponse.getDatasourceResponse();
|
41
|
}
|
42
|
|
43
|
@Override
|
44
|
@RequestMapping(value = "/api/search/{field}", produces = { "application/json" }, method = RequestMethod.GET)
|
45
|
public List<SearchInterfacesEntry> searchInterface(@PathVariable final String field, @RequestParam final String value) {
|
46
|
return dsInfoRetriever.searchInterface(field, value);
|
47
|
}
|
48
|
|
49
|
}
|