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
.Language
;
43 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
44 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
45 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
46 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
47 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
48 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
49 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
50 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
51 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
52 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
53 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
54 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
57 * The ExternalGeoController class is a Spring MVC Controller.
59 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
60 * The available {datasource-name}s are defined in a configuration file which
61 * is loaded by the {@link UpdatableRoutingDataSource}. If the
62 * UpdatableRoutingDataSource is not being used in the actual application
63 * context any arbitrary {datasource-name} may be used.
65 * @author a.kohlbecker
70 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
71 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
73 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
76 private IEditGeoService geoservice
;
79 private IDescriptionService descriptionService
;
82 private IOccurrenceService occurrenceService
;
85 private ITermService termService
;
89 public void initBinder(WebDataBinder binder
) {
90 super.initBinder(binder
);
91 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
98 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
99 * .cdm.api.service.IService)
103 public void setService(ITaxonService service
) {
104 this.service
= service
;
108 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
109 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
110 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
113 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
117 * @return URI parameter Strings for the EDIT Map Service
118 * @throws IOException TODO write controller method documentation
120 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
121 public ModelAndView
doGetDistributionMapUriParams(
122 @PathVariable("uuid") UUID uuid
,
123 HttpServletRequest request
,
124 HttpServletResponse response
)
131 String backLayer
= null;
133 logger
.info("doGetDistributionMapUriParams() " + request
.getServletPath());
134 ModelAndView mv
= new ModelAndView();
136 // get the descriptions for the taxon
137 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
139 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
141 List
<Language
> langs
= LocaleContext
.getLanguages();
143 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, null, null, null, null, null);
144 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
145 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
, presenceAbsenceTermColors
, width
, height
, bbox
,
147 mv
.addObject(uriParams
);
153 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
154 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
155 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
158 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
162 * @return URI parameter Strings for the EDIT Map Service
163 * @throws IOException TODO write controller method documentation
165 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
166 public ModelAndView
doGetOccurrenceMapUriParams(
167 @PathVariable("uuid") UUID uuid
,
168 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
169 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
170 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
171 HttpServletRequest request
,
172 HttpServletResponse response
)
175 Integer width
= null;
176 Integer height
= null;
178 String backLayer
= null;
179 Boolean doReturnImage
= null;
180 Map
<Class
<?
extends SpecimenOrObservationBase
>, Color
> specimenOrObservationTypeColors
= null;
182 logger
.info("doGetOccurrenceMapUriParams() " + request
.getServletPath() + "?" + request
.getQueryString());
183 ModelAndView mv
= new ModelAndView();
185 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
187 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
189 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
190 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
192 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
194 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
195 mv
.addObject(uriParams
);