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
;import org
.apache
.logging
.log4j
.Logger
;
26 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
27 import org
.springframework
.stereotype
.Controller
;
28 import org
.springframework
.web
.bind
.WebDataBinder
;
29 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
30 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
31 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
32 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
33 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
34 import org
.springframework
.web
.servlet
.ModelAndView
;
36 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
37 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
38 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.l10n
.LocaleContext
;
41 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
42 import eu
.etaxonomy
.cdm
.api
.util
.DescriptionUtility
;
43 import eu
.etaxonomy
.cdm
.api
.util
.TaxonRelationshipEdge
;
44 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
45 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
46 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
47 import eu
.etaxonomy
.cdm
.ext
.geo
.OccurrenceServiceRequestParameterDto
;
48 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
49 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
50 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
51 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
53 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
54 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
55 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
56 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
57 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
58 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
59 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
60 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
61 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
62 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
63 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
64 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
65 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
66 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
67 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
68 import io
.swagger
.annotations
.Api
;
71 * The ExternalGeoController class is a Spring MVC Controller.
73 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
74 * The available {datasource-name}s are defined in a configuration file which
75 * is loaded by the {@link UpdatableRoutingDataSource}. If the
76 * UpdatableRoutingDataSource is not being used in the actual application
77 * context any arbitrary {datasource-name} may be used.
79 * @author a.kohlbecker
85 @Api(value
="mapServiceParameters")
86 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
87 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
89 public static final Logger logger
= LogManager
.getLogger(ExternalGeoController
.class);
92 private IEditGeoService geoservice
;
95 private IDescriptionService descriptionService
;
98 private IOccurrenceService occurrenceService
;
101 private ITermService termService
;
105 public void initBinder(WebDataBinder binder
) {
106 super.initBinder(binder
);
107 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
108 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
113 public void setService(ITaxonService service
) {
114 this.service
= service
;
118 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
119 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
120 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
123 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
126 * @param subAreaPreference
127 * enables the <b>Sub area preference rule</b> if set to true,
128 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
129 * @param statusOrderPreference
130 * enables the <b>Status order preference rule</b> if set to true,
131 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
132 * @param hideMarkedAreas
133 * comma separated list of {@link MarkerType} uuids,
134 * distributions where the area has a {@link Marker} with one of
135 * the specified {@link MarkerType}s will be skipped, see
136 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
139 * @return URI parameter Strings for the EDIT Map Service
140 * @throws IOException
142 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
143 public ModelAndView
doGetDistributionMapUriParams(
144 @PathVariable("uuid") UUID uuid
,
145 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
146 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
147 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
148 HttpServletRequest request
,
149 HttpServletResponse response
)
152 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
153 ModelAndView mv
= new ModelAndView();
155 // get the descriptions for the taxon
156 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
158 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= null;
160 List
<Language
> langs
= LocaleContext
.getLanguages();
162 Set
<MarkerType
> hideMarkedAreas
= null;
163 if(hideMarkedAreasList
!= null){
164 hideMarkedAreas
= hideMarkedAreasList
.asSet();
167 Set
<DefinedTerm
> scopes
= null;
168 Set
<NamedArea
> geographicalScope
= null;
169 Integer pageSize
= null;
170 Integer pageNumber
= null;
171 List
<String
> propertyPaths
= null;
172 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
174 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
175 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
176 subAreaPreference
, statusOrderPreference
,
177 hideMarkedAreas
, presenceAbsenceTermColors
, langs
);
178 mv
.addObject(uriParams
);
185 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
186 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
187 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
190 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
194 * @return URI parameter Strings for the EDIT Map Service
195 * @throws IOException TODO write controller method documentation
197 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
198 public OccurrenceServiceRequestParameterDto
doGetOccurrenceMapUriParams(
199 @PathVariable("uuid") UUID uuid
,
200 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
201 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
202 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
203 HttpServletRequest request
,
204 HttpServletResponse response
)
208 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
210 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
212 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurencesForTaxon(uuid
, relationshipUuids
,
213 relationshipInversUuids
, maxDepth
, response
);
215 OccurrenceServiceRequestParameterDto dto
= geoservice
.getOccurrenceServiceRequestParameters(specimensOrObersvations
,
216 specimenOrObservationTypeColors
);
221 private List
<SpecimenOrObservationBase
> occurencesForTaxon(UUID taxonUuid
, UuidList relationshipUuids
,
222 UuidList relationshipInversUuids
, Integer maxDepth
, HttpServletResponse response
) throws IOException
{
223 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
224 relationshipUuids
, relationshipInversUuids
, termService
);
226 Taxon taxon
= getCdmBaseInstance(Taxon
.class, taxonUuid
, response
, (List
<String
>)null);
228 List
<OrderHint
> orderHints
= new ArrayList
<>();
229 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
231 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
232 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
233 return specimensOrObersvations
;
237 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
238 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
239 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
242 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
246 * @return URI parameter Strings for the EDIT Map Service
247 * @throws IOException TODO write controller method documentation
249 @RequestMapping(value
= { "taxonOccurrencesForX" }, method
= RequestMethod
.GET
)
250 public ModelAndView
doGetOccurrenceXMapUriParams(
251 @RequestParam(value
= "fieldUnitUuidList", required
= false) UuidList fieldUnitUuids
,
252 HttpServletRequest request
,
253 HttpServletResponse response
)
256 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
258 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
259 ModelAndView mv
= new ModelAndView();
261 List
<Point
> fieldUnitPoints
= occurrenceService
.findPointsForFieldUnitList(fieldUnitUuids
);
263 OccurrenceServiceRequestParameterDto dto
= EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
264 null, specimenOrObservationTypeColors
);
277 * @throws IOException
279 * @author a.kohlbecker
281 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
282 public ModelAndView
doMapShapeFileToNamedAreas(
283 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
284 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
285 @RequestParam(required
=true, value
="localFile") String localFile
,
286 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
287 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
288 HttpServletRequest request
,
289 HttpServletResponse response
)
292 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
293 ModelAndView mv
= new ModelAndView();
295 FileReader reader
= new FileReader(localFile
);
297 Set
<UUID
> areaUuidSet
= null;
298 if(namedAreaUuids
!= null) {
299 areaUuidSet
= namedAreaUuids
.asSet();
301 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
302 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
303 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
304 for(NamedArea area
: resultMap
.keySet()){
305 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
307 mv
.addObject(flatResultMap
);