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
;
17 import java
.util
.UUID
;
19 import javax
.servlet
.http
.HttpServletRequest
;
20 import javax
.servlet
.http
.HttpServletResponse
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
24 import org
.springframework
.stereotype
.Controller
;
25 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
26 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
27 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
28 import org
.springframework
.web
.servlet
.ModelAndView
;
30 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
31 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
32 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
33 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
34 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
35 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
36 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
37 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
39 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
42 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
43 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
44 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
45 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
48 * The ExternalGeoController class is a Spring MVC Controller.
50 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
51 * The available {datasource-name}s are defined in a configuration file which
52 * is loaded by the {@link UpdatableRoutingDataSource}. If the
53 * UpdatableRoutingDataSource is not being used in the actual application
54 * context any arbitrary {datasource-name} may be used.
56 * @author a.kohlbecker
61 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
62 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
64 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
67 private IEditGeoService geoservice
;
70 private IDescriptionService descriptionService
;
73 private IOccurrenceService occurrenceService
;
79 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
80 * .cdm.api.service.IService)
84 public void setService(ITaxonService service
) {
85 this.service
= service
;
89 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
90 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
91 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
94 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
98 * @return URI parameter Strings for the EDIT Map Service
99 * @throws IOException TODO write controller method documentation
101 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
102 public ModelAndView
doGetDistributionMapUriParams(
103 @PathVariable("uuid") UUID uuid
,
104 HttpServletRequest request
,
105 HttpServletResponse response
)
112 String backLayer
= null;
114 logger
.info("doGetDistributionMapUriParams() " + request
.getServletPath());
115 ModelAndView mv
= new ModelAndView();
117 // get the descriptions for the taxon
118 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
120 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
122 List
<Language
> langs
= LocaleContext
.getLanguages();
124 Pager
<TaxonDescription
> page
= descriptionService
.getTaxonDescriptions(taxon
, null, null, null, null, null);
125 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
126 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
, presenceAbsenceTermColors
, width
, height
, bbox
,
128 mv
.addObject(uriParams
);
134 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
135 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
136 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
139 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
143 * @return URI parameter Strings for the EDIT Map Service
144 * @throws IOException TODO write controller method documentation
146 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
147 public ModelAndView
doGetOccurrenceMapUriParams(
148 @PathVariable("uuid") UUID uuid
,
149 HttpServletRequest request
,
150 HttpServletResponse response
)
153 Integer width
= null;
154 Integer height
= null;
156 String backLayer
= null;
157 Boolean doReturnImage
= null;
158 Map
<Class
<?
extends SpecimenOrObservationBase
>, Color
> specimenOrObservationTypeColors
= null;
160 logger
.info("doGetOccurrenceMapUriParams() " + request
.getServletPath());
161 ModelAndView mv
= new ModelAndView();
163 // get the descriptions for the taxon
164 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
166 TaxonBase tb
= service
.load(uuid
);
168 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
169 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
172 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, null, (Taxon
)tb
, null, null, null, orderHints
, null);
174 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
175 mv
.addObject(uriParams
);