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
.INaturalLanguageGenerator
;
33 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
35 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
36 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
37 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
39 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
40 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
41 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
42 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
43 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
46 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
49 * TODO write controller documentation
51 * @author a.kohlbecker
56 @RequestMapping(value
= {"/description/{uuid}", "/description/{uuid_list}", "/descriptionelement/{descriptionelement_uuid}", "/featuretree/{featuretree_uuid}"})
57 public class DescriptionController
extends AnnotatableController
<DescriptionBase
, IDescriptionService
>
60 private IFeatureTreeService featureTreeService
;
63 public DescriptionController(){
67 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
70 "root.feature.representations",
71 "root.children.feature.representations",
75 public void initBinder(WebDataBinder binder
) {
76 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
77 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
78 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
82 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
86 public void setService(IDescriptionService service
) {
87 this.service
= service
;
91 * TODO write controller method documentation
98 @RequestMapping(value
= {"/featuretree/{featuretree_uuid}"}, method
= RequestMethod
.GET
)
99 public FeatureTree
doGetFeatureTree(
100 @PathVariable("featuretree_uuid") UUID uuid
,
101 HttpServletRequest request
,
102 HttpServletResponse response
)throws IOException
{
103 FeatureTree featureTree
= featureTreeService
.load(uuid
, FEATURETREE_INIT_STRATEGY
);
104 if(featureTree
== null){
105 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
110 @RequestMapping(value
= "/descriptionelement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
111 public Pager
<Annotation
> getAnnotations(
112 @PathVariable("descriptionelement_uuid") UUID uuid
,
113 HttpServletRequest request
,
114 HttpServletResponse response
) throws IOException
{
115 logger
.info("getAnnotations() - " + request
.getServletPath());
116 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
117 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, ANNOTATION_INIT_STRATEGY
);
122 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
123 public NamedAreaTree doGetOrderedDistributions(
124 @PathVariable("uuid_list") UuidList descriptionUuidList,
125 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
126 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
127 HttpServletRequest request, HttpServletResponse response) {
128 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
129 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
130 TaxonDescription description;
131 for (UUID descriptionUuid : descriptionUuidList) {
132 description = (TaxonDescription) service.load(descriptionUuid);
133 taxonDescriptions.add(description);
135 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
140 @RequestMapping(value
= "/description/{uuid}/naturallanguagedescription/{featuretree_uuid}", method
= RequestMethod
.GET
)
141 public ModelAndView
doGenerateNaturalLanguageDescription(
142 @PathVariable("uuid") UUID uuid
,
143 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
144 HttpServletRequest request
,
145 HttpServletResponse response
) throws IOException
{
146 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getServletPath());
148 DescriptionBase description
= service
.load(uuid
);
150 ModelAndView mv
= new ModelAndView();
152 List
<Language
> languages
= LocaleContext
.getLanguages();
154 if(!(description
instanceof TaxonDescription
)){
155 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
156 // will terminate thread
159 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, FEATURETREE_INIT_STRATEGY
);
160 if(featureTree
== null){
161 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
162 // will terminate thread
165 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
167 (TaxonDescription
)description
,
171 mv
.addObject(naturalLanguageDescription
);
176 @RequestMapping(value
= "/description/{uuid}/hasstructureddata", method
= RequestMethod
.GET
)
177 public ModelAndView
doHasStructuredData(
178 @PathVariable("uuid") UUID uuid
,
179 HttpServletRequest request
,
180 HttpServletResponse response
) throws IOException
{
181 logger
.info("doHasStructuredData() - " + request
.getServletPath());
183 ModelAndView mv
= new ModelAndView();
185 DescriptionBase description
= service
.load(uuid
);
187 if(!(description
instanceof TaxonDescription
)){
188 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
189 // will terminate thread
192 boolean hasStructuredData
= service
.hasStructuredData(description
);
194 mv
.addObject(hasStructuredData
);