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
.HashMap
;
16 import java
.util
.List
;
19 import java
.util
.UUID
;
21 import javax
.servlet
.http
.HttpServletRequest
;
22 import javax
.servlet
.http
.HttpServletResponse
;
24 import org
.apache
.logging
.log4j
.LogManager
;
25 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
.geo
.IDistributionService
;
41 import eu
.etaxonomy
.cdm
.api
.util
.TaxonRelationshipEdge
;
42 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
43 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
44 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
45 import eu
.etaxonomy
.cdm
.ext
.geo
.OccurrenceServiceRequestParameterDto
;
46 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
47 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
48 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
49 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
50 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
51 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
52 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
53 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
54 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
55 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
56 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
57 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
58 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
59 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
60 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
61 import io
.swagger
.annotations
.Api
;
64 * The ExternalGeoController class is a Spring MVC Controller.
66 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
67 * The available {datasource-name}s are defined in a configuration file which
68 * is loaded by the {@link UpdatableRoutingDataSource}. If the
69 * UpdatableRoutingDataSource is not being used in the actual application
70 * context any arbitrary {datasource-name} may be used.
72 * @author a.kohlbecker
78 @Api(value
="mapServiceParameters")
79 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
80 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
82 private static final Logger logger
= LogManager
.getLogger();
85 private IEditGeoService geoService
;
88 private IDistributionService distributionService
;
91 private IDescriptionService descriptionService
;
94 private IOccurrenceService occurrenceService
;
97 private ITermService termService
;
101 public void initBinder(WebDataBinder binder
) {
102 super.initBinder(binder
);
103 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
104 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
109 public void setService(ITaxonService service
) {
110 this.service
= service
;
114 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
115 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
116 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
119 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
123 * @return URI parameter Strings for the EDIT Map Service
124 * @throws IOException TODO write controller method documentation
126 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
127 public OccurrenceServiceRequestParameterDto
doGetOccurrenceMapUriParams(
128 @PathVariable("uuid") UUID uuid
,
129 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
130 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
131 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
132 HttpServletRequest request
,
133 HttpServletResponse response
)
137 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
139 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
141 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurencesForTaxon(uuid
, relationshipUuids
,
142 relationshipInversUuids
, maxDepth
, response
);
144 OccurrenceServiceRequestParameterDto dto
= geoService
.getOccurrenceServiceRequestParameters(specimensOrObersvations
,
145 specimenOrObservationTypeColors
);
150 private List
<SpecimenOrObservationBase
> occurencesForTaxon(UUID taxonUuid
, UuidList relationshipUuids
,
151 UuidList relationshipInversUuids
, Integer maxDepth
, HttpServletResponse response
) throws IOException
{
152 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
153 relationshipUuids
, relationshipInversUuids
, termService
);
155 Taxon taxon
= getCdmBaseInstance(Taxon
.class, taxonUuid
, response
, (List
<String
>)null);
157 List
<OrderHint
> orderHints
= new ArrayList
<>();
158 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
160 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
161 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
162 return specimensOrObersvations
;
166 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
167 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
168 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
171 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
175 * @return URI parameter Strings for the EDIT Map Service
176 * @throws IOException TODO write controller method documentation
178 @RequestMapping(value
= { "taxonOccurrencesForX" }, method
= RequestMethod
.GET
)
179 public ModelAndView
doGetOccurrenceXMapUriParams(
180 @RequestParam(value
= "fieldUnitUuidList", required
= false) UuidList fieldUnitUuids
,
181 HttpServletRequest request
,
182 HttpServletResponse response
)
185 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
187 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
188 ModelAndView mv
= new ModelAndView();
190 List
<Point
> fieldUnitPoints
= occurrenceService
.findPointsForFieldUnitList(fieldUnitUuids
);
192 OccurrenceServiceRequestParameterDto dto
= EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
193 null, specimenOrObservationTypeColors
);
206 * @throws IOException
208 * @author a.kohlbecker
210 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
211 public ModelAndView
doMapShapeFileToNamedAreas(
212 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
213 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
214 @RequestParam(required
=true, value
="localFile") String localFile
,
215 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
216 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
217 HttpServletRequest request
,
218 HttpServletResponse response
)
221 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
222 ModelAndView mv
= new ModelAndView();
224 FileReader reader
= new FileReader(localFile
);
226 Set
<UUID
> areaUuidSet
= null;
227 if(namedAreaUuids
!= null) {
228 areaUuidSet
= namedAreaUuids
.asSet();
230 Map
<NamedArea
, String
> resultMap
= distributionService
.mapShapeFileToNamedAreas(
231 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
232 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
233 for(NamedArea area
: resultMap
.keySet()){
234 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
236 mv
.addObject(flatResultMap
);