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/{uuid}", "/portal/description/{uuid_list}", "/portal/descriptionElement/{descriptionelement_uuid}", "/portal/featureTree/{featuretree_uuid}"})
62 public class DescriptionPortalController
extends BaseController
<DescriptionBase
, IDescriptionService
>
65 private IFeatureTreeService featureTreeService
;
67 private static final List
<String
> FEATURETREE_INIT_STRATEGY
= Arrays
.asList(
70 "root.feature.representations",
71 "root.children.feature.representations",
74 private static final List
<String
> DESCRIPTIONS_DISTRIBUTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
75 "elements.sources.citation.$",
79 protected static final List
<String
> DESCRIPTION_INIT_STRATEGY
= Arrays
.asList(new String
[]{
82 "elements.sources.citation.authorTeam.$",
83 "elements.sources.nameUsedInSource.originalNameString",
84 "elements.area.level",
85 "elements.modifyingText",
91 public DescriptionPortalController() {
93 setInitializationStrategy(DESCRIPTION_INIT_STRATEGY
);
98 public void initBinder(WebDataBinder binder
) {
99 super.initBinder(binder
);
100 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
101 binder
.registerCustomEditor(NamedAreaLevel
.class, new NamedAreaLevelPropertyEditor());
105 * @see eu.etaxonomy.cdm.remote.controller.GenericController#setService(eu.etaxonomy.cdm.api.service.IService)
109 public void setService(IDescriptionService service
) {
110 this.service
= service
;
114 * TODO write controller method documentation
119 * @throws IOException
122 @RequestMapping(value
= {"/portal/featureTree/{featuretree_uuid}"}, method
= RequestMethod
.GET
)
123 public FeatureTree
doGetFeatureTree(
124 @PathVariable("featuretree_uuid") UUID featureUuid
,
125 HttpServletRequest request
,
126 HttpServletResponse response
)throws IOException
{
127 //UUID featureTreeUuid = readValueUuid(request, null);
128 FeatureTree featureTree
= featureTreeService
.load(featureUuid
, FEATURETREE_INIT_STRATEGY
);
129 if(featureTree
== null){
130 HttpStatusMessage
.UUID_NOT_FOUND
.send(response
);
135 @RequestMapping(value
= "/portal/descriptionElement/{descriptionelement_uuid}/annotation", method
= RequestMethod
.GET
)
136 public Pager
<Annotation
> getAnnotations(
137 @PathVariable("descriptionelement_uuid") UUID uuid
,
138 HttpServletRequest request
,
139 HttpServletResponse response
) throws IOException
{
140 logger
.info("getAnnotations() - " + request
.getServletPath());
141 DescriptionElementBase annotatableEntity
= service
.getDescriptionElementByUuid(uuid
);
142 Pager
<Annotation
> annotations
= service
.getDescriptionElementAnnotations(annotatableEntity
, null, null, 0, null, DEFAULT_INIT_STRATEGY
);
146 @RequestMapping(value
= "/portal/description/{uuid_list}/DistributionTree", method
= RequestMethod
.GET
)
147 public DistributionTree
doGetOrderedDistributionsB(
148 @PathVariable("uuid_list") UuidList descriptionUuidList
,
149 @RequestParam(value
= "omitLevels", required
= false) Set
<NamedAreaLevel
> levels
,
150 HttpServletRequest request
, HttpServletResponse response
) {
151 logger
.info("getOrderedDistributionsB(" + ObjectUtils
.toString(levels
) + ") - " + request
.getServletPath());
152 Set
<TaxonDescription
> taxonDescriptions
= new HashSet
<TaxonDescription
>();
153 TaxonDescription description
;
154 for (UUID descriptionUuid
: descriptionUuidList
) {
155 description
= (TaxonDescription
) service
.load(descriptionUuid
, DESCRIPTION_INIT_STRATEGY
);
156 taxonDescriptions
.add(description
);
158 DistributionTree distTree
= service
.getOrderedDistributions(taxonDescriptions
, levels
, DESCRIPTION_INIT_STRATEGY
);