2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.remote
.controller
;
12 import java
.io
.IOException
;
13 import java
.util
.Arrays
;
14 import java
.util
.List
;
15 import java
.util
.UUID
;
17 import javax
.servlet
.http
.HttpServletRequest
;
18 import javax
.servlet
.http
.HttpServletResponse
;
20 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
21 import org
.springframework
.stereotype
.Controller
;
22 import org
.springframework
.web
.bind
.WebDataBinder
;
23 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
24 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
27 import org
.springframework
.web
.servlet
.ModelAndView
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
33 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
34 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
35 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
36 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
37 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
39 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
40 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
41 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
42 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
43 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
44 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
45 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
46 import io
.swagger
.annotations
.Api
;
49 * TODO write controller documentation
51 * @author a.kohlbecker
57 @RequestMapping(value
= {"/description/{uuid}", "/description/{uuid_list}"})
58 public class DescriptionController
extends AbstractIdentifiableController
<DescriptionBase
, IDescriptionService
>
61 private IFeatureTreeService featureTreeService
;
64 private ITermService termService
;
66 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
69 "elements.sources.citation.authorship",
70 "elements.sources.nameUsedInSource",
71 "elements.multilanguageText",
77 public void initBinder(WebDataBinder binder
) {
78 super.initBinder(binder
);
79 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
80 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
81 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
86 public void setService(IDescriptionService service
) {
87 this.service
= service
;
90 @RequestMapping(value
= "hasStructuredData", method
= RequestMethod
.GET
)
91 public ModelAndView
doHasStructuredData(
92 @PathVariable("uuid") UUID uuid
,
93 HttpServletRequest request
,
94 HttpServletResponse response
) throws IOException
{
95 logger
.info("doHasStructuredData() - " + request
.getRequestURI());
97 ModelAndView mv
= new ModelAndView();
99 DescriptionBase
<?
> description
= service
.load(uuid
);
101 if(!(description
instanceof TaxonDescription
)){
102 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
103 // will terminate thread
106 boolean hasStructuredData
= service
.hasStructuredData(description
);
108 mv
.addObject(hasStructuredData
);
113 @RequestMapping(value = "{uuid_list}/namedAreaTree", method = RequestMethod.GET)
114 public NamedAreaTree doGetOrderedDistributions(
115 @PathVariable("uuid_list") UuidList descriptionUuidList,
116 @RequestParam(value = "omitLevels", required = false) Set<NamedAreaLevel> levels,
117 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
118 HttpServletRequest request, HttpServletResponse response) {
119 logger.info("getOrderedDistributions(" + ObjectUtils.toString(levels) + ") - " + request.getRequestURI());
120 Set<TaxonDescription> taxonDescriptions = new HashSet<TaxonDescription>();
121 TaxonDescription description;
122 for (UUID descriptionUuid : descriptionUuidList) {
123 description = (TaxonDescription) service.load(descriptionUuid);
124 taxonDescriptions.add(description);
126 NamedAreaTree areaTree = service.getOrderedDistributions(taxonDescriptions, levels);
131 @RequestMapping(value
= "naturalLanguageDescription/{featuretree_uuid}", method
= RequestMethod
.GET
) // mapped as absolute path, see CdmAntPathMatcher
132 public ModelAndView
doGenerateNaturalLanguageDescription(
133 @PathVariable("uuid") UUID uuid
,
134 @PathVariable("featuretree_uuid") UUID featureTreeUuid
,
135 HttpServletRequest request
,
136 HttpServletResponse response
) throws IOException
{
137 logger
.info("doGenerateNaturalLanguageDescription() - " + request
.getRequestURI());
139 DescriptionBase
<?
> description
= service
.load(uuid
);
141 ModelAndView mv
= new ModelAndView();
143 List
<Language
> languages
= LocaleContext
.getLanguages();
145 if(!(description
instanceof TaxonDescription
)){
146 HttpStatusMessage
.UUID_REFERENCES_WRONG_TYPE
.send(response
);
147 // will terminate thread
150 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, null);
151 if(featureTree
== null){
152 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
153 // will terminate thread
156 String naturalLanguageDescription
= service
.generateNaturalLanguageDescription(
158 (TaxonDescription
)description
,
161 TextData textData
= TextData
.NewInstance(Feature
.DESCRIPTION());
162 textData
.putText(Language
.DEFAULT(), naturalLanguageDescription
);
163 mv
.addObject(textData
);