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 io
.swagger
.annotations
.Api
;
13 import java
.awt
.Color
;
14 import java
.io
.FileReader
;
15 import java
.io
.IOException
;
16 import java
.util
.ArrayList
;
17 import java
.util
.Collection
;
18 import java
.util
.HashMap
;
19 import java
.util
.List
;
22 import java
.util
.UUID
;
24 import javax
.servlet
.http
.HttpServletRequest
;
25 import javax
.servlet
.http
.HttpServletResponse
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.springframework
.beans
.factory
.annotation
.Autowired
;
29 import org
.springframework
.stereotype
.Controller
;
30 import org
.springframework
.web
.bind
.WebDataBinder
;
31 import org
.springframework
.web
.bind
.annotation
.InitBinder
;
32 import org
.springframework
.web
.bind
.annotation
.PathVariable
;
33 import org
.springframework
.web
.bind
.annotation
.RequestMapping
;
34 import org
.springframework
.web
.bind
.annotation
.RequestMethod
;
35 import org
.springframework
.web
.bind
.annotation
.RequestParam
;
36 import org
.springframework
.web
.servlet
.ModelAndView
;
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
.pager
.Pager
;
43 import eu
.etaxonomy
.cdm
.api
.service
.util
.TaxonRelationshipEdge
;
44 import eu
.etaxonomy
.cdm
.api
.utility
.DescriptionUtility
;
45 import eu
.etaxonomy
.cdm
.database
.UpdatableRoutingDataSource
;
46 import eu
.etaxonomy
.cdm
.ext
.geo
.IEditGeoService
;
47 import eu
.etaxonomy
.cdm
.ext
.geo
.OccurrenceServiceRequestParameterDto
;
48 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTerm
;
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
.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
.persistence
.query
.OrderHint
;
60 import eu
.etaxonomy
.cdm
.persistence
.query
.OrderHint
.SortOrder
;
61 import eu
.etaxonomy
.cdm
.remote
.controller
.BaseController
;
62 import eu
.etaxonomy
.cdm
.remote
.controller
.util
.ControllerUtils
;
63 import eu
.etaxonomy
.cdm
.remote
.editor
.DefinedTermBaseList
;
64 import eu
.etaxonomy
.cdm
.remote
.editor
.TermBaseListPropertyEditor
;
65 import eu
.etaxonomy
.cdm
.remote
.editor
.UUIDListPropertyEditor
;
66 import eu
.etaxonomy
.cdm
.remote
.editor
.UuidList
;
67 import eu
.etaxonomy
.cdm
.remote
.l10n
.LocaleContext
;
70 * The ExternalGeoController class is a Spring MVC Controller.
72 * The syntax of the mapped service URIs contains the the {datasource-name} path element.
73 * The available {datasource-name}s are defined in a configuration file which
74 * is loaded by the {@link UpdatableRoutingDataSource}. If the
75 * UpdatableRoutingDataSource is not being used in the actual application
76 * context any arbitrary {datasource-name} may be used.
78 * @author a.kohlbecker
83 @Api(value
="mapServiceParameters")
84 @RequestMapping(value
= { "ext/edit/mapServiceParameters/" })
85 public class ExternalGeoController
extends BaseController
<TaxonBase
, ITaxonService
> {
87 public static final Logger logger
= Logger
.getLogger(ExternalGeoController
.class);
90 private IEditGeoService geoservice
;
93 private IDescriptionService descriptionService
;
96 private IOccurrenceService occurrenceService
;
99 private ITermService termService
;
103 public void initBinder(WebDataBinder binder
) {
104 super.initBinder(binder
);
105 binder
.registerCustomEditor(UuidList
.class, new UUIDListPropertyEditor());
106 binder
.registerCustomEditor(DefinedTermBaseList
.class, new TermBaseListPropertyEditor
<MarkerType
>(termService
));
111 public void setService(ITaxonService service
) {
112 this.service
= service
;
116 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
117 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
118 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
121 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
124 * @param subAreaPreference
125 * enables the <b>Sub area preference rule</b> if set to true,
126 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
127 * @param statusOrderPreference
128 * enables the <b>Status order preference rule</b> if set to true,
129 * see {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean}
130 * @param hideMarkedAreas
131 * comma separated list of {@link MarkerType} uuids,
132 * distributions where the area has a {@link Marker} with one of
133 * the specified {@link MarkerType}s will be skipped, see
134 * {@link DescriptionUtility#filterDistributions(Collection, boolean, boolean, Set)}
137 * @return URI parameter Strings for the EDIT Map Service
138 * @throws IOException
140 @RequestMapping(value
= { "taxonDistributionFor/{uuid}" }, method
= RequestMethod
.GET
)
141 public ModelAndView
doGetDistributionMapUriParams(
142 @PathVariable("uuid") UUID uuid
,
143 @RequestParam(value
= "subAreaPreference", required
= false) boolean subAreaPreference
,
144 @RequestParam(value
= "statusOrderPreference", required
= false) boolean statusOrderPreference
,
145 @RequestParam(value
= "hideMarkedAreas", required
= false) DefinedTermBaseList
<MarkerType
> hideMarkedAreasList
,
146 HttpServletRequest request
,
147 HttpServletResponse response
)
150 logger
.info("doGetDistributionMapUriParams() " + request
.getRequestURI());
151 ModelAndView mv
= new ModelAndView();
153 // get the descriptions for the taxon
154 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
156 Map
<PresenceAbsenceTerm
, Color
> presenceAbsenceTermColors
= null;
158 List
<Language
> langs
= LocaleContext
.getLanguages();
160 Set
<MarkerType
> hideMarkedAreas
= null;
161 if(hideMarkedAreasList
!= null){
162 hideMarkedAreas
= hideMarkedAreasList
.asSet();
165 Set
<DefinedTerm
> scopes
= null;
166 Set
<NamedArea
> geographicalScope
= null;
167 Integer pageSize
= null;
168 Integer pageNumber
= null;
169 List
<String
> propertyPaths
= null;
170 Pager
<TaxonDescription
> page
= descriptionService
.pageTaxonDescriptions(taxon
, scopes
, geographicalScope
, pageSize
, pageNumber
, propertyPaths
);
172 List
<TaxonDescription
> taxonDescriptions
= page
.getRecords();
173 String uriParams
= geoservice
.getDistributionServiceRequestParameterString(taxonDescriptions
,
174 subAreaPreference
, statusOrderPreference
,
175 hideMarkedAreas
, presenceAbsenceTermColors
, langs
);
176 mv
.addObject(uriParams
);
183 * Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
184 * {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
185 * an valid URI parameter String. Higher level distribution areas are expanded in order to include all
188 * URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
192 * @return URI parameter Strings for the EDIT Map Service
193 * @throws IOException TODO write controller method documentation
195 @RequestMapping(value
= { "taxonOccurrencesFor/{uuid}" }, method
= RequestMethod
.GET
)
196 public ModelAndView
doGetOccurrenceMapUriParams(
197 @PathVariable("uuid") UUID uuid
,
198 @RequestParam(value
= "relationships", required
= false) UuidList relationshipUuids
,
199 @RequestParam(value
= "relationshipsInvers", required
= false) UuidList relationshipInversUuids
,
200 @RequestParam(value
= "maxDepth", required
= false) Integer maxDepth
,
201 HttpServletRequest request
,
202 HttpServletResponse response
)
205 Map
<SpecimenOrObservationType
, Color
> specimenOrObservationTypeColors
= null;
207 logger
.info("doGetOccurrenceMapUriParams() " + requestPathAndQuery(request
));
208 ModelAndView mv
= new ModelAndView();
210 Set
<TaxonRelationshipEdge
> includeRelationships
= ControllerUtils
.loadIncludeRelationships(
211 relationshipUuids
, relationshipInversUuids
, termService
);
213 Taxon taxon
= getCdmBaseInstance(Taxon
.class, uuid
, response
, (List
<String
>)null);
215 List
<OrderHint
> orderHints
= new ArrayList
<OrderHint
>();
216 orderHints
.add(new OrderHint("titleCache", SortOrder
.DESCENDING
));
218 List
<SpecimenOrObservationBase
> specimensOrObersvations
= occurrenceService
.listByAssociatedTaxon(
219 null, includeRelationships
, taxon
, maxDepth
, null, null, orderHints
, null);
221 OccurrenceServiceRequestParameterDto dto
= geoservice
.getOccurrenceServiceRequestParameterString(specimensOrObersvations
,
222 specimenOrObservationTypeColors
);
235 * @throws IOException
237 * @author a.kohlbecker
239 @RequestMapping(value
= { "mapShapeFileToNamedAreas" }, method
= RequestMethod
.GET
)
240 public ModelAndView
doMapShapeFileToNamedAreas(
241 @RequestParam(required
=false, value
="vocabularyUuid") UUID vocabUuid
,
242 @RequestParam(required
=false, value
="namedAreaUuids") UuidList namedAreaUuids
,
243 @RequestParam(required
=true, value
="localFile") String localFile
,
244 @RequestParam(required
=true, value
="idSearchField") List
<String
> idSearchFields
,
245 @RequestParam(required
=true, value
="wmsLayerName") String wmsLayerName
,
246 HttpServletRequest request
,
247 HttpServletResponse response
)
250 logger
.info("doMapShapeFileToNamedAreas() " + requestPathAndQuery(request
));
251 ModelAndView mv
= new ModelAndView();
253 FileReader reader
= new FileReader(localFile
);
255 Set
<UUID
> areaUuidSet
= null;
256 if(namedAreaUuids
!= null) {
257 areaUuidSet
= namedAreaUuids
.asSet();
259 Map
<NamedArea
, String
> resultMap
= geoservice
.mapShapeFileToNamedAreas(
260 reader
, idSearchFields
, wmsLayerName
, vocabUuid
, areaUuidSet
);
261 Map
<String
, String
> flatResultMap
= new HashMap
<String
, String
>(resultMap
.size());
262 for(NamedArea area
: resultMap
.keySet()){
263 flatResultMap
.put(area
.getTitleCache() + " [" + area
.getUuid() + "]", resultMap
.get(area
));
265 mv
.addObject(flatResultMap
);