1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.remote.controller;
|
12
|
|
13
|
import java.io.IOException;
|
14
|
import java.util.Arrays;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import javax.servlet.http.HttpServletRequest;
|
19
|
import javax.servlet.http.HttpServletResponse;
|
20
|
|
21
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
import org.springframework.stereotype.Controller;
|
23
|
import org.springframework.web.bind.WebDataBinder;
|
24
|
import org.springframework.web.bind.annotation.InitBinder;
|
25
|
import org.springframework.web.bind.annotation.PathVariable;
|
26
|
import org.springframework.web.bind.annotation.RequestMapping;
|
27
|
import org.springframework.web.bind.annotation.RequestMethod;
|
28
|
import org.springframework.web.bind.annotation.RequestParam;
|
29
|
import org.springframework.web.servlet.ModelAndView;
|
30
|
|
31
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
32
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
33
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
34
|
import eu.etaxonomy.cdm.remote.editor.UUIDPropertyEditor;
|
35
|
|
36
|
/**
|
37
|
* TODO write controller documentation
|
38
|
*
|
39
|
* @author a.kohlbecker
|
40
|
* @date 24.03.2009
|
41
|
*/
|
42
|
|
43
|
@Controller
|
44
|
@RequestMapping(value = {"/reference/{uuid}"})
|
45
|
public class ReferenceController extends AnnotatableController<ReferenceBase, IReferenceService>
|
46
|
{
|
47
|
|
48
|
private static final List<String> NOMENCLATURAL_CITATION_INIT_STRATEGY = Arrays.asList(new String []{
|
49
|
"$",
|
50
|
"authorTeam", // TODO obsolete??
|
51
|
"inReference.authorTeam"
|
52
|
});
|
53
|
|
54
|
private static final List<String> CITATION_WITH_AUTHORTEAM_INIT_STRATEGY = Arrays.asList(new String []{
|
55
|
"authorTeam.$" // TODO obsolete??
|
56
|
});
|
57
|
|
58
|
@InitBinder
|
59
|
public void initBinder(WebDataBinder binder) {
|
60
|
binder.registerCustomEditor(UUID.class, new UUIDPropertyEditor());
|
61
|
}
|
62
|
|
63
|
public ReferenceController(){
|
64
|
setInitializationStrategy(Arrays.asList(new String[]{
|
65
|
"$",
|
66
|
"authorTeam.$" // TODO obsolete??
|
67
|
}));
|
68
|
}
|
69
|
|
70
|
/* (non-Javadoc)
|
71
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
72
|
*/
|
73
|
@Autowired
|
74
|
@Override
|
75
|
public void setService(IReferenceService service) {
|
76
|
this.service = service;
|
77
|
}
|
78
|
|
79
|
/**
|
80
|
* TODO write controller documentation
|
81
|
*
|
82
|
* @param request
|
83
|
* @param response
|
84
|
* @return
|
85
|
* @throws IOException
|
86
|
*/
|
87
|
@RequestMapping(
|
88
|
value = {"nomenclaturalCitation"},
|
89
|
method = RequestMethod.GET)
|
90
|
public ModelAndView doGetNomenclaturalCitation(
|
91
|
@PathVariable("uuid") UUID uuid,
|
92
|
HttpServletRequest request,
|
93
|
HttpServletResponse response,
|
94
|
@RequestParam(value = "microReference", required = false) String microReference)throws IOException {
|
95
|
ModelAndView mv = new ModelAndView();
|
96
|
ReferenceBase rb = service.load(uuid, NOMENCLATURAL_CITATION_INIT_STRATEGY);
|
97
|
if(INomenclaturalReference.class.isAssignableFrom(rb.getClass())){
|
98
|
String nomRefCit = ((INomenclaturalReference)rb).getNomenclaturalCitation(microReference);
|
99
|
mv.addObject(nomRefCit);
|
100
|
return mv;
|
101
|
} else {
|
102
|
response.sendError(400, "The supplied reference-uuid must specify a INomenclaturalReference.");
|
103
|
}
|
104
|
return mv;
|
105
|
}
|
106
|
|
107
|
@RequestMapping(
|
108
|
value = {"authorTeam"},
|
109
|
method = RequestMethod.GET)
|
110
|
public ModelAndView doGetAuthorTeam(
|
111
|
@PathVariable("uuid") UUID uuid,
|
112
|
HttpServletRequest request,
|
113
|
HttpServletResponse response) {
|
114
|
ModelAndView mv = new ModelAndView();
|
115
|
ReferenceBase rb = service.load(uuid, CITATION_WITH_AUTHORTEAM_INIT_STRATEGY);
|
116
|
if(rb.getAuthorTeam() != null){
|
117
|
mv.addObject(rb.getAuthorTeam());
|
118
|
}
|
119
|
return mv;
|
120
|
}
|
121
|
|
122
|
}
|