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
.IOccurrenceService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
34 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
39 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
40 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
43 * TODO write controller documentation
45 * @author a.kohlbecker
50 @RequestMapping(value
= {"/taxon/{uuid}"})
51 public class TaxonController
extends AnnotatableController
<TaxonBase
, ITaxonService
>
53 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
56 private IOccurrenceService occurrenceService
;
58 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
62 public TaxonController(){
64 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
68 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
72 public void setService(ITaxonService service
) {
73 this.service
= service
;
78 * Get the set of accepted {@link Taxon} entities for a given
79 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
81 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
85 * @return a set on a list of {@link Taxon} entities which are initialized
86 * using the following initialization strategy:
87 * {@link #DEFAULT_INIT_STRATEGY}
90 @RequestMapping(value
= "accepted", method
= RequestMethod
.GET
)
91 public Set
<TaxonBase
> doGetAccepted(
92 @PathVariable("uuid") UUID uuid
,
93 HttpServletRequest request
,
94 HttpServletResponse response
) throws IOException
{
95 logger
.info("getAccepted() " + request
.getServletPath());
96 TaxonBase tb
= service
.load(uuid
);
97 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
98 if(tb
instanceof Taxon
){
99 //the taxon already is accepted
100 //FIXME take the current view into account once views are implemented!!!
101 resultset
.add((Taxon
)tb
);
103 Synonym syn
= (Synonym
)tb
;
104 resultset
.addAll(syn
.getAcceptedTaxa());
110 @RequestMapping(value
= "taxonNodes", method
= RequestMethod
.GET
)
111 public Set
<TaxonNode
> doGetTaxonNodes(
112 @PathVariable("uuid") UUID uuid
,
113 HttpServletRequest request
,
114 HttpServletResponse response
) throws IOException
{
115 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
116 if(tb
instanceof Taxon
){
117 return ((Taxon
)tb
).getTaxonNodes();
119 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
124 @RequestMapping(value
= "specimensOrObersvations", method
= RequestMethod
.GET
)
125 public ModelAndView
doListSpecimensOrObersvations(
126 @PathVariable("uuid") UUID uuid
,
127 HttpServletRequest request
,
128 HttpServletResponse response
) throws IOException
{
129 logger
.info("doGetDescriptionElementsByType() - " + request
.getServletPath());
131 ModelAndView mv
= new ModelAndView();
133 TaxonBase tb
= service
.load(uuid
);
135 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
136 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
138 if(tb
instanceof Taxon
){
139 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAnyAssociation(
140 null, (Taxon
)tb
, null, 0, orderHints
, null);
141 mv
.addObject(specimensOrObersvations
);
143 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);