2 |
2 |
|
3 |
3 |
import java.util.List;
|
4 |
4 |
import javax.annotation.Resource;
|
|
5 |
import javax.servlet.http.HttpServletRequest;
|
5 |
6 |
|
6 |
7 |
import eu.dnetlib.common.rmi.DNetRestDocumentation;
|
7 |
8 |
import eu.dnetlib.vocabularies.publisher.VocabularyNotFoundException;
|
... | ... | |
14 |
15 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
16 |
import org.springframework.stereotype.Controller;
|
16 |
17 |
import org.springframework.ui.ModelMap;
|
|
18 |
import org.springframework.util.AntPathMatcher;
|
17 |
19 |
import org.springframework.web.bind.annotation.*;
|
|
20 |
import org.springframework.web.servlet.HandlerMapping;
|
18 |
21 |
|
19 |
22 |
@Controller
|
20 |
23 |
@DNetRestDocumentation
|
... | ... | |
46 |
49 |
return this.vocabularyRetriever.getVocabularyByCode(code);
|
47 |
50 |
}
|
48 |
51 |
|
49 |
|
@RequestMapping(value = "/vocabularies/{code}/{term}", method = RequestMethod.GET, produces = { "application/json" })
|
|
52 |
@RequestMapping(value = "/vocabularies/{code}/**", method = RequestMethod.GET, produces = { "application/json" })
|
50 |
53 |
public @ResponseBody
|
51 |
54 |
VocabularyTerm getTermSynonyms(
|
52 |
55 |
@PathVariable("code") final String code,
|
53 |
|
@PathVariable("term") final String term) throws VocabularyNotFoundException {
|
|
56 |
final HttpServletRequest request) throws VocabularyNotFoundException {
|
|
57 |
final String term = extractTerm(request);
|
54 |
58 |
log.debug(String.format("getVocabulary with code = %s, term = %s", code, term));
|
55 |
59 |
return this.vocabularyRetriever.getTermSynonyms(code, term);
|
56 |
60 |
}
|
57 |
61 |
|
|
62 |
|
|
63 |
private String extractTerm(HttpServletRequest request) {
|
|
64 |
|
|
65 |
String path = (String) request.getAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE); // /elements/CATEGORY1/CATEGORY1_1/ID
|
|
66 |
String bestMatchPattern = (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); // /elements/**
|
|
67 |
|
|
68 |
return new AntPathMatcher().extractPathWithinPattern(bestMatchPattern, path); // CATEGORY1/CATEGORY1_1/ID
|
|
69 |
}
|
|
70 |
|
58 |
71 |
// View-based methods for html responses
|
59 |
72 |
@RequestMapping(value = "/vocabularies", method = RequestMethod.GET, produces = { "text/html" })
|
60 |
73 |
public void listVocabularies(final ModelMap map) {
|
... | ... | |
69 |
82 |
@PathVariable("code") final String code,
|
70 |
83 |
final ModelMap map) throws VocabularyNotFoundException {
|
71 |
84 |
|
72 |
|
//TODO find a way to url-encode codes with slashes "/" as they break the rendering
|
73 |
85 |
map.addAttribute("vocabulary", getVocabulary(code));
|
74 |
86 |
map.addAttribute("baseURL", baseURL);
|
75 |
87 |
map.addAttribute("context", context);
|
76 |
88 |
return "displayVocabulary";
|
77 |
89 |
}
|
78 |
90 |
|
79 |
|
@RequestMapping(value = "/vocabularies/{code}/{term}", method = RequestMethod.GET, produces = { "text/html" })
|
|
91 |
@RequestMapping(value = "/vocabularies/{code}/**", method = RequestMethod.GET, produces = { "text/html" })
|
80 |
92 |
public String getTermSynonyms(
|
81 |
93 |
@PathVariable("code") final String code,
|
82 |
|
@PathVariable("term") final String term,
|
|
94 |
final HttpServletRequest request,
|
83 |
95 |
final ModelMap map) throws VocabularyNotFoundException {
|
84 |
|
log.debug(String.format("getVocabulary with code = %s, term = %s", code, term));
|
85 |
|
|
86 |
96 |
map.addAttribute("vocabulary", getVocabulary(code));
|
87 |
|
map.addAttribute("term", getTermSynonyms(code, term));
|
|
97 |
map.addAttribute("term", getTermSynonyms(code, request));
|
88 |
98 |
map.addAttribute("baseURL", baseURL);
|
89 |
99 |
map.addAttribute("context", context);
|
90 |
100 |
return "displaySynonyms";
|
workaround for the slash character breaking the url resolution: we cannot use the path variables