1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2009 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.cdm.ext.geo;
|
11
|
|
12
|
import java.awt.Color;
|
13
|
import java.io.IOException;
|
14
|
import java.io.Reader;
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.HashSet;
|
17
|
import java.util.List;
|
18
|
import java.util.Map;
|
19
|
import java.util.Set;
|
20
|
import java.util.UUID;
|
21
|
|
22
|
import org.apache.log4j.Logger;
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
24
|
import org.springframework.stereotype.Service;
|
25
|
import org.springframework.transaction.annotation.Transactional;
|
26
|
|
27
|
import eu.etaxonomy.cdm.model.common.Language;
|
28
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
29
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
32
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
33
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
34
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
35
|
import eu.etaxonomy.cdm.model.location.Point;
|
36
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
37
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
38
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
39
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
40
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
41
|
import eu.etaxonomy.cdm.persistence.dao.common.ITermVocabularyDao;
|
42
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
|
43
|
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
|
44
|
|
45
|
/**
|
46
|
* @author a.kohlbecker
|
47
|
* @date 18.06.2009
|
48
|
*
|
49
|
*/
|
50
|
@Service
|
51
|
@Transactional(readOnly = true)
|
52
|
public class EditGeoService implements IEditGeoService {
|
53
|
public static final Logger logger = Logger.getLogger(EditGeoService.class);
|
54
|
|
55
|
// private static final String DEFAULT_BACK_LAYER = "tdwg4";
|
56
|
|
57
|
@Autowired
|
58
|
private IDescriptionDao dao;
|
59
|
|
60
|
@Autowired
|
61
|
private IGeoServiceAreaMapping areaMapping;
|
62
|
|
63
|
private IDefinedTermDao termDao;
|
64
|
|
65
|
@Autowired
|
66
|
private ITermVocabularyDao vocabDao;
|
67
|
|
68
|
@Autowired
|
69
|
public void setTermDao(IDefinedTermDao termDao) {
|
70
|
this.termDao = termDao;
|
71
|
EditGeoServiceUtilities.setTermDao(termDao);
|
72
|
}
|
73
|
|
74
|
@Autowired
|
75
|
private IOccurrenceDao occurrenceDao;
|
76
|
|
77
|
private Set<Feature> getDistributionFeatures() {
|
78
|
Set<Feature> distributionFeature = new HashSet<Feature>();
|
79
|
Feature feature = (Feature) termDao.findByUuid(Feature.DISTRIBUTION().getUuid());
|
80
|
distributionFeature.add(feature);
|
81
|
return distributionFeature;
|
82
|
}
|
83
|
|
84
|
/*
|
85
|
* (non-Javadoc)
|
86
|
*
|
87
|
* @see
|
88
|
* eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString
|
89
|
* (java.util.List, java.util.Map, int, int, java.lang.String,
|
90
|
* java.lang.String, java.util.List)
|
91
|
*/
|
92
|
@Override
|
93
|
public String getDistributionServiceRequestParameterString(List<TaxonDescription> taxonDescriptions,
|
94
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
|
95
|
String backLayer, List<Language> langs) {
|
96
|
|
97
|
Set<Distribution> distributions = new HashSet<Distribution>();
|
98
|
for (TaxonDescription taxonDescription : taxonDescriptions) {
|
99
|
List<Distribution> result = (List) dao.getDescriptionElements(
|
100
|
taxonDescription, null,
|
101
|
getDistributionFeatures(),
|
102
|
Distribution.class,
|
103
|
null,
|
104
|
null,
|
105
|
null);
|
106
|
distributions.addAll(result);
|
107
|
}
|
108
|
|
109
|
String uriParams = getDistributionServiceRequestParameterString(distributions, presenceAbsenceTermColors,
|
110
|
width, height, bbox, backLayer, langs);
|
111
|
|
112
|
return uriParams;
|
113
|
}
|
114
|
|
115
|
|
116
|
/* (non-Javadoc)
|
117
|
* @see eu.etaxonomy.cdm.ext.geo.IEditGeoService#getDistributionServiceRequestParameterString(java.util.Set, java.util.Map, int, int, java.lang.String, java.lang.String, java.util.List)
|
118
|
*/
|
119
|
@Override
|
120
|
public String getDistributionServiceRequestParameterString(Set<Distribution> distributions,
|
121
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
|
122
|
String backLayer, List<Language> langs) {
|
123
|
|
124
|
// if (backLayer == null) {
|
125
|
// backLayer = DEFAULT_BACK_LAYER;
|
126
|
// }
|
127
|
String uriParams = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions,
|
128
|
areaMapping, presenceAbsenceTermColors, width, height, bbox, backLayer, null, langs);
|
129
|
return uriParams;
|
130
|
}
|
131
|
|
132
|
/*
|
133
|
* (non-Javadoc)
|
134
|
*
|
135
|
* @see
|
136
|
* eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString
|
137
|
* (eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int,
|
138
|
* int, java.lang.String, java.lang.String)
|
139
|
*/
|
140
|
@Override
|
141
|
@Deprecated
|
142
|
public String getDistributionServiceRequestParameterString(TaxonDescription taxonDescription,
|
143
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
|
144
|
String backLayer, List<Language> langs) {
|
145
|
|
146
|
List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
|
147
|
taxonDescriptions.add(taxonDescription);
|
148
|
|
149
|
return getDistributionServiceRequestParameterString(taxonDescriptions, presenceAbsenceTermColors, width,
|
150
|
height, bbox, backLayer, langs);
|
151
|
}
|
152
|
|
153
|
/*
|
154
|
* (non-Javadoc)
|
155
|
*
|
156
|
* @see eu.etaxonomy.cdm.ext.geo.IEditGeoService#
|
157
|
* getOccurrenceServiceRequestParameterString
|
158
|
* (eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int,
|
159
|
* int, java.lang.String, java.lang.String)
|
160
|
*/
|
161
|
@Override
|
162
|
public String getOccurrenceServiceRequestParameterString(List<SpecimenOrObservationBase> specimensOrObersvations,
|
163
|
Map<SpecimenOrObservationType, Color> specimenOrObservationTypeColors,
|
164
|
Boolean doReturnImage, Integer width, Integer height, String bbox, String backLayer) {
|
165
|
|
166
|
List<Point> fieldUnitPoints = new ArrayList<Point>();
|
167
|
List<Point> derivedUnitPoints = new ArrayList<Point>();
|
168
|
|
169
|
IndividualsAssociation individualsAssociation;
|
170
|
DerivedUnit derivedUnit;
|
171
|
|
172
|
for (SpecimenOrObservationBase specimenOrObservationBase : specimensOrObersvations) {
|
173
|
SpecimenOrObservationBase<?> specimenOrObservation = occurrenceDao
|
174
|
.load(specimenOrObservationBase.getUuid());
|
175
|
|
176
|
if (specimenOrObservation instanceof FieldUnit) {
|
177
|
fieldUnitPoints.add(((FieldUnit) specimenOrObservation).getGatheringEvent()
|
178
|
.getExactLocation());
|
179
|
}
|
180
|
if (specimenOrObservation instanceof DerivedUnit) {
|
181
|
registerDerivedUnitLocations((DerivedUnit) specimenOrObservation, derivedUnitPoints);
|
182
|
}
|
183
|
}
|
184
|
|
185
|
return EditGeoServiceUtilities.getOccurrenceServiceRequestParameterString(fieldUnitPoints,
|
186
|
derivedUnitPoints, specimenOrObservationTypeColors, doReturnImage, width, height, bbox, backLayer);
|
187
|
|
188
|
}
|
189
|
|
190
|
/**
|
191
|
* @param derivedUnit
|
192
|
* @param derivedUnitPoints
|
193
|
*/
|
194
|
private void registerDerivedUnitLocations(DerivedUnit derivedUnit, List<Point> derivedUnitPoints) {
|
195
|
|
196
|
Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
|
197
|
if (originals != null) {
|
198
|
for (SpecimenOrObservationBase original : originals) {
|
199
|
if (original instanceof FieldUnit) {
|
200
|
if (((FieldUnit) original).getGatheringEvent() != null) {
|
201
|
Point point = ((FieldUnit) original).getGatheringEvent().getExactLocation();
|
202
|
if (point != null) {
|
203
|
// FIXME: remove next statement after
|
204
|
// DerivedUnitFacade or ABCD import is fixed
|
205
|
if (point.getLatitude() == 0.0 && point.getLongitude() == 0.0) {
|
206
|
continue;
|
207
|
}
|
208
|
derivedUnitPoints.add(point);
|
209
|
}
|
210
|
}
|
211
|
} else {
|
212
|
registerDerivedUnitLocations((DerivedUnit) original, derivedUnitPoints);
|
213
|
}
|
214
|
}
|
215
|
}
|
216
|
|
217
|
}
|
218
|
|
219
|
/*
|
220
|
* (non-Javadoc)
|
221
|
*
|
222
|
* @see
|
223
|
* eu.etaxonomy.cdm.ext.geo.IEditGeoService#setMapping(eu.etaxonomy.cdm.
|
224
|
* model.location.NamedArea, eu.etaxonomy.cdm.ext.geo.GeoServiceArea)
|
225
|
*/
|
226
|
@Override
|
227
|
public void setMapping(NamedArea area, GeoServiceArea geoServiceArea) {
|
228
|
areaMapping.set(area, geoServiceArea);
|
229
|
|
230
|
}
|
231
|
|
232
|
|
233
|
/* (non-Javadoc)
|
234
|
* @see eu.etaxonomy.cdm.ext.geo.IEditGeoService#mapShapeFileToNamedAreas(java.io.Reader, java.util.List, java.lang.String, eu.etaxonomy.cdm.model.common.TermVocabulary)
|
235
|
*/
|
236
|
@Override
|
237
|
@Transactional(readOnly=false)
|
238
|
public Map<NamedArea, String> mapShapeFileToNamedAreas(Reader csvReader, List<String> idSearchFields, String wmsLayerName, UUID areaVocabularyUuid) throws IOException {
|
239
|
TermVocabulary<NamedArea> areaVocabulary = vocabDao.load(areaVocabularyUuid);
|
240
|
ShpAttributesToNamedAreaMapper mapper = new ShpAttributesToNamedAreaMapper(areaVocabulary, areaMapping);
|
241
|
Map<NamedArea, String> resultMap = mapper.readCsv(csvReader, idSearchFields, wmsLayerName);
|
242
|
vocabDao.saveOrUpdate(areaVocabulary);
|
243
|
return resultMap;
|
244
|
}
|
245
|
|
246
|
}
|