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
.common
.Representation
;
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
.TaxonDescription
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
42 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
43 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
45 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
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 AnnotatableController
<DescriptionBase
, IDescriptionService
>
61 private IFeatureTreeService featureTreeService
;
64 public DescriptionController(){
68 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
71 "root.feature.representations",
72 "root.children.feature.representations",
73 "root.children.children.feature.representations",
78 public void initBinder(WebDataBinder binder
) {
79 super.initBinder(binder
);
80 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
81 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
85 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
89 public void setService(IDescriptionService service
) {
90 this.service
= service
;
99 @RequestMapping(value
= {"/featureTree/{uuid}"}, method
= RequestMethod
.GET
)
100 public FeatureTree
doGetFeatureTree(
101 @PathVariable("uuid") UUID uuid
,
102 HttpServletRequest request
,
103 HttpServletResponse response
)throws IOException
{
104 FeatureTree featureTree
= getCdmBaseInstance(FeatureTree
.class, featureTreeService
, uuid
, response
, FEATURETREE_INIT_STRATEGY
);
109 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
110 public Pager
<Annotation
> getAnnotations(
111 @PathVariable("descriptionelement_uuid") UUID uuid
,
112 HttpServletRequest request
,
113 HttpServletResponse response
) throws IOException
{
114 logger
.info("getAnnotations() - " + request
.getServletPath());
115 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
116 if(annotatableEntity
== null){
117 HttpStatusMessage
.UUID_INVALID
.send(response
);
118 // method will exit here
120 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, ANNOTATION_INIT_STRATEGY
);
125 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
126 public NamedAreaTree doGetOrderedDistributions(
127 @PathVariable("uuid_list") UuidList descriptionUuidList,
128 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
129 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
130 HttpServletRequest request, HttpServletResponse response) {
131 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getServletPath());
132 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
133 TaxonDescription description;
134 for (UUID descriptionUuid : descriptionUuidList) {
135 description = (TaxonDescription) service.load(descriptionUuid);
136 taxonDescriptions.add(description);
138 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
143 @RequestMapping(value
= "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method
= RequestMethod
.GET
)
144 public ModelAndView
doGenerateNaturalLanguageDescription(
145 @PathVariable("uuid") UUID uuid
,
146 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
147 HttpServletRequest request
,
148 HttpServletResponse response
) throws IOException
{
149 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getServletPath());
151 DescriptionBase description
= service
.load(uuid
);
153 ModelAndView mv
= new ModelAndView();
155 List
<Language
> languages
= LocaleContext
.getLanguages();
157 if(!(description
instanceof TaxonDescription
)){
158 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
159 // will terminate thread
162 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, null);
163 if(featureTree
== null){
164 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
165 // will terminate thread
168 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
170 (TaxonDescription
)description
,
174 TextData textData
= TextData
.NewInstance(Feature
.DESCRIPTION());
175 textData
.putText(naturalLanguageDescription
, Language
.DEFAULT());
177 mv
.addObject(textData
);
183 @RequestMapping(value
= "/description/{uuid}/hasStructuredData", method
= RequestMethod
.GET
)
184 public ModelAndView
doHasStructuredData(
185 @PathVariable("uuid") UUID uuid
,
186 HttpServletRequest request
,
187 HttpServletResponse response
) throws IOException
{
188 logger
.info("doHasStructuredData() - " + request
.getServletPath());
190 ModelAndView mv
= new ModelAndView();
192 DescriptionBase description
= service
.load(uuid
);
194 if(!(description
instanceof TaxonDescription
)){
195 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
196 // will terminate thread
199 boolean hasStructuredData
= service
.hasStructuredData(description
);
201 mv
.addObject(hasStructuredData
);