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
.DescriptionBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
40 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
41 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
42 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
43 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
44 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
47 * TODO write controller documentation
49 * @author a.kohlbecker
54 @RequestMapping(value
= {"/description/{uuid}", "/description/{uuid_list}"})
55 public class DescriptionController
extends AnnotatableController
<DescriptionBase
, IDescriptionService
>
58 private IFeatureTreeService featureTreeService
;
61 public DescriptionController(){
65 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
68 "root.feature.representations",
69 "root.children.feature.representations",
73 public void initBinder(WebDataBinder binder
) {
74 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
75 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
76 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
80 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
84 public void setService(IDescriptionService service
) {
85 this.service
= service
;
94 @RequestMapping(value
= {"/featureTree/{uuid}"}, method
= RequestMethod
.GET
)
95 public FeatureTree
doGetFeatureTree(
96 @PathVariable("uuid") UUID uuid
,
97 HttpServletRequest request
,
98 HttpServletResponse response
)throws IOException
{
99 FeatureTree featureTree
= getCdmBaseInstance(FeatureTree
.class, featureTreeService
, uuid
, response
, FEATURETREE_INIT_STRATEGY
);
104 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
105 public Pager
<Annotation
> getAnnotations(
106 @PathVariable("descriptionelement_uuid") UUID uuid
,
107 HttpServletRequest request
,
108 HttpServletResponse response
) throws IOException
{
109 logger
.info("getAnnotations() - " + request
.getServletPath());
110 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
111 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, ANNOTATION_INIT_STRATEGY
);
116 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
117 public NamedAreaTree doGetOrderedDistributions(
118 @PathVariable("uuid_list") UuidList descriptionUuidList,
119 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
120 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
121 HttpServletRequest request, HttpServletResponse response) {
122 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
123 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
124 TaxonDescription description;
125 for (UUID descriptionUuid : descriptionUuidList) {
126 description = (TaxonDescription) service.load(descriptionUuid);
127 taxonDescriptions.add(description);
129 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
134 @RequestMapping(value
= "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method
= RequestMethod
.GET
)
135 public ModelAndView
doGenerateNaturalLanguageDescription(
136 @PathVariable("uuid") UUID uuid
,
137 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
138 HttpServletRequest request
,
139 HttpServletResponse response
) throws IOException
{
140 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getServletPath());
142 DescriptionBase description
= service
.load(uuid
);
144 ModelAndView mv
= new ModelAndView();
146 List
<Language
> languages
= LocaleContext
.getLanguages();
148 if(!(description
instanceof TaxonDescription
)){
149 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
150 // will terminate thread
153 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, FEATURETREE_INIT_STRATEGY
);
154 if(featureTree
== null){
155 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
156 // will terminate thread
159 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
161 (TaxonDescription
)description
,
165 mv
.addObject(naturalLanguageDescription
);
170 @RequestMapping(value
= "/description/{uuid}/hasStructuredData", method
= RequestMethod
.GET
)
171 public ModelAndView
doHasStructuredData(
172 @PathVariable("uuid") UUID uuid
,
173 HttpServletRequest request
,
174 HttpServletResponse response
) throws IOException
{
175 logger
.info("doHasStructuredData() - " + request
.getServletPath());
177 ModelAndView mv
= new ModelAndView();
179 DescriptionBase description
= service
.load(uuid
);
181 if(!(description
instanceof TaxonDescription
)){
182 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
183 // will terminate thread
186 boolean hasStructuredData
= service
.hasStructuredData(description
);
188 mv
.addObject(hasStructuredData
);