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
;
42 import eu
.etaxonomy
.cdm
.strategy
.TaggedTextGenerator
;
45 * TODO write controller documentation
47 * @author a.kohlbecker
52 @RequestMapping(value
= {"/taxon/{uuid}"})
53 public class TaxonController
extends AnnotatableController
<TaxonBase
, ITaxonService
>
55 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
58 private IOccurrenceService occurrenceService
;
60 private INameService nameService
;
62 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
66 public TaxonController(){
68 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
73 public void setService(ITaxonService service
) {
74 this.service
= service
;
79 * Get the set of accepted {@link Taxon} entities for a given
80 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
82 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
86 * @return a set on a list of {@link Taxon} entities which are initialized
87 * using the following initialization strategy:
88 * {@link #DEFAULT_INIT_STRATEGY}
91 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
92 public Set
<TaxonBase
> doGetAccepted(
93 @PathVariable("uuid") UUID uuid
,
94 HttpServletRequest request
,
95 HttpServletResponse response
) throws IOException
{
96 logger
.info("getAccepted() " + request
.getServletPath());
97 TaxonBase tb
= service
.load(uuid
);
98 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
99 if(tb
instanceof Taxon
){
100 //the taxon already is accepted
101 //FIXME take the current view into account once views are implemented!!!
102 resultset
.add((Taxon
)tb
);
104 Synonym syn
= (Synonym
)tb
;
105 resultset
.addAll(syn
.getAcceptedTaxa());
111 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
112 public Set
<TaxonNode
> doGetTaxonNodes(
113 @PathVariable("uuid") UUID uuid
,
114 HttpServletRequest request
,
115 HttpServletResponse response
) throws IOException
{
116 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
117 if(tb
instanceof Taxon
){
118 return ((Taxon
)tb
).getTaxonNodes();
120 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
125 @RequestMapping(value
= "specimensOrObersvations", method
= RequestMethod
.GET
)
126 public ModelAndView
doListSpecimensOrObersvations(
127 @PathVariable("uuid") UUID uuid
,
128 HttpServletRequest request
,
129 HttpServletResponse response
) throws IOException
{
130 logger
.info("doListSpecimensOrObersvations() - " + request
.getServletPath());
132 ModelAndView mv
= new ModelAndView();
134 TaxonBase tb
= service
.load(uuid
);
136 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
137 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
139 if(tb
instanceof Taxon
){
140 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAnyAssociation(
141 null, (Taxon
)tb
, null, 0, orderHints
, null);
142 mv
.addObject(specimensOrObersvations
);
144 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
151 @RequestMapping(value
= "taggedName", method
= RequestMethod
.GET
)
152 public ModelAndView
doGetTaggedName(
153 @PathVariable("uuid") UUID uuid
,
154 HttpServletRequest request
,
155 HttpServletResponse response
) throws IOException
{
156 logger
.info("doGetDescriptionElementsByType() - " + request
.getServletPath());
158 ModelAndView mv
= new ModelAndView();
160 TaxonBase tb
= service
.load(uuid
, Arrays
.asList(new String
[] {"name"}));
161 mv
.addObject(nameService
.getTaggedName(tb
.getName().getUuid()));