1
|
package eu.dnetlib.vocabularies.publisher.controller;
|
2
|
|
3
|
import java.util.List;
|
4
|
|
5
|
import javax.annotation.Resource;
|
6
|
|
7
|
import eu.dnetlib.common.rmi.DNetRestDocumentation;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.springframework.beans.factory.annotation.Value;
|
11
|
import org.springframework.stereotype.Controller;
|
12
|
import org.springframework.ui.ModelMap;
|
13
|
import org.springframework.web.bind.annotation.PathVariable;
|
14
|
import org.springframework.web.bind.annotation.RequestMapping;
|
15
|
import org.springframework.web.bind.annotation.RequestMethod;
|
16
|
import org.springframework.web.bind.annotation.ResponseBody;
|
17
|
|
18
|
import eu.dnetlib.vocabularies.publisher.VocabularyNotFoundException;
|
19
|
import eu.dnetlib.vocabularies.publisher.VocabularyRetriever;
|
20
|
import eu.dnetlib.vocabularies.publisher.model.Vocabulary;
|
21
|
|
22
|
@Controller
|
23
|
@DNetRestDocumentation
|
24
|
public class VocabularyPublisherController {
|
25
|
|
26
|
private static final Log log = LogFactory.getLog(VocabularyPublisherController.class);
|
27
|
|
28
|
@Resource
|
29
|
private VocabularyRetriever vocabularyRetriever;
|
30
|
@Value("${vocabulary.publisher.title}")
|
31
|
private String title;
|
32
|
@Value("${vocabulary.publisher.baseURL}")
|
33
|
private String baseURL;
|
34
|
@Value("${container.context}")
|
35
|
private String context;
|
36
|
|
37
|
@RequestMapping(value = "/vocabularies", method = RequestMethod.GET, produces = { "application/json" })
|
38
|
public @ResponseBody
|
39
|
List<Vocabulary> listVocabularies() {
|
40
|
log.debug("listVocabularies()");
|
41
|
return vocabularyRetriever.listVocabularies();
|
42
|
}
|
43
|
|
44
|
@RequestMapping(value = "/vocabularies/{code}", method = RequestMethod.GET, produces = { "application/json" })
|
45
|
public @ResponseBody
|
46
|
Vocabulary getVocabulary(@PathVariable("code") final String code) throws VocabularyNotFoundException {
|
47
|
log.debug("getVocabulary with code = " + code);
|
48
|
return this.vocabularyRetriever.getVocabularyByCode(code);
|
49
|
}
|
50
|
|
51
|
// View-based methods for html responses
|
52
|
@RequestMapping(value = "/vocabularies", method = RequestMethod.GET, produces = { "text/html" })
|
53
|
public void listVocabularies(final ModelMap map) {
|
54
|
map.addAttribute("vocabularies", listVocabularies());
|
55
|
map.addAttribute("title", title);
|
56
|
map.addAttribute("baseURL", baseURL);
|
57
|
map.addAttribute("context", context);
|
58
|
}
|
59
|
|
60
|
@RequestMapping(value = "/vocabularies/{code}", method = RequestMethod.GET, produces = { "text/html" })
|
61
|
public String getVocabulary(@PathVariable("code") final String code, final ModelMap map) throws VocabularyNotFoundException {
|
62
|
map.addAttribute("vocabulary", getVocabulary(code));
|
63
|
map.addAttribute("baseURL", baseURL);
|
64
|
map.addAttribute("context", context);
|
65
|
return "displayVocabulary";
|
66
|
}
|
67
|
|
68
|
}
|