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