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
.Synonym
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
40 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
41 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
44 * TODO write controller documentation
46 * @author a.kohlbecker
51 @RequestMapping(value
= {"/taxon/{uuid}"})
52 public class TaxonController
extends BaseController
<TaxonBase
, ITaxonService
>
54 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
57 private IOccurrenceService occurrenceService
;
59 private INameService nameService
;
61 private ITaxonService taxonService
;
64 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
68 public TaxonController(){
70 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
75 public void setService(ITaxonService service
) {
76 this.service
= service
;
81 * Get the set of accepted {@link Taxon} entities for a given
82 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
84 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
88 * @return a set on a list of {@link Taxon} entities which are initialized
89 * using the following initialization strategy:
90 * {@link #DEFAULT_INIT_STRATEGY}
93 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
94 public Set
<TaxonBase
> doGetAccepted(
95 @PathVariable("uuid") UUID uuid
,
96 HttpServletRequest request
,
97 HttpServletResponse response
) throws IOException
{
98 logger
.info("getAccepted() " + request
.getServletPath());
99 TaxonBase tb
= service
.load(uuid
);
100 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
101 if(tb
instanceof Taxon
){
102 //the taxon already is accepted
103 //FIXME take the current view into account once views are implemented!!!
104 resultset
.add((Taxon
)tb
);
106 Synonym syn
= (Synonym
)tb
;
107 resultset
.addAll(syn
.getAcceptedTaxa());
113 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
114 public Set
<TaxonNode
> doGetTaxonNodes(
115 @PathVariable("uuid") UUID uuid
,
116 HttpServletRequest request
,
117 HttpServletResponse response
) throws IOException
{
118 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
119 if(tb
instanceof Taxon
){
120 return ((Taxon
)tb
).getTaxonNodes();
122 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
128 @RequestMapping(value
= "specimensOrObersvations", method
= RequestMethod
.GET
)
129 public ModelAndView
doListSpecimensOrObersvations(
130 @PathVariable("uuid") UUID uuid
,
131 HttpServletRequest request
,
132 HttpServletResponse response
) throws IOException
{
133 logger
.info("doListSpecimensOrObersvations() - " + request
.getServletPath());
135 ModelAndView mv
= new ModelAndView();
137 TaxonBase tb
= service
.load(uuid
);
139 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
140 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
142 if(tb
instanceof Taxon
){
143 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAnyAssociation(
144 null, (Taxon
)tb
, null, 0, orderHints
, null);
145 mv
.addObject(specimensOrObersvations
);
147 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
154 @RequestMapping(value
= "taggedName", method
= RequestMethod
.GET
)
155 public ModelAndView
doGetTaggedName(
156 @PathVariable("uuid") UUID uuid
,
157 HttpServletRequest request
,
158 HttpServletResponse response
) throws IOException
{
159 logger
.info("doGetDescriptionElementsByType() - " + request
.getServletPath());
161 ModelAndView mv
= new ModelAndView();
163 TaxonBase tb
= service
.load(uuid
, Arrays
.asList(new String
[] {"name"}));
164 mv
.addObject(nameService
.getTaggedName(tb
.getName().getUuid()));
169 * FIXME change @RequestMapping to /taxon/findBestMatchingTaxon and also move into TaxonListController
171 @RequestMapping(value
= "/bestMatchingTaxon/{taxonName}", method
= RequestMethod
.GET
)
172 public TaxonBase
doFindBestMatchingTaxon(
173 @PathVariable("taxonName") String taxonName
,
174 HttpServletRequest request
,
175 HttpServletResponse response
)throws IOException
{
177 Taxon bestMatchingTaxon
= taxonService
.findBestMatchingTaxon(taxonName
);
179 return bestMatchingTaxon
;