1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.remote.controller.ext;
|
10
|
|
11
|
import java.awt.Color;
|
12
|
import java.io.IOException;
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import javax.servlet.http.HttpServletRequest;
|
20
|
import javax.servlet.http.HttpServletResponse;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Controller;
|
25
|
import org.springframework.web.bind.WebDataBinder;
|
26
|
import org.springframework.web.bind.annotation.CrossOrigin;
|
27
|
import org.springframework.web.bind.annotation.InitBinder;
|
28
|
import org.springframework.web.bind.annotation.PathVariable;
|
29
|
import org.springframework.web.bind.annotation.RequestMapping;
|
30
|
import org.springframework.web.bind.annotation.RequestMethod;
|
31
|
import org.springframework.web.bind.annotation.RequestParam;
|
32
|
|
33
|
import de.micromata.opengis.kml.v_2_2_0.Kml;
|
34
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
35
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
36
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
37
|
import eu.etaxonomy.cdm.api.service.util.TaxonRelationshipEdge;
|
38
|
import eu.etaxonomy.cdm.database.UpdatableRoutingDataSource;
|
39
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
40
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
41
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
42
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
43
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
44
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
45
|
import eu.etaxonomy.cdm.persistence.query.OrderHint;
|
46
|
import eu.etaxonomy.cdm.persistence.query.OrderHint.SortOrder;
|
47
|
import eu.etaxonomy.cdm.remote.controller.BaseController;
|
48
|
import eu.etaxonomy.cdm.remote.controller.util.ControllerUtils;
|
49
|
import eu.etaxonomy.cdm.remote.editor.DefinedTermBaseList;
|
50
|
import eu.etaxonomy.cdm.remote.editor.TermBaseListPropertyEditor;
|
51
|
import eu.etaxonomy.cdm.remote.editor.UUIDListPropertyEditor;
|
52
|
import eu.etaxonomy.cdm.remote.editor.UuidList;
|
53
|
import io.swagger.annotations.Api;
|
54
|
|
55
|
/**
|
56
|
* The ExternalGeoController class is a Spring MVC Controller.
|
57
|
* <p>
|
58
|
* The syntax of the mapped service URIs contains the the {datasource-name} path element.
|
59
|
* The available {datasource-name}s are defined in a configuration file which
|
60
|
* is loaded by the {@link UpdatableRoutingDataSource}. If the
|
61
|
* UpdatableRoutingDataSource is not being used in the actual application
|
62
|
* context any arbitrary {datasource-name} may be used.
|
63
|
* <p>
|
64
|
* @author a.kohlbecker
|
65
|
* @since 18.06.2009
|
66
|
*
|
67
|
*/
|
68
|
@CrossOrigin(origins = "*")
|
69
|
@Controller
|
70
|
@Api(value="mapServiceParameters")
|
71
|
@RequestMapping(value = { "kml" })
|
72
|
public class KmlController extends BaseController<TaxonBase, ITaxonService> {
|
73
|
|
74
|
public static final Logger logger = Logger.getLogger(KmlController.class);
|
75
|
|
76
|
@Autowired
|
77
|
private IEditGeoService geoservice;
|
78
|
|
79
|
@Autowired
|
80
|
private IOccurrenceService occurrenceService;
|
81
|
|
82
|
@Autowired
|
83
|
private ITermService termService;
|
84
|
|
85
|
@InitBinder
|
86
|
@Override
|
87
|
public void initBinder(WebDataBinder binder) {
|
88
|
super.initBinder(binder);
|
89
|
binder.registerCustomEditor(UuidList.class, new UUIDListPropertyEditor());
|
90
|
binder.registerCustomEditor(DefinedTermBaseList.class, new TermBaseListPropertyEditor<MarkerType>(termService));
|
91
|
}
|
92
|
|
93
|
@Autowired
|
94
|
@Override
|
95
|
public void setService(ITaxonService service) {
|
96
|
this.service = service;
|
97
|
}
|
98
|
|
99
|
/**
|
100
|
* Assembles and returns URI parameter Strings for the EDIT Map Service. The distribution areas for the
|
101
|
* {@link Taxon} instance identified by the <code>{taxon-uuid}</code> are found and are translated into
|
102
|
* an valid URI parameter String. Higher level distribution areas are expanded in order to include all
|
103
|
* nested sub-areas.
|
104
|
* <p>
|
105
|
* URI: <b>/{datasource-name}/geo/map/distribution/{taxon-uuid}</b>
|
106
|
*
|
107
|
* @param request
|
108
|
* @param response
|
109
|
* @return URI parameter Strings for the EDIT Map Service
|
110
|
* @throws IOException TODO write controller method documentation
|
111
|
*/
|
112
|
@RequestMapping(value = { "taxonOccurrencesFor/{uuid}" }, method = RequestMethod.GET)
|
113
|
public Kml doGetOccurrenceKml(
|
114
|
@PathVariable("uuid") UUID uuid,
|
115
|
@RequestParam(value = "relationships", required = false) UuidList relationshipUuids,
|
116
|
@RequestParam(value = "relationshipsInvers", required = false) UuidList relationshipInversUuids,
|
117
|
@RequestParam(value = "maxDepth", required = false) Integer maxDepth,
|
118
|
HttpServletRequest request,
|
119
|
HttpServletResponse response)
|
120
|
throws IOException {
|
121
|
|
122
|
|
123
|
logger.info("doGetOccurrenceKml() " + requestPathAndQuery(request));
|
124
|
|
125
|
Map<SpecimenOrObservationType, Color> specimenOrObservationTypeColors = null;
|
126
|
|
127
|
List<SpecimenOrObservationBase> specimensOrObersvations = occurencesForTaxon(uuid, relationshipUuids,
|
128
|
relationshipInversUuids, maxDepth, response);
|
129
|
|
130
|
Kml kml = geoservice.occurrencesToKML(specimensOrObersvations, specimenOrObservationTypeColors);
|
131
|
|
132
|
return kml;
|
133
|
}
|
134
|
|
135
|
private List<SpecimenOrObservationBase> occurencesForTaxon(UUID taxonUuid, UuidList relationshipUuids,
|
136
|
UuidList relationshipInversUuids, Integer maxDepth, HttpServletResponse response) throws IOException {
|
137
|
Set<TaxonRelationshipEdge> includeRelationships = ControllerUtils.loadIncludeRelationships(
|
138
|
relationshipUuids, relationshipInversUuids, termService);
|
139
|
|
140
|
Taxon taxon = getCdmBaseInstance(Taxon.class, taxonUuid, response, (List<String>)null);
|
141
|
|
142
|
List<OrderHint> orderHints = new ArrayList<OrderHint>();
|
143
|
orderHints.add(new OrderHint("titleCache", SortOrder.DESCENDING));
|
144
|
|
145
|
List<SpecimenOrObservationBase> specimensOrObersvations = occurrenceService.listByAssociatedTaxon(
|
146
|
null, includeRelationships, taxon, maxDepth, null, null, orderHints, null);
|
147
|
return specimensOrObersvations;
|
148
|
}
|
149
|
|
150
|
|
151
|
}
|