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
.Arrays
;
15 import java
.util
.HashSet
;
16 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import javax
.servlet
.http
.HttpServletRequest
;
21 import javax
.servlet
.http
.HttpServletResponse
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
25 import org
.springframework
.stereotype
.Controller
;
26 import org
.springframework
.web
.bind
.WebDataBinder
;
27 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
28 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
30 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
33 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
34 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
35 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
36 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
37 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
40 * TODO write controller documentation
42 * @author a.kohlbecker
47 @RequestMapping(value
= {"/taxon/*", "/taxon/{uuid}"})
48 public class TaxonController
extends AnnotatableController
<TaxonBase
, ITaxonService
>
50 public static final Logger logger
= Logger
.getLogger(TaxonController
.class);
52 protected static final List
<String
> TAXONNODE_INIT_STRATEGY
= Arrays
.asList(new String
[]{
56 public TaxonController(){
58 setUuidParameterPattern("^/taxon/([^/?#&\\.]+).*");
59 setInitializationStrategy(Arrays
.asList(new String
[]{"$","name.nomenclaturalReference"}));
63 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
67 public void setService(ITaxonService service
) {
68 this.service
= service
;
73 * Get the set of accepted {@link Taxon} entities for a given
74 * {@link TaxonBase} entity identified by the <code>{taxon-uuid}</code>.
76 * URI: <b>/{datasource-name}/taxon/{taxon-uuid}/accepted</b>
80 * @return a set on a list of {@link Taxon} entities which are initialized
81 * using the following initialization strategy:
82 * {@link #DEFAULT_INIT_STRATEGY}
85 @RequestMapping(value
= "{uuid}/accepted", method
= RequestMethod
.GET
)
86 public Set
<TaxonBase
> doGetAccepted(
87 @PathVariable("uuid") UUID uuid
,
88 HttpServletRequest request
,
89 HttpServletResponse response
) throws IOException
{
90 logger
.info("getAccepted() " + request
.getServletPath());
91 TaxonBase tb
= service
.load(uuid
);
92 HashSet
<TaxonBase
> resultset
= new HashSet
<TaxonBase
>();
93 if(tb
instanceof Taxon
){
94 //the taxon already is accepted
95 //FIXME take the current view into account once views are implemented!!!
96 resultset
.add((Taxon
)tb
);
98 Synonym syn
= (Synonym
)tb
;
99 resultset
.addAll(syn
.getAcceptedTaxa());
105 @RequestMapping(value
= "{uuid}/taxonNodes", method
= RequestMethod
.GET
)
106 public Set
<TaxonNode
> doGetTaxonNodes(
107 @PathVariable("uuid") UUID uuid
,
108 HttpServletRequest request
,
109 HttpServletResponse response
) throws IOException
{
110 TaxonBase tb
= service
.load(uuid
, TAXONNODE_INIT_STRATEGY
);
111 if(tb
instanceof Taxon
){
112 return ((Taxon
)tb
).getTaxonNodes();
114 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);