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 io.swagger.annotations.Api;
|
14
|
|
15
|
import java.io.IOException;
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.Arrays;
|
18
|
import java.util.List;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import javax.servlet.http.HttpServletRequest;
|
22
|
import javax.servlet.http.HttpServletResponse;
|
23
|
|
24
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
import org.springframework.stereotype.Controller;
|
26
|
import org.springframework.web.bind.annotation.PathVariable;
|
27
|
import org.springframework.web.bind.annotation.RequestMapping;
|
28
|
import org.springframework.web.bind.annotation.RequestMethod;
|
29
|
import org.springframework.web.servlet.ModelAndView;
|
30
|
|
31
|
import eu.etaxonomy.cdm.api.service.INameService;
|
32
|
import eu.etaxonomy.cdm.api.service.pager.Pager;
|
33
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
34
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
35
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
36
|
|
37
|
/**
|
38
|
* TODO write controller documentation
|
39
|
*
|
40
|
* @author a.kohlbecker
|
41
|
* @date 24.03.2009
|
42
|
*/
|
43
|
|
44
|
@Controller
|
45
|
@Api("name")
|
46
|
@RequestMapping(value = {"/name/{uuid}"})
|
47
|
public class NameController extends BaseController<TaxonNameBase, INameService>
|
48
|
{
|
49
|
|
50
|
private static final List<String> TYPEDESIGNATION_INIT_STRATEGY = Arrays.asList(new String []{
|
51
|
"typeStatus.representations",
|
52
|
"typifiedNames",
|
53
|
"typeSpecimen",
|
54
|
"typeName",
|
55
|
"citation",
|
56
|
"citation.authorship.$",
|
57
|
});
|
58
|
|
59
|
private static final List<String> NAME_CACHE_INIT_STRATEGY = Arrays.asList(new String []{
|
60
|
|
61
|
});
|
62
|
|
63
|
public NameController(){
|
64
|
super();
|
65
|
setInitializationStrategy(Arrays.asList(new String[]{"$"})); //TODO still needed????
|
66
|
}
|
67
|
|
68
|
/* (non-Javadoc)
|
69
|
* @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
|
70
|
*/
|
71
|
@Autowired
|
72
|
@Override
|
73
|
public void setService(INameService service) {
|
74
|
this.service = service;
|
75
|
}
|
76
|
|
77
|
|
78
|
/**
|
79
|
* Get the list of {@link TypeDesignationBase}s of the
|
80
|
* {@link TaxonNameBase} instance identified by the <code>{name-uuid}</code>.
|
81
|
* <p>
|
82
|
* URI: <b>/{datasource-name}/name/{name-uuid}/typeDesignations</b>
|
83
|
*
|
84
|
* @param request
|
85
|
* @param response
|
86
|
* @return a List of {@link TypeDesignationBase} entities which are initialized
|
87
|
* using the {@link #TYPEDESIGNATION_INIT_STRATEGY}
|
88
|
* @throws IOException
|
89
|
*
|
90
|
* TODO obsolete method?
|
91
|
*/
|
92
|
@RequestMapping(value = { "typeDesignations" }, method = RequestMethod.GET)
|
93
|
public List<TypeDesignationBase> doGetNameTypeDesignations(
|
94
|
@PathVariable("uuid") UUID uuid, HttpServletRequest request,
|
95
|
HttpServletResponse response) throws IOException {
|
96
|
|
97
|
if (request != null) {
|
98
|
logger.info("doGetTypeDesignations()" + request.getRequestURI());
|
99
|
}
|
100
|
TaxonNameBase tnb = getCdmBaseInstance(uuid, response,
|
101
|
(List<String>) null);
|
102
|
Pager<TypeDesignationBase> p = service.getTypeDesignations(tnb, null,
|
103
|
null, null, TYPEDESIGNATION_INIT_STRATEGY);
|
104
|
return p.getRecords();
|
105
|
}
|
106
|
|
107
|
@RequestMapping(
|
108
|
value = {"nameCache"},
|
109
|
method = RequestMethod.GET)
|
110
|
public List<String> doGetNameCache(@PathVariable("uuid") UUID uuid,
|
111
|
HttpServletRequest request, HttpServletResponse response)throws IOException {
|
112
|
|
113
|
logger.info("doGetNameCache()" + request.getRequestURI());
|
114
|
TaxonNameBase tnb = getCdmBaseInstance(uuid, response, NAME_CACHE_INIT_STRATEGY);
|
115
|
NonViralName nvn = (NonViralName) tnb;
|
116
|
String nameCacheString = nvn.getNameCache();
|
117
|
List result = new ArrayList<String>();
|
118
|
result.add(nameCacheString);
|
119
|
return result;
|
120
|
|
121
|
}
|
122
|
|
123
|
@RequestMapping(value = "taggedName", method = RequestMethod.GET)
|
124
|
public ModelAndView doGetTaggedName(
|
125
|
@PathVariable("uuid") UUID uuid,
|
126
|
HttpServletRequest request,
|
127
|
HttpServletResponse response) throws IOException {
|
128
|
logger.info("doGetDescriptionElementsByType() - " + request.getRequestURI());
|
129
|
|
130
|
ModelAndView mv = new ModelAndView();
|
131
|
mv.addObject(service.getTaggedName(uuid));
|
132
|
return mv;
|
133
|
}
|
134
|
|
135
|
|
136
|
}
|