3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.cdm
.remote
.controller
;
13 import java
.io
.IOException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Arrays
;
16 import java
.util
.HashSet
;
17 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import javax
.servlet
.http
.HttpServletRequest
;
22 import javax
.servlet
.http
.HttpServletResponse
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
26 import org
.springframework
.stereotype
.Controller
;
27 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
30 import org
.springframework
.web
.servlet
.ModelAndView
;
32 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
35 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
42 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
45 * TODO write controller documentation
47 * @author a.kohlbecker
52 @RequestMapping(value
= {"/taxon/{uuid}"})
53 public class TaxonController
extends BaseController
<TaxonBase
, ITaxonService
>
55 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
58 private IOccurrenceService occurrenceService
;
60 private INameService nameService
;
62 private ITaxonService taxonService
;
65 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
69 public TaxonController(){
71 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
77 public void setService(ITaxonService service
) {
78 this.service
= service
;
83 * Get the set of accepted {@link Taxon} entities for a given
84 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
86 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
90 * @return a set on a list of {@link Taxon} entities which are initialized
91 * using the following initialization strategy:
92 * {@link #DEFAULT_INIT_STRATEGY}
95 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
96 public Set
<TaxonBase
> doGetAccepted(
97 @PathVariable("uuid") UUID uuid
,
98 HttpServletRequest request
,
99 HttpServletResponse response
) throws IOException
{
100 logger
.info("getAccepted() " + request
.getRequestURI());
101 TaxonBase tb
= service
.load(uuid
);
102 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
103 if(tb
instanceof Taxon
){
104 //the taxon already is accepted
105 //FIXME take the current view into account once views are implemented!!!
108 Synonym syn
= (Synonym
)tb
;
109 resultset
.addAll(syn
.getAcceptedTaxa());
115 @RequestMapping(value
= "classifications", method
= RequestMethod
.GET
)
116 public List
<Classification
> doGetClassifications(
117 @PathVariable("uuid") UUID uuid
,
118 HttpServletRequest request
,
119 HttpServletResponse response
) throws IOException
{
120 logger
.info("doGetClassifications(): " + request
.getRequestURI());
121 TaxonBase taxonBase
= service
.load(uuid
);
123 if (taxonBase
== null){
124 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
127 return service
.listClassifications(taxonBase
, null, null, getInitializationStrategy());
130 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
131 public Set
<TaxonNode
> doGetTaxonNodes(
132 @PathVariable("uuid") UUID uuid
,
133 HttpServletRequest request
,
134 HttpServletResponse response
) throws IOException
{
135 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
136 if(tb
instanceof Taxon
){
137 return ((Taxon
)tb
).getTaxonNodes();
139 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
145 @RequestMapping(value
= "specimensOrObservations", method
= RequestMethod
.GET
)
146 public ModelAndView
doListSpecimensOrObservations(
147 @PathVariable("uuid") UUID uuid
,
148 HttpServletRequest request
,
149 HttpServletResponse response
) throws IOException
{
150 logger
.info("doListSpecimensOrObservations() - " + request
.getRequestURI());
152 ModelAndView mv
= new ModelAndView();
154 TaxonBase tb
= service
.load(uuid
);
156 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
157 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
159 if(tb
instanceof Taxon
){
160 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, null, (Taxon
)tb
, null, null, null, orderHints
, null);
161 mv
.addObject(specimensOrObersvations
);
163 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
170 @RequestMapping(value
= "taggedName", method
= RequestMethod
.GET
)
171 public ModelAndView
doGetTaggedName(
172 @PathVariable("uuid") UUID uuid
,
173 HttpServletRequest request
,
174 HttpServletResponse response
) throws IOException
{
175 logger
.info("doGetDescriptionElementsByType() - " + request
.getRequestURI());
177 ModelAndView mv
= new ModelAndView();
179 TaxonBase tb
= service
.load(uuid
, Arrays
.asList(new String
[] {"name"}));
180 mv
.addObject(nameService
.getTaggedName(tb
.getName().getUuid()));
185 * FIXME change @RequestMapping to /taxon/findBestMatchingTaxon and also move into TaxonListController
187 @RequestMapping(value
= "/bestMatchingTaxon/{taxonName}", method
= RequestMethod
.GET
)
188 public TaxonBase
doFindBestMatchingTaxon(
189 @PathVariable("taxonName") String taxonName
,
190 HttpServletRequest request
,
191 HttpServletResponse response
)throws IOException
{
193 Taxon bestMatchingTaxon
= taxonService
.findBestMatchingTaxon(taxonName
);
195 return bestMatchingTaxon
;