Revision 45692
Added by Michele Artini over 7 years ago
InformationServiceModule.java | ||
---|---|---|
10 | 10 |
import java.util.List; |
11 | 11 |
import java.util.Map; |
12 | 12 |
import java.util.Set; |
13 |
import java.util.stream.Collectors; |
|
13 | 14 |
|
14 | 15 |
import javax.servlet.ServletOutputStream; |
15 | 16 |
import javax.servlet.ServletResponse; |
16 | 17 |
|
17 | 18 |
import org.apache.commons.io.IOUtils; |
18 |
import org.apache.commons.lang3.StringUtils; |
|
19 | 19 |
import org.apache.commons.lang3.math.NumberUtils; |
20 | 20 |
import org.apache.commons.logging.Log; |
21 | 21 |
import org.apache.commons.logging.LogFactory; |
22 |
import org.dom4j.Document; |
|
23 |
import org.dom4j.io.SAXReader; |
|
24 | 22 |
import org.springframework.beans.factory.annotation.Autowired; |
25 | 23 |
import org.springframework.ui.ModelMap; |
24 |
import org.springframework.web.bind.annotation.PathVariable; |
|
25 |
import org.springframework.web.bind.annotation.RequestBody; |
|
26 | 26 |
import org.springframework.web.bind.annotation.RequestMapping; |
27 |
import org.springframework.web.bind.annotation.RequestMethod; |
|
27 | 28 |
import org.springframework.web.bind.annotation.RequestParam; |
28 | 29 |
import org.springframework.web.bind.annotation.RestController; |
29 | 30 |
|
... | ... | |
58 | 59 |
@Override |
59 | 60 |
public void populateModelMap(final ModelMap map) {} |
60 | 61 |
|
61 |
@RequestMapping("xquery.do")
|
|
62 |
public List<String> query(@RequestParam("query") final String query) throws Exception {
|
|
62 |
@RequestMapping("xquery") |
|
63 |
public List<String> query(@RequestParam("q") final String query) throws Exception { |
|
63 | 64 |
log.debug("Executing xquery: " + query); |
64 | 65 |
return isClient.find(query); |
65 | 66 |
} |
66 | 67 |
|
67 |
@RequestMapping("listSchemas.do")
|
|
68 |
@RequestMapping("schemas")
|
|
68 | 69 |
public Set<String> listSchemas() throws Exception { |
69 | 70 |
return isClient.listSchemas(); |
70 | 71 |
} |
71 | 72 |
|
72 |
@RequestMapping("getSchema.do")
|
|
73 |
public String getSchema(@RequestParam("name") final String name) throws Exception {
|
|
73 |
@RequestMapping("schema/{name}")
|
|
74 |
public String getSchema(@PathVariable final String name) throws Exception {
|
|
74 | 75 |
return isClient.getSchema(name); |
75 | 76 |
} |
76 | 77 |
|
77 |
@RequestMapping("listCollections.do")
|
|
78 |
@RequestMapping("collections")
|
|
78 | 79 |
public List<CollectionDesc> listCollections() throws Exception { |
79 | 80 |
final String xquery = "for $kind in xmldb:get-child-collections('/db/DRIVER') " + |
80 | 81 |
"for $type in xmldb:get-child-collections(concat('/db/DRIVER/', $kind)) " + |
... | ... | |
101 | 102 |
return res; |
102 | 103 |
} |
103 | 104 |
|
104 |
@RequestMapping("listProfiles.do") |
|
105 |
public List<String> listProfiles(@RequestParam("kind") final String kind, |
|
106 |
@RequestParam("type") final String type) throws Exception { |
|
105 |
@RequestMapping("profiles/{kind}/{type}") |
|
106 |
public List<String> listProfiles(@PathVariable final String kind, @PathVariable final String type) throws Exception { |
|
107 | 107 |
final String collName = "/db/DRIVER/" + kind + "/" + type; |
108 | 108 |
final String xquery = "distinct-values(for $x in collection('" + collName + "') return $x//RESOURCE_IDENTIFIER/@value/string())"; |
109 | 109 |
final List<String> res = isClient.find(xquery); |
... | ... | |
113 | 113 |
return res; |
114 | 114 |
} |
115 | 115 |
|
116 |
@RequestMapping("getProfile.do")
|
|
117 |
public String getProfiles(@RequestParam("id") final String id) throws Exception {
|
|
118 |
return isClient.getProfile(id);
|
|
116 |
@RequestMapping(value = "profile/{kind}/{type}/{filename}", method = RequestMethod.GET)
|
|
117 |
public String getProfiles(@PathVariable final String kind, @PathVariable final String type, @PathVariable final String filename) throws Exception {
|
|
118 |
return isClient.getProfile(String.format("%s/%s/%s", kind, type, filename));
|
|
119 | 119 |
} |
120 | 120 |
|
121 |
@RequestMapping("registerProfile.do")
|
|
122 |
public String registerProfile(@RequestParam("profile") final String profile) throws Exception {
|
|
121 |
@RequestMapping(value = "profile", method = RequestMethod.POST)
|
|
122 |
public String registerProfile(@RequestBody final String profile) throws Exception {
|
|
123 | 123 |
return isClient.register(profile); |
124 | 124 |
} |
125 | 125 |
|
126 |
@RequestMapping("updateProfile.do") |
|
127 |
public String updateProfile(@RequestParam("profile") final String profile) throws Exception { |
|
128 |
final SAXReader reader = new SAXReader(); |
|
129 |
final Document doc = reader.read(new StringReader(profile)); |
|
126 |
@RequestMapping(value = "profile/{kind}/{type}/{filename}", method = RequestMethod.POST) |
|
127 |
public String updateProfile(@PathVariable final String kind, |
|
128 |
@PathVariable final String type, |
|
129 |
@PathVariable final String filename, |
|
130 |
@RequestBody final String profile) throws Exception { |
|
130 | 131 |
|
131 |
final String id = doc.valueOf("//RESOURCE_IDENTIFIER/@value"); |
|
132 |
|
|
133 |
if (StringUtils.isEmpty(id)) { throw new Exception("RESOURCE_IDENTIFIER is empty"); } |
|
134 |
|
|
132 |
final String id = String.format("%s/%s/%s", kind, type, filename); |
|
135 | 133 |
isClient.updateProfile(id, profile); |
136 | 134 |
return id; |
137 | 135 |
} |
138 | 136 |
|
139 |
@RequestMapping("deleteProfile.do")
|
|
140 |
public boolean deleteProfile(@RequestParam("id") final String id) throws Exception {
|
|
141 |
isClient.deleteProfile(id);
|
|
137 |
@RequestMapping(value = "profile/{kind}/{type}/{filename}", method = RequestMethod.DELETE)
|
|
138 |
public boolean deleteProfile(@PathVariable final String kind, @PathVariable final String type, @PathVariable final String filename) throws Exception {
|
|
139 |
isClient.deleteProfile(String.format("%s/%s/%s", kind, type, filename));
|
|
142 | 140 |
return true; |
143 | 141 |
} |
144 | 142 |
|
... | ... | |
181 | 179 |
return map; |
182 | 180 |
} |
183 | 181 |
|
184 |
@RequestMapping("listServices.do")
|
|
182 |
@RequestMapping("services")
|
|
185 | 183 |
public Collection<ServiceGrouperDesc> listServices() throws Exception { |
186 |
final String xq = IOUtils.toString(getClass().getResourceAsStream("/eu/dnetlib/functionality/modular/xquery/listServices.xquery")); |
|
187 | 184 |
|
188 |
final List<ServiceDesc> list = Lists.newArrayList();
|
|
185 |
final String xq = "for $x in collection('/db/DRIVER/dnetService') return concat ($x//RESOURCE_IDENTIFIER/@value, ' @ ', $x//RESOURCE_URI/@value)";
|
|
189 | 186 |
|
190 |
final SAXReader reader = new SAXReader(); |
|
191 |
for (final String s : isClient.find(xq)) { |
|
192 |
final Document doc = reader.read(new StringReader(s)); |
|
193 |
final String id = doc.valueOf("/service/id").trim(); |
|
194 |
final String name = doc.valueOf("/service/name").trim(); |
|
195 |
final String wsdl = doc.valueOf("/service/wsdl").trim(); |
|
196 |
list.add(new ServiceDesc(id, name, wsdl)); |
|
197 |
} |
|
187 |
final List<ServiceDesc> list = isClient.find(xq).stream() |
|
188 |
.map(e -> e.split("@")) |
|
189 |
.filter(arr -> arr.length == 2) |
|
190 |
.filter(arr -> arr[0].split("/").length == 3) |
|
191 |
.map(arr -> new ServiceDesc(arr[0].trim(), arr[0].split("/")[1], arr[1].trim())) |
|
192 |
.collect(Collectors.toList()); |
|
198 | 193 |
|
199 | 194 |
final Map<String, ServiceGrouperDesc> map = Maps.newHashMap(); |
200 | 195 |
for (final ServiceDesc s : list) { |
... | ... | |
212 | 207 |
return map.values(); |
213 | 208 |
} |
214 | 209 |
|
215 |
@RequestMapping("ping.do")
|
|
210 |
@RequestMapping("ping") |
|
216 | 211 |
public long pingUrl(@RequestParam("url") final String url, |
217 | 212 |
@RequestParam("timeout") final int timeout) |
218 | 213 |
throws IOException { |
Also available in: Unified diff