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
.List
;
16 import java
.util
.UUID
;
18 import javax
.servlet
.http
.HttpServletRequest
;
19 import javax
.servlet
.http
.HttpServletResponse
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
23 import org
.springframework
.stereotype
.Controller
;
24 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
25 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
27 import org
.springframework
.web
.servlet
.ModelAndView
;
29 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
30 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
32 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
33 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
34 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
35 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
36 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
39 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
40 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
41 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
44 * The ExternalGeoController class is a Spring MVC Controller.
46 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
47 * The available {datasource-name}s are defined in a configuration file which
48 * is loaded by the {@link UpdatableRoutingDataSource}. If the
49 * UpdatableRoutingDataSource is not being used in the actual application
50 * context any arbitrary {datasource-name} may be used.
52 * @author a.kohlbecker
57 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
58 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
60 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
63 private IEditGeoService geoservice
;
65 private IDescriptionService descriptionService
;
71 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
72 * .cdm.api.service.IService)
76 public void setService(ITaxonService service
) {
77 this.service
= service
;
81 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
82 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
83 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
86 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
90 * @return URI parameter Strings for the EDIT Map Service
91 * @throws IOException TODO write controller method documentation
93 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
94 public ModelAndView
doGetDistributionMapUriParams(
95 @PathVariable("uuid") UUID uuid
,
96 HttpServletRequest request
,
97 HttpServletResponse response
)
104 String backLayer
= null;
106 logger
.info("doGetDistributionMapUriParams() " + request
.getServletPath());
107 ModelAndView mv
= new ModelAndView();
109 // get the descriptions for the taxon
110 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
112 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
114 List
<Language
> langs
= LocaleContext
.getLanguages();
116 Pager
<TaxonDescription
> page
= descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, null);
117 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
118 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
, presenceAbsenceTermColors
, width
, height
, bbox
,
120 mv
.addObject(uriParams
);
126 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
127 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
128 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
131 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
135 * @return URI parameter Strings for the EDIT Map Service
136 * @throws IOException TODO write controller method documentation
138 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
139 public ModelAndView
doGetOccurrenceMapUriParams(
140 @PathVariable("uuid") UUID uuid
,
141 HttpServletRequest request
,
142 HttpServletResponse response
)
145 Integer width
= null;
146 Integer height
= null;
148 String backLayer
= null;
149 Boolean doReturnImage
= null;
150 Map
<Class
<?
extends SpecimenOrObservationBase
>, Color
> specimenOrObservationTypeColors
= null;
152 logger
.info("doGetOccurrenceMapUriParams() " + request
.getServletPath());
153 ModelAndView mv
= new ModelAndView();
155 // get the descriptions for the taxon
156 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
158 Pager
<TaxonDescription
> page
= descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, null);
159 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
161 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(taxonDescriptions
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
162 mv
.addObject(uriParams
);