2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.remote
.controller
.ext
;
11 import java
.awt
.Color
;
12 import java
.io
.FileReader
;
13 import java
.io
.IOException
;
14 import java
.util
.ArrayList
;
15 import java
.util
.Collection
;
16 import java
.util
.HashMap
;
17 import java
.util
.List
;
20 import java
.util
.UUID
;
22 import javax
.servlet
.http
.HttpServletRequest
;
23 import javax
.servlet
.http
.HttpServletResponse
;
25 import org
.apache
.logging
.log4j
.LogManager
;
26 import org
.apache
.logging
.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
.l10n
.LocaleContext
;
42 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
43 import eu
.etaxonomy
.cdm
.api
.util
.DescriptionUtility
;
44 import eu
.etaxonomy
.cdm
.api
.util
.TaxonRelationshipEdge
;
45 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
46 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
47 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
48 import eu
.etaxonomy
.cdm
.ext
.geo
.OccurrenceServiceRequestParameterDto
;
49 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
50 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
51 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
52 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
54 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
55 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
57 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
58 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
59 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
60 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
61 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
62 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
63 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
64 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
65 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
66 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
67 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
68 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
69 import io
.swagger
.annotations
.Api
;
72 * The ExternalGeoController class is a Spring MVC Controller.
74 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
75 * The available {datasource-name}s are defined in a configuration file which
76 * is loaded by the {@link UpdatableRoutingDataSource}. If the
77 * UpdatableRoutingDataSource is not being used in the actual application
78 * context any arbitrary {datasource-name} may be used.
80 * @author a.kohlbecker
86 @Api(value
="mapServiceParameters")
87 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
88 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
90 private static final Logger logger
= LogManager
.getLogger();
93 private IEditGeoService geoservice
;
96 private IDescriptionService descriptionService
;
99 private IOccurrenceService occurrenceService
;
102 private ITermService termService
;
106 public void initBinder(WebDataBinder binder
) {
107 super.initBinder(binder
);
108 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
109 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
114 public void setService(ITaxonService service
) {
115 this.service
= service
;
119 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
120 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
121 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
124 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
127 * @param subAreaPreference
128 * enables the <b>Sub area preference rule</b> if set to true,
129 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
130 * @param statusOrderPreference
131 * enables the <b>Status order preference rule</b> if set to true,
132 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
133 * @param hideMarkedAreas
134 * comma separated list of {@link MarkerType} uuids,
135 * distributions where the area has a {@link Marker} with one of
136 * the specified {@link MarkerType}s will be skipped, see
137 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
140 * @return URI parameter Strings for the EDIT Map Service
141 * @throws IOException
143 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
144 public ModelAndView
doGetDistributionMapUriParams(
145 @PathVariable("uuid") UUID uuid
,
146 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
147 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
148 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
149 HttpServletRequest request
,
150 HttpServletResponse response
)
153 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
154 ModelAndView mv
= new ModelAndView();
156 // get the descriptions for the taxon
157 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
159 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= null;
161 List
<Language
> langs
= LocaleContext
.getLanguages();
163 Set
<MarkerType
> hideMarkedAreas
= null;
164 if(hideMarkedAreasList
!= null){
165 hideMarkedAreas
= hideMarkedAreasList
.asSet();
168 Set
<DefinedTerm
> scopes
= null;
169 Set
<NamedArea
> geographicalScope
= null;
170 Integer pageSize
= null;
171 Integer pageNumber
= null;
172 List
<String
> propertyPaths
= null;
173 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
175 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
176 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
177 subAreaPreference
, statusOrderPreference
,
178 hideMarkedAreas
, presenceAbsenceTermColors
, langs
);
179 mv
.addObject(uriParams
);
186 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
187 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
188 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
191 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
195 * @return URI parameter Strings for the EDIT Map Service
196 * @throws IOException TODO write controller method documentation
198 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
199 public OccurrenceServiceRequestParameterDto
doGetOccurrenceMapUriParams(
200 @PathVariable("uuid") UUID uuid
,
201 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
202 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
203 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
204 HttpServletRequest request
,
205 HttpServletResponse response
)
209 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
211 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
213 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurencesForTaxon(uuid
, relationshipUuids
,
214 relationshipInversUuids
, maxDepth
, response
);
216 OccurrenceServiceRequestParameterDto dto
= geoservice
.getOccurrenceServiceRequestParameters(specimensOrObersvations
,
217 specimenOrObservationTypeColors
);
222 private List
<SpecimenOrObservationBase
> occurencesForTaxon(UUID taxonUuid
, UuidList relationshipUuids
,
223 UuidList relationshipInversUuids
, Integer maxDepth
, HttpServletResponse response
) throws IOException
{
224 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
225 relationshipUuids
, relationshipInversUuids
, termService
);
227 Taxon taxon
= getCdmBaseInstance(Taxon
.class, taxonUuid
, response
, (List
<String
>)null);
229 List
<OrderHint
> orderHints
= new ArrayList
<>();
230 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
232 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
233 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
234 return specimensOrObersvations
;
238 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
239 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
240 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
243 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
247 * @return URI parameter Strings for the EDIT Map Service
248 * @throws IOException TODO write controller method documentation
250 @RequestMapping(value
= { "taxonOccurrencesForX" }, method
= RequestMethod
.GET
)
251 public ModelAndView
doGetOccurrenceXMapUriParams(
252 @RequestParam(value
= "fieldUnitUuidList", required
= false) UuidList fieldUnitUuids
,
253 HttpServletRequest request
,
254 HttpServletResponse response
)
257 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
259 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
260 ModelAndView mv
= new ModelAndView();
262 List
<Point
> fieldUnitPoints
= occurrenceService
.findPointsForFieldUnitList(fieldUnitUuids
);
264 OccurrenceServiceRequestParameterDto dto
= EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
265 null, specimenOrObservationTypeColors
);
278 * @throws IOException
280 * @author a.kohlbecker
282 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
283 public ModelAndView
doMapShapeFileToNamedAreas(
284 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
285 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
286 @RequestParam(required
=true, value
="localFile") String localFile
,
287 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
288 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
289 HttpServletRequest request
,
290 HttpServletResponse response
)
293 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
294 ModelAndView mv
= new ModelAndView();
296 FileReader reader
= new FileReader(localFile
);
298 Set
<UUID
> areaUuidSet
= null;
299 if(namedAreaUuids
!= null) {
300 areaUuidSet
= namedAreaUuids
.asSet();
302 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
303 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
304 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
305 for(NamedArea area
: resultMap
.keySet()){
306 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
308 mv
.addObject(flatResultMap
);