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
.HashSet
;
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
.apache
.commons
.lang
.ObjectUtils
;
24 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
25 import org
.springframework
.stereotype
.Controller
;
26 import org
.springframework
.web
.bind
.WebDataBinder
;
27 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
28 import org
.springframework
.web
.bind
.annotation
.ModelAttribute
;
29 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
30 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
31 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
32 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
34 import eu
.etaxonomy
.cdm
.api
.service
.AnnotatableServiceBase
;
35 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionServiceImpl
;
36 import eu
.etaxonomy
.cdm
.api
.service
.DistributionTree
;
37 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.NamedAreaTree
;
40 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
41 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
43 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
44 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
45 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
46 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
47 import eu
.etaxonomy
.cdm
.remote
.editor
.NamedAreaLevelPropertyEditor
;
49 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
50 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDPropertyEditor
;
51 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
54 * TODO write controller documentation
56 * @author a.kohlbecker
61 @RequestMapping(value
= {"/portal/description/*","/portal/description/{uuid}", "/portal/description/{uuid_list}", "/portal/descriptionelement/*", "/portal/featuretree/*"})
62 public class DescriptionPortalController
extends AnnotatableController
<DescriptionBase
, IDescriptionService
>
65 private IFeatureTreeService featureTreeService
;
67 public DescriptionPortalController(){
69 setUuidParameterPattern("^/(?:[^/]+)/([^/?#&\\.]+).*");
72 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
75 "root.feature.representations",
76 "root.children.feature.representations",
78 private static final List
<String
> DESCRIPTIONS_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
82 "elements.sources.citation",
83 "elements.sources.citation.$",
86 //"elements.area.level",
88 protected static final List
<String
> TAXONDESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
91 "elements.sources.citation.",
92 // "elements.sources.citation.authorTeam.$",
93 // "elements.sources.citation.authorTeam.titleCache",
94 // "elements.sources.citation.authorTeam.nomenclaturalTitleCache",
95 "elements.sources.nameUsedInSource.titleCache",
96 "elements.sources.nameUsedInSource.originalNameString",
98 "elements.area.level",
99 "elements.modifyingText",
103 public void initBinder(WebDataBinder binder
) {
104 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
105 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
106 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
110 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
114 public void setService(IDescriptionService service
) {
115 this.service
= service
;
119 * TODO write controller method documentation
124 * @throws IOException
127 @RequestMapping(value
= {"/portal/featuretree/{featuretree_uuid}"}, method
= RequestMethod
.GET
)
128 public FeatureTree
doGetFeatureTree(
129 @PathVariable("featuretree_uuid") UUID featureUuid
,
130 HttpServletRequest request
,
131 HttpServletResponse response
)throws IOException
{
132 //UUID featureTreeUuid = readValueUuid(request, null);
133 FeatureTree featureTree
= featureTreeService
.load(featureUuid
, FEATURETREE_INIT_STRATEGY
);
134 if(featureTree
== null){
135 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
140 @RequestMapping(value
= "/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
141 public Pager
<Annotation
> getAnnotations(
142 @PathVariable("descriptionelement_uuid") UUID uuid
,
143 HttpServletRequest request
,
144 HttpServletResponse response
) throws IOException
{
145 logger
.info("getAnnotations() - " + request
.getServletPath());
146 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
147 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, ANNOTATION_INIT_STRATEGY
);
151 @RequestMapping(value
= "{uuid_list}/namedAreaTree", method
= RequestMethod
.GET
)
152 public NamedAreaTree
doGetOrderedDistributions(
153 @PathVariable("uuid_list") UuidList descriptionUuidList
,
154 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> levels
,
155 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
156 HttpServletRequest request
, HttpServletResponse response
) {
157 logger
.info("getOrderedDistributions(" + ObjectUtils
.toString(levels
) + ") - " + request
.getServletPath());
158 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
159 TaxonDescription description
;
160 for (UUID descriptionUuid
: descriptionUuidList
) {
161 description
= (TaxonDescription
) service
.load(descriptionUuid
);
162 taxonDescriptions
.add(description
);
164 NamedAreaTree areaTree
= service
.getOrderedDistributions(taxonDescriptions
, levels
);
168 @RequestMapping(value
= "{uuid_list}/DistributionTree", method
= RequestMethod
.GET
)
169 public DistributionTree
doGetOrderedDistributionsB(
170 @PathVariable("uuid_list") UuidList descriptionUuidList
,
171 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> levels
,
172 HttpServletRequest request
, HttpServletResponse response
) {
173 logger
.info("getOrderedDistributionsB(" + ObjectUtils
.toString(levels
) + ") - " + request
.getServletPath());
174 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
175 TaxonDescription description
;
176 for (UUID descriptionUuid
: descriptionUuidList
) {
177 description
= (TaxonDescription
) service
.load(descriptionUuid
, TAXONDESCRIPTION_INIT_STRATEGY
);
178 taxonDescriptions
.add(description
);
180 DistributionTree distTree
= service
.getOrderedDistributionsB(taxonDescriptions
, levels
);