1
|
package eu.dnetlib.enabling.is.controller;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import org.apache.commons.lang3.StringUtils;
|
6
|
import org.springframework.beans.factory.annotation.Autowired;
|
7
|
import org.springframework.http.MediaType;
|
8
|
import org.springframework.web.bind.annotation.PathVariable;
|
9
|
import org.springframework.web.bind.annotation.RequestMapping;
|
10
|
import org.springframework.web.bind.annotation.RequestParam;
|
11
|
import org.springframework.web.bind.annotation.RestController;
|
12
|
|
13
|
import eu.dnetlib.DnetConstants;
|
14
|
import eu.dnetlib.enabling.annotations.DnetService;
|
15
|
import eu.dnetlib.enabling.annotations.DnetServiceType;
|
16
|
import eu.dnetlib.enabling.is.DnetInformationServiceException;
|
17
|
import eu.dnetlib.enabling.is.store.ISStore;
|
18
|
import eu.dnetlib.enabling.is.tools.XQueryUtils;
|
19
|
import eu.dnetlib.services.BaseService;
|
20
|
|
21
|
@RestController
|
22
|
@RequestMapping("/lookup")
|
23
|
@DnetService(DnetServiceType.IS_LOOKUP)
|
24
|
public class ISLookUpController extends BaseService {
|
25
|
|
26
|
// private static final Log log = LogFactory.getLog(ISLookUpController.class); // NOPMD by marko on 11/24/08 5:02 PM
|
27
|
|
28
|
@Autowired
|
29
|
private ISStore isStore;
|
30
|
|
31
|
@Autowired
|
32
|
private XQueryUtils xqueryUtils;
|
33
|
|
34
|
@RequestMapping(value = "profile/{id}", produces = MediaType.APPLICATION_XML_VALUE)
|
35
|
public String getProfile(@PathVariable("id") final String profId) throws DnetInformationServiceException {
|
36
|
if (StringUtils.isBlank(profId)) { throw new DnetInformationServiceException("Invalid null profile ID: " + profId); }
|
37
|
|
38
|
final String res = isStore.getXML(
|
39
|
xqueryUtils.getFileName(profId),
|
40
|
xqueryUtils.getRootCollection() + xqueryUtils.getCollectionName(profId));
|
41
|
|
42
|
if (res == null) { throw new DnetInformationServiceException("document " + profId + " not found"); }
|
43
|
|
44
|
return res;
|
45
|
|
46
|
}
|
47
|
|
48
|
@RequestMapping(value = "schema/{name}", produces = MediaType.APPLICATION_XML_VALUE)
|
49
|
public String getSchema(@PathVariable("name") final String resourceType) throws DnetInformationServiceException {
|
50
|
if (StringUtils.isBlank(resourceType)) { throw new DnetInformationServiceException("Invalid resourceType"); }
|
51
|
|
52
|
return isStore.getXML(resourceType, xqueryUtils.getRootCollection() + DnetConstants.RESOURCE_TYPES);
|
53
|
}
|
54
|
|
55
|
@RequestMapping("schemas")
|
56
|
public List<String> listSchemas() throws DnetInformationServiceException {
|
57
|
return isStore.getFileNames(xqueryUtils.getRootCollection() + "/" + DnetConstants.RESOURCE_TYPES);
|
58
|
}
|
59
|
|
60
|
@RequestMapping("find")
|
61
|
public List<String> find(@RequestParam("q") final String xquery) throws DnetInformationServiceException {
|
62
|
return isStore.quickSearchXML(xquery);
|
63
|
}
|
64
|
|
65
|
}
|