3 * Copyright (C) 2009 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.
10 package eu
.etaxonomy
.cdm
.remote
.controller
.ext
;
12 import java
.awt
.Color
;
13 import java
.io
.IOException
;
14 import java
.util
.ArrayList
;
15 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
.log4j
.Logger
;
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
.PathVariable
;
29 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
30 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
31 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
32 import org
.springframework
.web
.servlet
.ModelAndView
;
34 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
35 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
36 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
39 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
40 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
41 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
42 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
43 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
44 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
45 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
46 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
47 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
48 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
50 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
51 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
52 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
53 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
54 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
55 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
56 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
59 * The ExternalGeoController class is a Spring MVC Controller.
61 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
62 * The available {datasource-name}s are defined in a configuration file which
63 * is loaded by the {@link UpdatableRoutingDataSource}. If the
64 * UpdatableRoutingDataSource is not being used in the actual application
65 * context any arbitrary {datasource-name} may be used.
67 * @author a.kohlbecker
72 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
73 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
75 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
78 private IEditGeoService geoservice
;
81 private IDescriptionService descriptionService
;
84 private IOccurrenceService occurrenceService
;
87 private ITermService termService
;
91 public void initBinder(WebDataBinder binder
) {
92 super.initBinder(binder
);
93 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
100 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
101 * .cdm.api.service.IService)
105 public void setService(ITaxonService service
) {
106 this.service
= service
;
110 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
111 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
112 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
115 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
119 * @return URI parameter Strings for the EDIT Map Service
120 * @throws IOException TODO write controller method documentation
122 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
123 public ModelAndView
doGetDistributionMapUriParams(
124 @PathVariable("uuid") UUID uuid
,
125 HttpServletRequest request
,
126 HttpServletResponse response
)
133 String backLayer
= null;
135 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
136 ModelAndView mv
= new ModelAndView();
138 // get the descriptions for the taxon
139 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
141 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
143 List
<Language
> langs
= LocaleContext
.getLanguages();
145 Set
<DefinedTerm
> scopes
= null;
146 Set
<NamedArea
> geographicalScope
= null;
147 Integer pageSize
= null;
148 Integer pageNumber
= null;
149 List
<String
> propertyPaths
= null;
150 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
152 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
153 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
, presenceAbsenceTermColors
, width
, height
, bbox
,
155 mv
.addObject(uriParams
);
161 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
162 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
163 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
166 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
170 * @return URI parameter Strings for the EDIT Map Service
171 * @throws IOException TODO write controller method documentation
173 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
174 public ModelAndView
doGetOccurrenceMapUriParams(
175 @PathVariable("uuid") UUID uuid
,
176 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
177 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
178 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
179 HttpServletRequest request
,
180 HttpServletResponse response
)
183 Integer width
= null;
184 Integer height
= null;
186 String backLayer
= null;
187 Boolean doReturnImage
= null;
188 Map
<Class
<?
extends SpecimenOrObservationBase
>, Color
> specimenOrObservationTypeColors
= null;
190 logger
.info("doGetOccurrenceMapUriParams() " + request
.getRequestURI() + "?" + request
.getQueryString());
191 ModelAndView mv
= new ModelAndView();
193 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
195 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
197 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
198 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
200 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
202 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
203 mv
.addObject(uriParams
);