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