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
.FileReader
;
14 import java
.io
.IOException
;
15 import java
.util
.ArrayList
;
16 import java
.util
.Collection
;
17 import java
.util
.HashMap
;
18 import java
.util
.List
;
21 import java
.util
.UUID
;
23 import javax
.servlet
.http
.HttpServletRequest
;
24 import javax
.servlet
.http
.HttpServletResponse
;
26 import org
.apache
.log4j
.Logger
;
27 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
28 import org
.springframework
.stereotype
.Controller
;
29 import org
.springframework
.web
.bind
.WebDataBinder
;
30 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
31 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
32 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
33 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
34 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
35 import org
.springframework
.web
.servlet
.ModelAndView
;
37 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
42 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
43 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
44 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
45 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
46 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
47 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
49 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
50 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
52 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
53 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
54 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
55 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
56 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
57 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
58 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
59 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
60 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
61 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
62 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
63 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
66 * The ExternalGeoController class is a Spring MVC Controller.
68 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
69 * The available {datasource-name}s are defined in a configuration file which
70 * is loaded by the {@link UpdatableRoutingDataSource}. If the
71 * UpdatableRoutingDataSource is not being used in the actual application
72 * context any arbitrary {datasource-name} may be used.
74 * @author a.kohlbecker
79 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
80 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
82 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
85 private IEditGeoService geoservice
;
88 private IDescriptionService descriptionService
;
91 private IOccurrenceService occurrenceService
;
94 private ITermService termService
;
98 public void initBinder(WebDataBinder binder
) {
99 super.initBinder(binder
);
100 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
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>
118 * @param subAreaPreference
119 * enables the <b>Sub area preference rule</b> if set to true,
120 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
121 * @param statusOrderPreference
122 * enables the <b>Status order preference rule</b> if set to true,
123 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
124 * @param hideMarkedAreas
125 * distributions where the area has a {@link Marker} with one of
126 * the specified {@link MarkerType}s will be skipped, see
127 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
130 * @return URI parameter Strings for the EDIT Map Service
131 * @throws IOException
133 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
134 public ModelAndView
doGetDistributionMapUriParams(
135 @PathVariable("uuid") UUID uuid
,
136 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
137 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
138 @RequestParam(value
= "hideMarkedAreas", required
= false) Set
<MarkerType
> hideMarkedAreas
,
139 HttpServletRequest request
,
140 HttpServletResponse response
)
147 String backLayer
= null;
149 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
150 ModelAndView mv
= new ModelAndView();
152 // get the descriptions for the taxon
153 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
155 Map
<PresenceAbsenceTermBase
<?
>, Color
> presenceAbsenceTermColors
= null;
157 List
<Language
> langs
= LocaleContext
.getLanguages();
159 Set
<DefinedTerm
> scopes
= null;
160 Set
<NamedArea
> geographicalScope
= null;
161 Integer pageSize
= null;
162 Integer pageNumber
= null;
163 List
<String
> propertyPaths
= null;
164 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
166 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
167 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
168 subAreaPreference
, statusOrderPreference
,
169 hideMarkedAreas
, presenceAbsenceTermColors
, width
, height
, bbox
, backLayer
, langs
);
170 mv
.addObject(uriParams
);
177 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
178 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
179 * an valid URI parameter String. Higher level distribiution areas are expanded in order to include all
182 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
186 * @return URI parameter Strings for the EDIT Map Service
187 * @throws IOException TODO write controller method documentation
189 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
190 public ModelAndView
doGetOccurrenceMapUriParams(
191 @PathVariable("uuid") UUID uuid
,
192 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
193 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
194 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
195 HttpServletRequest request
,
196 HttpServletResponse response
)
199 Integer width
= null;
200 Integer height
= null;
202 String backLayer
= null;
203 Boolean doReturnImage
= null;
204 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
206 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
207 ModelAndView mv
= new ModelAndView();
209 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(relationshipUuids
, relationshipInversUuids
, termService
);
211 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
213 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
214 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
216 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
218 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
, specimenOrObservationTypeColors
, doReturnImage
, width
, height
, bbox
, backLayer
);
219 mv
.addObject(uriParams
);
231 * @throws IOException
233 * @author a.kohlbecker
235 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
236 public ModelAndView
doMapShapeFileToNamedAreas(
237 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
238 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
239 @RequestParam(required
=true, value
="localFile") String localFile
,
240 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
241 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
242 HttpServletRequest request
,
243 HttpServletResponse response
)
246 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
247 ModelAndView mv
= new ModelAndView();
249 FileReader reader
= new FileReader(localFile
);
251 Set
<UUID
> areaUuidSet
= null;
252 if(namedAreaUuids
!= null) {
253 areaUuidSet
= namedAreaUuids
.asSet();
255 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
256 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
257 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
258 for(NamedArea area
: resultMap
.keySet()){
259 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
261 mv
.addObject(flatResultMap
);