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
.log4j
.Logger
;
26 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
27 import org
.springframework
.http
.HttpStatus
;
28 import org
.springframework
.http
.ResponseEntity
;
29 import org
.springframework
.stereotype
.Controller
;
30 import org
.springframework
.web
.bind
.WebDataBinder
;
31 import org
.springframework
.web
.bind
.annotation
.CrossOrigin
;
32 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
33 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
34 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
35 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
36 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
37 import org
.springframework
.web
.bind
.annotation
.RestController
;
38 import org
.springframework
.web
.servlet
.ModelAndView
;
40 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
41 import eu
.etaxonomy
.cdm
.api
.service
.IOccurrenceService
;
42 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonService
;
43 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
44 import eu
.etaxonomy
.cdm
.api
.service
.pager
.Pager
;
45 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
46 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
47 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
48 import eu
.etaxonomy
.cdm
.ext
.geo
.EditGeoServiceUtilities
;
49 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
50 import eu
.etaxonomy
.cdm
.ext
.geo
.OccurrenceServiceRequestParameterDto
;
51 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
52 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
53 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
54 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
55 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
56 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
57 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
58 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
59 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
60 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
61 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
62 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
63 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
;
64 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
65 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
66 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
67 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
68 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
69 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
70 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
71 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
72 import io
.swagger
.annotations
.Api
;
75 * The ExternalGeoController class is a Spring MVC Controller.
77 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
78 * The available {datasource-name}s are defined in a configuration file which
79 * is loaded by the {@link UpdatableRoutingDataSource}. If the
80 * UpdatableRoutingDataSource is not being used in the actual application
81 * context any arbitrary {datasource-name} may be used.
83 * @author a.kohlbecker
89 @Api(value
="mapServiceParameters")
90 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
91 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
93 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
96 private IEditGeoService geoservice
;
99 private IDescriptionService descriptionService
;
102 private IOccurrenceService occurrenceService
;
105 private ITermService termService
;
109 public void initBinder(WebDataBinder binder
) {
110 super.initBinder(binder
);
111 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
112 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
117 public void setService(ITaxonService service
) {
118 this.service
= service
;
122 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
123 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
124 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
127 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
130 * @param subAreaPreference
131 * enables the <b>Sub area preference rule</b> if set to true,
132 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
133 * @param statusOrderPreference
134 * enables the <b>Status order preference rule</b> if set to true,
135 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
136 * @param hideMarkedAreas
137 * comma separated list of {@link MarkerType} uuids,
138 * distributions where the area has a {@link Marker} with one of
139 * the specified {@link MarkerType}s will be skipped, see
140 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
143 * @return URI parameter Strings for the EDIT Map Service
144 * @throws IOException
146 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
147 public ModelAndView
doGetDistributionMapUriParams(
148 @PathVariable("uuid") UUID uuid
,
149 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
150 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
151 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
152 HttpServletRequest request
,
153 HttpServletResponse response
)
156 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
157 ModelAndView mv
= new ModelAndView();
159 // get the descriptions for the taxon
160 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
162 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= null;
164 List
<Language
> langs
= LocaleContext
.getLanguages();
166 Set
<MarkerType
> hideMarkedAreas
= null;
167 if(hideMarkedAreasList
!= null){
168 hideMarkedAreas
= hideMarkedAreasList
.asSet();
171 Set
<DefinedTerm
> scopes
= null;
172 Set
<NamedArea
> geographicalScope
= null;
173 Integer pageSize
= null;
174 Integer pageNumber
= null;
175 List
<String
> propertyPaths
= null;
176 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
178 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
179 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
180 subAreaPreference
, statusOrderPreference
,
181 hideMarkedAreas
, presenceAbsenceTermColors
, langs
);
182 mv
.addObject(uriParams
);
189 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
190 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
191 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
194 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
198 * @return URI parameter Strings for the EDIT Map Service
199 * @throws IOException TODO write controller method documentation
201 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
202 public OccurrenceServiceRequestParameterDto
doGetOccurrenceMapUriParams(
203 @PathVariable("uuid") UUID uuid
,
204 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
205 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
206 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
207 HttpServletRequest request
,
208 HttpServletResponse response
)
212 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
214 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
216 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurencesForTaxon(uuid
, relationshipUuids
,
217 relationshipInversUuids
, maxDepth
, response
);
219 OccurrenceServiceRequestParameterDto dto
= geoservice
.getOccurrenceServiceRequestParameters(specimensOrObersvations
,
220 specimenOrObservationTypeColors
);
225 private List
<SpecimenOrObservationBase
> occurencesForTaxon(UUID taxonUuid
, UuidList relationshipUuids
,
226 UuidList relationshipInversUuids
, Integer maxDepth
, HttpServletResponse response
) throws IOException
{
227 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
228 relationshipUuids
, relationshipInversUuids
, termService
);
230 Taxon taxon
= getCdmBaseInstance(Taxon
.class, taxonUuid
, response
, (List
<String
>)null);
232 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
233 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
235 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
236 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
237 return specimensOrObersvations
;
241 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
242 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
243 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
246 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
250 * @return URI parameter Strings for the EDIT Map Service
251 * @throws IOException TODO write controller method documentation
253 @RequestMapping(value
= { "taxonOccurrencesForX" }, method
= RequestMethod
.GET
)
254 public ModelAndView
doGetOccurrenceXMapUriParams(
255 @RequestParam(value
= "fieldUnitUuidList", required
= false) UuidList fieldUnitUuids
,
256 HttpServletRequest request
,
257 HttpServletResponse response
)
260 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
262 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
263 ModelAndView mv
= new ModelAndView();
265 List
<Point
> fieldUnitPoints
= occurrenceService
.findPointsForFieldUnitList(fieldUnitUuids
);
267 OccurrenceServiceRequestParameterDto dto
= EditGeoServiceUtilities
.getOccurrenceServiceRequestParameterString(fieldUnitPoints
,
268 null, specimenOrObservationTypeColors
);
281 * @throws IOException
283 * @author a.kohlbecker
285 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
286 public ModelAndView
doMapShapeFileToNamedAreas(
287 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
288 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
289 @RequestParam(required
=true, value
="localFile") String localFile
,
290 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
291 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
292 HttpServletRequest request
,
293 HttpServletResponse response
)
296 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
297 ModelAndView mv
= new ModelAndView();
299 FileReader reader
= new FileReader(localFile
);
301 Set
<UUID
> areaUuidSet
= null;
302 if(namedAreaUuids
!= null) {
303 areaUuidSet
= namedAreaUuids
.asSet();
305 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
306 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
307 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
308 for(NamedArea area
: resultMap
.keySet()){
309 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
311 mv
.addObject(flatResultMap
);