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
.EnumSet
;
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
.filter
.TaxonOccurrenceRelationType
;
38 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
39 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
40 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.geo
.IDistributionService
;
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
.MarkerType
;
49 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
50 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
51 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
52 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
53 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
54 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
55 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
56 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
57 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
58 import eu
.etaxonomy
.cdm
.remote
.controller
.TaxonController
;
59 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
60 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
61 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
62 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
63 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
64 import io
.swagger
.annotations
.Api
;
67 * The ExternalGeoController class is a Spring MVC Controller.
69 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
70 * The available {datasource-name}s are defined in a configuration file which
71 * is loaded by the {@link UpdatableRoutingDataSource}. If the
72 * UpdatableRoutingDataSource is not being used in the actual application
73 * context any arbitrary {datasource-name} may be used.
75 * @author a.kohlbecker
81 @Api(value
="mapServiceParameters")
82 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
83 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
85 private static final Logger logger
= LogManager
.getLogger();
88 private IEditGeoService geoService
;
91 private IDistributionService distributionService
;
94 private IDescriptionService descriptionService
;
97 private IOccurrenceService occurrenceService
;
100 private ITermService termService
;
104 public void initBinder(WebDataBinder binder
) {
105 super.initBinder(binder
);
106 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
107 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
112 public void setService(ITaxonService service
) {
113 this.service
= service
;
117 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
118 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
119 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
122 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
126 * @return URI parameter Strings for the EDIT Map Service
127 * @throws IOException TODO write controller method documentation
129 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
130 public OccurrenceServiceRequestParameterDto
doGetOccurrenceMapUriParams(
131 @PathVariable("uuid") UUID taxonUuid
,
132 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
133 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
134 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
135 @RequestParam(value
= "taxOccRelFilter", required
= false) String taxOccRelFilter
,
136 HttpServletRequest request
,
137 HttpServletResponse response
)
140 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
142 boolean includeUnpublished
= NO_UNPUBLISHED
;
143 EnumSet
<TaxonOccurrenceRelationType
> taxonOccurrenceRelTypes
= TaxonController
.bindAssociationFilter(taxOccRelFilter
);
145 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
147 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurencesForTaxon(taxonUuid
, relationshipUuids
,
148 relationshipInversUuids
, includeUnpublished
,
149 taxonOccurrenceRelTypes
,
152 OccurrenceServiceRequestParameterDto dto
= geoService
.getOccurrenceServiceRequestParameters(specimensOrObersvations
,
153 specimenOrObservationTypeColors
);
158 private List
<SpecimenOrObservationBase
> occurencesForTaxon(UUID taxonUuid
, UuidList relationshipUuids
,
159 UuidList relationshipInversUuids
, boolean includeUnpublished
,
160 EnumSet
<TaxonOccurrenceRelationType
> taxonOccurrenceRelTypes
,
162 HttpServletResponse response
) throws IOException
{
164 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
165 relationshipUuids
, relationshipInversUuids
, termService
);
167 Taxon taxon
= getCdmBaseInstance(Taxon
.class, taxonUuid
, response
, (List
<String
>)null);
169 List
<OrderHint
> orderHints
= new ArrayList
<>();
170 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
172 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
173 null, includeRelationships
, taxon
, includeUnpublished
,
174 taxonOccurrenceRelTypes
,
175 maxDepth
, null, null, orderHints
, null);
176 return specimensOrObersvations
;
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 //TODO needed? Seems to be not used currently. Difference to
193 // doGetOccurrenceMapUriParams() seems to be that there is taxon relation here
194 @RequestMapping(value
= { "taxonOccurrencesForX" }, method
= RequestMethod
.GET
)
195 public ModelAndView
doGetOccurrenceXMapUriParams(
196 @RequestParam(value
= "fieldUnitUuidList", required
= false) UuidList fieldUnitUuids
,
197 HttpServletRequest request
,
198 HttpServletResponse response
)
201 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
203 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
204 ModelAndView mv
= new ModelAndView();
206 List
<Point
> fieldUnitPoints
= occurrenceService
.findPointsForFieldUnitList(fieldUnitUuids
);
208 OccurrenceServiceRequestParameterDto dto
= EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
209 null, specimenOrObservationTypeColors
);
222 * @throws IOException
224 * @author a.kohlbecker
226 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
227 public ModelAndView
doMapShapeFileToNamedAreas(
228 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
229 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
230 @RequestParam(required
=true, value
="localFile") String localFile
,
231 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
232 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
233 HttpServletRequest request
,
234 HttpServletResponse response
)
237 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
238 ModelAndView mv
= new ModelAndView();
240 FileReader reader
= new FileReader(localFile
);
242 Set
<UUID
> areaUuidSet
= null;
243 if(namedAreaUuids
!= null) {
244 areaUuidSet
= namedAreaUuids
.asSet();
246 Map
<NamedArea
, String
> resultMap
= distributionService
.mapShapeFileToNamedAreas(
247 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
248 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
249 for(NamedArea area
: resultMap
.keySet()){
250 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
252 mv
.addObject(flatResultMap
);