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
.IDescriptionService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.NamedAreaTree
;
39 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
40 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
43 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
44 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
45 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
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
= {"/description/*","/description/{uuid}", "/description/{uuid_list}", "/descriptionelement/*", "/featuretree/*"})
62 public class DescriptionController
extends AnnotatableController
<DescriptionBase
, IDescriptionService
>
65 private IFeatureTreeService featureTreeService
;
67 public DescriptionController(){
69 setUuidParameterPattern("^/(?:[^/]+)/([^/?#&\\.]+).*");
72 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
75 "root.feature.representations",
76 "root.children.feature.representations",
80 public void initBinder(WebDataBinder binder
) {
81 binder
.registerCustomEditor(UUID
.class, new UUIDPropertyEditor());
82 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
83 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
87 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
91 public void setService(IDescriptionService service
) {
92 this.service
= service
;
96 * TODO write controller method documentation
101 * @throws IOException
103 @RequestMapping(value
= {"/featuretree/{featuretree_uuid}"}, method
= RequestMethod
.GET
)
104 public FeatureTree
doGetFeatureTree(
105 @PathVariable("featuretree_uuid") UUID uuid
,
106 HttpServletRequest request
,
107 HttpServletResponse response
)throws IOException
{
108 UUID featureTreeUuid
= readValueUuid(request
, null);
109 FeatureTree featureTree
= featureTreeService
.load(featureTreeUuid
, FEATURETREE_INIT_STRATEGY
);
110 if(featureTree
== null){
111 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
116 @RequestMapping(value
= "/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
117 public Pager
<Annotation
> getAnnotations(
118 @PathVariable("descriptionelement_uuid") UUID uuid
,
119 HttpServletRequest request
,
120 HttpServletResponse response
) throws IOException
{
121 logger
.info("getAnnotations() - " + request
.getServletPath());
122 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
123 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, ANNOTATION_INIT_STRATEGY
);
127 @RequestMapping(value
= "{uuid_list}/namedAreaTree", method
= RequestMethod
.GET
)
128 public NamedAreaTree
doGetOrderedDistributions(
129 @PathVariable("uuid_list") UuidList descriptionUuidList
,
130 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> levels
,
131 //@ModelAttribute("omitLevels") HashSet<NamedAreaLevel> levels,
132 HttpServletRequest request
, HttpServletResponse response
) {
133 logger
.info("getOrderedDistributions(" + ObjectUtils
.toString(levels
) + ") - " + request
.getServletPath());
134 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
135 TaxonDescription description
;
136 for (UUID descriptionUuid
: descriptionUuidList
) {
137 description
= (TaxonDescription
) service
.load(descriptionUuid
);
138 taxonDescriptions
.add(description
);
140 NamedAreaTree areaTree
= service
.getOrderedDistributions(taxonDescriptions
, levels
);