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
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
21 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
22 import org
.springframework
.stereotype
.Controller
;
23 import org
.springframework
.web
.bind
.WebDataBinder
;
24 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
25 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
28 import org
.springframework
.web
.servlet
.ModelAndView
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
35 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
39 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
40 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
42 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
43 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
46 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
47 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
50 * TODO write controller documentation
52 * @author a.kohlbecker
57 @RequestMapping(value
= {"/description/{uuid}", "/description/{uuid_list}"})
58 public class DescriptionController
extends BaseController
<DescriptionBase
, IDescriptionService
>
61 private IFeatureTreeService featureTreeService
;
64 public DescriptionController(){
68 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
71 "elements.sources.citation.authorTeam",
72 "elements.sources.nameUsedInSource.originalNameString",
73 "elements.multilanguageText",
79 public void initBinder(WebDataBinder binder
) {
80 super.initBinder(binder
);
81 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
82 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
86 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
90 public void setService(IDescriptionService service
) {
91 this.service
= service
;
94 @RequestMapping(value
= "hasStructuredData", method
= RequestMethod
.GET
)
95 public ModelAndView
doHasStructuredData(
96 @PathVariable("uuid") UUID uuid
,
97 HttpServletRequest request
,
98 HttpServletResponse response
) throws IOException
{
99 logger
.info("doHasStructuredData() - " + request
.getRequestURI());
101 ModelAndView mv
= new ModelAndView();
103 DescriptionBase description
= service
.load(uuid
);
105 if(!(description
instanceof TaxonDescription
)){
106 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
107 // will terminate thread
110 boolean hasStructuredData
= service
.hasStructuredData(description
);
112 mv
.addObject(hasStructuredData
);
116 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}", method
= RequestMethod
.GET
)
117 public ModelAndView
doGetDescriptionElement(
118 @PathVariable("descriptionelement_uuid") UUID uuid
,
119 HttpServletRequest request
,
120 HttpServletResponse response
) throws IOException
{
122 ModelAndView mv
= new ModelAndView();
123 logger
.info("doGetDescriptionElement() - " + request
.getRequestURI());
124 DescriptionElementBase element
= service
.getDescriptionElementByUuid(uuid
);
125 if(element
== null) {
126 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
128 mv
.addObject(element
);
132 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/annotations", method
= RequestMethod
.GET
)
133 public Pager
<Annotation
> doGetDescriptionElementAnnotations(
134 @PathVariable("descriptionelement_uuid") UUID uuid
,
135 HttpServletRequest request
,
136 HttpServletResponse response
) throws IOException
{
137 logger
.info("doGetDescriptionElementAnnotations() - " + request
.getRequestURI());
138 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
139 if(annotatableEntity
== null){
140 HttpStatusMessage
.UUID_INVALID
.send(response
);
141 // method will exit here
145 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, getInitializationStrategy());
149 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/states", method
= RequestMethod
.GET
)
150 public ModelAndView
doGetDescriptionElementStates(
151 @PathVariable("descriptionelement_uuid") UUID uuid
,
152 HttpServletRequest request
,
153 HttpServletResponse response
) throws IOException
{
154 logger
.info("doGetDescriptionElementStates() - " + request
.getRequestURI());
156 ModelAndView mv
= new ModelAndView();
158 DescriptionElementBase descriptionElement
= service
.loadDescriptionElement(uuid
,
159 Arrays
.asList( new String
[]{
160 "states.state.representations",
164 if(descriptionElement
== null){
165 HttpStatusMessage
.UUID_INVALID
.send(response
);
166 // method will exit here
170 if(descriptionElement
instanceof CategoricalData
){
173 List
<StateData
> states
= ((CategoricalData
)descriptionElement
).getStateData();
174 mv
.addObject(states
);
179 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
180 public NamedAreaTree doGetOrderedDistributions(
181 @PathVariable("uuid_list") UuidList descriptionUuidList,
182 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
183 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
184 HttpServletRequest request, HttpServletResponse response) {
185 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
186 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
187 TaxonDescription description;
188 for (UUID descriptionUuid : descriptionUuidList) {
189 description = (TaxonDescription) service.load(descriptionUuid);
190 taxonDescriptions.add(description);
192 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
197 @RequestMapping(value
= "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method
= RequestMethod
.GET
)
198 public ModelAndView
doGenerateNaturalLanguageDescription(
199 @PathVariable("uuid") UUID uuid
,
200 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
201 HttpServletRequest request
,
202 HttpServletResponse response
) throws IOException
{
203 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getRequestURI());
205 DescriptionBase description
= service
.load(uuid
);
207 ModelAndView mv
= new ModelAndView();
209 List
<Language
> languages
= LocaleContext
.getLanguages();
211 if(!(description
instanceof TaxonDescription
)){
212 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
213 // will terminate thread
216 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, null);
217 if(featureTree
== null){
218 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
219 // will terminate thread
222 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
224 (TaxonDescription
)description
,
227 TextData textData
= TextData
.NewInstance(Feature
.DESCRIPTION());
228 textData
.putText(Language
.DEFAULT(), naturalLanguageDescription
);
229 mv
.addObject(textData
);