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
.List
;
18 import java
.util
.UUID
;
20 import javax
.persistence
.EntityNotFoundException
;
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
.bind
.annotation
.RequestParam
;
31 import org
.springframework
.web
.servlet
.ModelAndView
;
33 import com
.wordnik
.swagger
.annotations
.Api
;
35 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.config
.IncludedTaxonConfiguration
;
40 import eu
.etaxonomy
.cdm
.api
.service
.dto
.IncludedTaxaDTO
;
41 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
42 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
43 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
44 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
45 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNodeAgentRelation
;
48 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
49 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
50 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.PagerParameters
;
53 * TODO write controller documentation
55 * @author a.kohlbecker
61 @RequestMapping(value
= {"/taxon/{uuid}"})
62 public class TaxonController
extends BaseController
<TaxonBase
, ITaxonService
>
64 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
67 private IOccurrenceService occurrenceService
;
69 private INameService nameService
;
71 private ITaxonNodeService nodeService
;
73 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
77 public TaxonController(){
79 setInitializationStrategy(Arrays
.asList(new String
[]{
81 "name.nomenclaturalReference"
89 public void setService(ITaxonService service
) {
90 this.service
= service
;
95 * Get the set of accepted {@link Taxon} entities for a given
96 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
98 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
102 * @return a set on a list of {@link Taxon} entities which are initialized
103 * using the following initialization strategy:
104 * {@link #DEFAULT_INIT_STRATEGY}
105 * @throws IOException
108 * Get the set of accepted {@link Taxon} entities for a given
109 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
111 * URI: <b>/{datasource-name}/portal/taxon/{taxon-uuid}/accepted</b>
115 * @return a Set of {@link Taxon} entities which are initialized
116 * using the following initialization strategy:
117 * {@link #SYNONYMY_INIT_STRATEGY}
118 * @throws IOException
119 * @Deprecated use getAcceptedFor() instead
122 @RequestMapping(value
= "accepted/{classification_uuid}", method
= RequestMethod
.GET
)
123 public List
<Taxon
> getAcceptedForWithClassificationFilter(
124 @PathVariable("uuid") UUID uuid
,
125 @PathVariable("classification_uuid") UUID classification_uuid
,
126 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
127 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
128 HttpServletRequest request
,
129 HttpServletResponse response
)
133 return getAcceptedFor(uuid
, classification_uuid
, pageNumber
, pageSize
, request
, response
);
136 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
137 public List
<Taxon
> getAcceptedFor(
138 @PathVariable("uuid") UUID uuid
,
139 @RequestParam(value
= "classificationFilter", required
= false) UUID classification_uuid
,
140 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
141 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
142 HttpServletRequest request
,
143 HttpServletResponse response
)
146 logger
.info("getAccepted() " + requestPathAndQuery(request
));
149 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
150 pagerParams
.normalizeAndValidate(response
);
152 List
<Taxon
> resultset
= new ArrayList
<Taxon
>();
154 resultset
= service
.listAcceptedTaxaFor(uuid
, classification_uuid
, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), null, getInitializationStrategy());
155 } catch (EntityNotFoundException e
){
156 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
162 @RequestMapping(value
= "classifications", method
= RequestMethod
.GET
)
163 public List
<Classification
> doGetClassifications(
164 @PathVariable("uuid") UUID uuid
,
165 HttpServletRequest request
,
166 HttpServletResponse response
) throws IOException
{
167 logger
.info("doGetClassifications(): " + request
.getRequestURI());
168 TaxonBase
<?
> taxonBase
= service
.load(uuid
);
170 if (taxonBase
== null){
171 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
174 return service
.listClassifications(taxonBase
, null, null, getInitializationStrategy());
177 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
178 public Set
<TaxonNode
> doGetTaxonNodes(
179 @PathVariable("uuid") UUID uuid
,
180 HttpServletRequest request
,
181 HttpServletResponse response
) throws IOException
{
183 TaxonBase
<?
> tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
184 if(tb
instanceof Taxon
){
185 return ((Taxon
)tb
).getTaxonNodes();
187 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
192 @RequestMapping(value
= "taxonNodeAgentRelations/{classification_uuid}", method
= RequestMethod
.GET
)
193 public Pager
<TaxonNodeAgentRelation
> doGetTaxonNodeAgentRelations(
194 @PathVariable("uuid") UUID uuid
,
195 @PathVariable("classification_uuid") UUID classificationUuid
,
196 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
197 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
198 HttpServletRequest request
,
199 HttpServletResponse response
) throws IOException
{
201 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
202 pagerParams
.normalizeAndValidate(response
);
204 Pager
<TaxonNodeAgentRelation
> pager
= nodeService
.pageTaxonNodeAgentRelations(uuid
, classificationUuid
,
205 pagerParams
.getPageSize(), pagerParams
.getPageIndex(), null);
212 @RequestMapping(value
= "specimensOrObservations", method
= RequestMethod
.GET
)
213 public ModelAndView
doListSpecimensOrObservations(
214 @PathVariable("uuid") UUID uuid
,
215 HttpServletRequest request
,
216 HttpServletResponse response
) throws IOException
{
217 logger
.info("doListSpecimensOrObservations() - " + request
.getRequestURI());
219 ModelAndView mv
= new ModelAndView();
221 TaxonBase
<?
> tb
= service
.load(uuid
);
223 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
224 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
226 if(tb
instanceof Taxon
){
227 List
<SpecimenOrObservationBase
<?
>> specimensOrObservations
= occurrenceService
.listByAssociatedTaxon(null, null, (Taxon
)tb
, null, null, null, orderHints
, null);
228 mv
.addObject(specimensOrObservations
);
230 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
237 @RequestMapping(value
= "associatedFieldUnits", method
= RequestMethod
.GET
)
238 public Pager
<SpecimenOrObservationBase
> doGetFieldUnits(
239 @PathVariable("uuid") UUID uuid
,
240 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
241 @RequestParam(value
= "pageNumber", required
= false) Integer pageNumber
,
242 @RequestParam(value
= "pageSize", required
= false) Integer pageSize
,
243 HttpServletRequest request
,
244 HttpServletResponse response
) throws IOException
{
245 logger
.info("doGetFieldUnits() - " + request
.getRequestURI());
247 ModelAndView mv
= new ModelAndView();
249 TaxonBase
<?
> tb
= service
.load(uuid
);
251 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
252 orderHints
.add(new OrderHint("titleCache", SortOrder
.ASCENDING
));
254 if(tb
instanceof Taxon
){
255 PagerParameters pagerParams
= new PagerParameters(pageSize
, pageNumber
);
256 pagerParams
.normalizeAndValidate(response
);
258 return occurrenceService
.pageFieldUnitsByAssociatedTaxon(null, (Taxon
) tb
, null, pagerParams
.getPageSize(), pagerParams
.getPageIndex(), orderHints
, null);
263 @RequestMapping(value
= "taggedName", method
= RequestMethod
.GET
)
264 public ModelAndView
doGetTaggedName(
265 @PathVariable("uuid") UUID uuid
,
266 HttpServletRequest request
) {
267 logger
.info("doGetDescriptionElementsByType() - " + request
.getRequestURI());
269 ModelAndView mv
= new ModelAndView();
271 TaxonBase
<?
> tb
= service
.load(uuid
, Arrays
.asList(new String
[] {"name"}));
272 mv
.addObject(nameService
.getTaggedName(tb
.getName().getUuid()));
277 * This webservice endpoint returns all taxa which are congruent or included in the taxon represented by the given taxon uuid.
278 * The result also returns the path to these taxa represented by the uuids of the taxon relationships types and doubtful information.
279 * If classificationUuids is set only taxa of classifications are returned which are included in the given classifications.
280 * Also the path to these taxa may not include taxa from other classifications.
282 * @param taxonUUIDString
283 * @param classificationStringList
284 * @param includeDoubtful
285 * @param onlyCongruent
289 * @throws IOException
292 @RequestMapping(value
= { "includedTaxa" }, method
= { RequestMethod
.GET
})
293 public ModelAndView
doGetIncludedTaxa(
294 @PathVariable("uuid") UUID uuid
,
295 @RequestParam(value
="classificationFilter", required
=false) final List
<String
> classificationStringList
,
296 @RequestParam(value
="includeDoubtful", required
=false) final boolean includeDoubtful
,
297 @RequestParam(value
="onlyCongruent", required
=false) final boolean onlyCongruent
,
298 HttpServletResponse response
,
299 HttpServletRequest request
) throws IOException
{
300 ModelAndView mv
= new ModelAndView();
302 * List<UUID> classificationFilter,
303 * boolean includeDoubtful,
304 * boolean onlyCongruent)
306 List
<UUID
> classificationFilter
= null;
307 if( classificationStringList
!= null ){
308 classificationFilter
= new ArrayList
<UUID
>();
309 for(String classString
:classificationStringList
){
310 classificationFilter
.add(UUID
.fromString(classString
));
313 final IncludedTaxonConfiguration configuration
= new IncludedTaxonConfiguration(classificationFilter
, includeDoubtful
, onlyCongruent
);
314 IncludedTaxaDTO listIncludedTaxa
= service
.listIncludedTaxa(uuid
, configuration
);
315 mv
.addObject(listIncludedTaxa
);