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
.PresenceAbsenceTerm
;
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
.DefinedTermBaseList
;
62 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
63 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
64 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
65 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
68 * The ExternalGeoController class is a Spring MVC Controller.
70 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
71 * The available {datasource-name}s are defined in a configuration file which
72 * is loaded by the {@link UpdatableRoutingDataSource}. If the
73 * UpdatableRoutingDataSource is not being used in the actual application
74 * context any arbitrary {datasource-name} may be used.
76 * @author a.kohlbecker
81 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
82 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
84 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
87 private IEditGeoService geoservice
;
90 private IDescriptionService descriptionService
;
93 private IOccurrenceService occurrenceService
;
96 private ITermService termService
;
100 public void initBinder(WebDataBinder binder
) {
101 super.initBinder(binder
);
102 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
103 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
108 public void setService(ITaxonService service
) {
109 this.service
= service
;
113 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
114 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
115 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
118 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
121 * @param subAreaPreference
122 * enables the <b>Sub area preference rule</b> if set to true,
123 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
124 * @param statusOrderPreference
125 * enables the <b>Status order preference rule</b> if set to true,
126 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
127 * @param hideMarkedAreas
128 * comma separated list of {@link MarkerType} uuids,
129 * distributions where the area has a {@link Marker} with one of
130 * the specified {@link MarkerType}s will be skipped, see
131 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
134 * @return URI parameter Strings for the EDIT Map Service
135 * @throws IOException
137 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
138 public ModelAndView
doGetDistributionMapUriParams(
139 @PathVariable("uuid") UUID uuid
,
140 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
141 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
142 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
143 HttpServletRequest request
,
144 HttpServletResponse response
)
147 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
148 ModelAndView mv
= new ModelAndView();
150 // get the descriptions for the taxon
151 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
153 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= null;
155 List
<Language
> langs
= LocaleContext
.getLanguages();
157 Set
<MarkerType
> hideMarkedAreas
= null;
158 if(hideMarkedAreasList
!= null){
159 hideMarkedAreas
= hideMarkedAreasList
.asSet();
162 Set
<DefinedTerm
> scopes
= null;
163 Set
<NamedArea
> geographicalScope
= null;
164 Integer pageSize
= null;
165 Integer pageNumber
= null;
166 List
<String
> propertyPaths
= null;
167 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
169 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
170 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
171 subAreaPreference
, statusOrderPreference
,
172 hideMarkedAreas
, presenceAbsenceTermColors
, langs
);
173 mv
.addObject(uriParams
);
180 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
181 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
182 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
185 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
189 * @return URI parameter Strings for the EDIT Map Service
190 * @throws IOException TODO write controller method documentation
192 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
193 public ModelAndView
doGetOccurrenceMapUriParams(
194 @PathVariable("uuid") UUID uuid
,
195 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
196 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
197 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
198 HttpServletRequest request
,
199 HttpServletResponse response
)
202 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
204 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
205 ModelAndView mv
= new ModelAndView();
207 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
208 relationshipUuids
, relationshipInversUuids
, termService
);
210 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
212 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
213 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
215 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
216 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
218 String uriParams
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
,
219 specimenOrObservationTypeColors
);
220 mv
.addObject(uriParams
);
232 * @throws IOException
234 * @author a.kohlbecker
236 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
237 public ModelAndView
doMapShapeFileToNamedAreas(
238 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
239 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
240 @RequestParam(required
=true, value
="localFile") String localFile
,
241 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
242 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
243 HttpServletRequest request
,
244 HttpServletResponse response
)
247 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
248 ModelAndView mv
= new ModelAndView();
250 FileReader reader
= new FileReader(localFile
);
252 Set
<UUID
> areaUuidSet
= null;
253 if(namedAreaUuids
!= null) {
254 areaUuidSet
= namedAreaUuids
.asSet();
256 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
257 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
258 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
259 for(NamedArea area
: resultMap
.keySet()){
260 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
262 mv
.addObject(flatResultMap
);