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
.occurrence
.SpecimenOrObservationType
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
50 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
51 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
52 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
53 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
54 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
55 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
56 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
57 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
60 * The ExternalGeoController class is a Spring MVC Controller.
62 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
63 * The available {datasource-name}s are defined in a configuration file which
64 * is loaded by the {@link UpdatableRoutingDataSource}. If the
65 * UpdatableRoutingDataSource is not being used in the actual application
66 * context any arbitrary {datasource-name} may be used.
68 * @author a.kohlbecker
73 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
74 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
76 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
79 private IEditGeoService geoservice
;
82 private IDescriptionService descriptionService
;
85 private IOccurrenceService occurrenceService
;
88 private ITermService termService
;
92 public void initBinder(WebDataBinder binder
) {
93 super.initBinder(binder
);
94 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
101 * eu.etaxonomy.cdm.remote.controller.BaseController#setService(eu.etaxonomy
102 * .cdm.api.service.IService)
106 public void setService(ITaxonService service
) {
107 this.service
= service
;
111 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
112 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
113 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
116 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
120 * @return URI parameter Strings for the EDIT Map Service
121 * @throws IOException TODO write controller method documentation
123 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
124 public ModelAndView
doGetDistributionMapUriParams(
125 @PathVariable("uuid") UUID uuid
,
126 HttpServletRequest request
,
127 HttpServletResponse response
)
134 String backLayer
= null;
136 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
137 ModelAndView mv
= new ModelAndView();
139 // get the descriptions for the taxon
140 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
142 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
144 List
<Language
> langs
= LocaleContext
.getLanguages();
146 Set
<DefinedTerm
> scopes
= null;
147 Set
<NamedArea
> geographicalScope
= null;
148 Integer pageSize
= null;
149 Integer pageNumber
= null;
150 List
<String
> propertyPaths
= null;
151 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
153 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
154 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
, presenceAbsenceTermColors
, width
, height
, bbox
,
156 mv
.addObject(uriParams
);
162 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
163 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
164 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
167 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
171 * @return URI parameter Strings for the EDIT Map Service
172 * @throws IOException TODO write controller method documentation
174 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
175 public ModelAndView
doGetOccurrenceMapUriParams(
176 @PathVariable("uuid") UUID uuid
,
177 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
178 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
179 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
180 HttpServletRequest request
,
181 HttpServletResponse response
)
184 Integer width
= null;
185 Integer height
= null;
187 String backLayer
= null;
188 Boolean doReturnImage
= null;
189 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
191 logger
.info("doGetOccurrenceMapUriParams() " + request
.getRequestURI() + "?" + request
.getQueryString());
192 ModelAndView mv
= new ModelAndView();
194 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
196 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
198 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
199 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
201 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
203 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
204 mv
.addObject(uriParams
);