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
.EnumSet
;
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
.springframework
.beans
.factory
.annotation
.Autowired
;
24 import org
.springframework
.stereotype
.Controller
;
25 import org
.springframework
.web
.bind
.WebDataBinder
;
26 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
27 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
28 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
30 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
31 import org
.springframework
.web
.servlet
.ModelAndView
;
33 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
;
37 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DistributionInfoDTO
.InfoPart
;
38 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
39 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
40 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
41 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
42 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
43 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
44 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
45 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
46 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
47 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
48 import eu
.etaxonomy
.cdm
.model
.description
.StateData
;
49 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
51 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
52 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
53 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
54 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
55 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
56 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
57 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
60 * TODO write controller documentation
62 * @author a.kohlbecker
67 @RequestMapping(value
= {"/description/{uuid}", "/description/{uuid_list}"})
68 public class DescriptionController
extends BaseController
<DescriptionBase
, IDescriptionService
>
71 private IFeatureTreeService featureTreeService
;
74 private ITermService termService
;
78 private IEditGeoService geoService
;
80 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
83 "elements.sources.citation.authorTeam",
84 "elements.sources.nameUsedInSource",
85 "elements.multilanguageText",
91 public void initBinder(WebDataBinder binder
) {
92 super.initBinder(binder
);
93 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
94 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
95 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
99 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
103 public void setService(IDescriptionService service
) {
104 this.service
= service
;
107 @RequestMapping(value
= "hasStructuredData", method
= RequestMethod
.GET
)
108 public ModelAndView
doHasStructuredData(
109 @PathVariable("uuid") UUID uuid
,
110 HttpServletRequest request
,
111 HttpServletResponse response
) throws IOException
{
112 logger
.info("doHasStructuredData() - " + request
.getRequestURI());
114 ModelAndView mv
= new ModelAndView();
116 DescriptionBase description
= service
.load(uuid
);
118 if(!(description
instanceof TaxonDescription
)){
119 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
120 // will terminate thread
123 boolean hasStructuredData
= service
.hasStructuredData(description
);
125 mv
.addObject(hasStructuredData
);
129 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}", method
= RequestMethod
.GET
)
130 public ModelAndView
doGetDescriptionElement(
131 @PathVariable("descriptionelement_uuid") UUID uuid
,
132 HttpServletRequest request
,
133 HttpServletResponse response
) throws IOException
{
135 ModelAndView mv
= new ModelAndView();
136 logger
.info("doGetDescriptionElement() - " + request
.getRequestURI());
137 DescriptionElementBase element
= service
.getDescriptionElementByUuid(uuid
);
138 if(element
== null) {
139 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
141 mv
.addObject(element
);
145 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/annotations", method
= RequestMethod
.GET
)
146 public Pager
<Annotation
> doGetDescriptionElementAnnotations(
147 @PathVariable("descriptionelement_uuid") UUID uuid
,
148 HttpServletRequest request
,
149 HttpServletResponse response
) throws IOException
{
150 logger
.info("doGetDescriptionElementAnnotations() - " + request
.getRequestURI());
151 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
152 if(annotatableEntity
== null){
153 HttpStatusMessage
.UUID_INVALID
.send(response
);
154 // method will exit here
158 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, getInitializationStrategy());
162 @RequestMapping(value
= "/descriptionElement/{descriptionelement_uuid}/states", method
= RequestMethod
.GET
)
163 public ModelAndView
doGetDescriptionElementStates(
164 @PathVariable("descriptionelement_uuid") UUID uuid
,
165 HttpServletRequest request
,
166 HttpServletResponse response
) throws IOException
{
167 logger
.info("doGetDescriptionElementStates() - " + request
.getRequestURI());
169 ModelAndView mv
= new ModelAndView();
171 DescriptionElementBase descriptionElement
= service
.loadDescriptionElement(uuid
,
172 Arrays
.asList( new String
[]{
173 "states.state.representations",
177 if(descriptionElement
== null){
178 HttpStatusMessage
.UUID_INVALID
.send(response
);
179 // method will exit here
183 if(descriptionElement
instanceof CategoricalData
){
186 List
<StateData
> states
= ((CategoricalData
)descriptionElement
).getStateData();
187 mv
.addObject(states
);
192 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
193 public NamedAreaTree doGetOrderedDistributions(
194 @PathVariable("uuid_list") UuidList descriptionUuidList,
195 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
196 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
197 HttpServletRequest request, HttpServletResponse response) {
198 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
199 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
200 TaxonDescription description;
201 for (UUID descriptionUuid : descriptionUuidList) {
202 description = (TaxonDescription) service.load(descriptionUuid);
203 taxonDescriptions.add(description);
205 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
210 @RequestMapping(value
= "/description/{uuid}/naturalLanguageDescription/{featuretree_uuid}", method
= RequestMethod
.GET
)
211 public ModelAndView
doGenerateNaturalLanguageDescription(
212 @PathVariable("uuid") UUID uuid
,
213 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
214 HttpServletRequest request
,
215 HttpServletResponse response
) throws IOException
{
216 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getRequestURI());
218 DescriptionBase description
= service
.load(uuid
);
220 ModelAndView mv
= new ModelAndView();
222 List
<Language
> languages
= LocaleContext
.getLanguages();
224 if(!(description
instanceof TaxonDescription
)){
225 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
226 // will terminate thread
229 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, null);
230 if(featureTree
== null){
231 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
232 // will terminate thread
235 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
237 (TaxonDescription
)description
,
240 TextData textData
= TextData
.NewInstance(Feature
.DESCRIPTION());
241 textData
.putText(Language
.DEFAULT(), naturalLanguageDescription
);
242 mv
.addObject(textData
);
249 * possible values: condensedStatusString, tree, mapUriParams,
251 * @param subAreaPreference
252 * @param statusOrderPreference
253 * @param hideMarkedAreasList
259 @RequestMapping(value
= "/description/distributionInfoFor/{uuid}", method
= RequestMethod
.GET
)
260 public ModelAndView
doGetDistributionInfo(
261 @PathVariable("uuid") UUID taxonUuid
,
262 @RequestParam("part") Set
<InfoPart
> partSet
,
263 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
264 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
265 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
266 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> omitLevels
,
267 HttpServletRequest request
,
268 HttpServletResponse response
) {
270 logger
.debug("doGetDistributionInfo() - " + requestPathAndQuery(request
));
272 ModelAndView mv
= new ModelAndView();
274 Set
<MarkerType
> hideMarkedAreas
= null;
275 if(hideMarkedAreasList
!= null){
276 hideMarkedAreas
= hideMarkedAreasList
.asSet();
279 EnumSet
<InfoPart
> parts
= EnumSet
.copyOf(partSet
);
281 DistributionInfoDTO dto
= geoService
.composeDistributionInfoFor(parts
, taxonUuid
, subAreaPreference
, statusOrderPreference
,
282 hideMarkedAreas
, omitLevels
, LocaleContext
.getLanguages());