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.util.ArrayList;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
|
19
|
import org.apache.log4j.Logger;
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
21
|
import org.springframework.stereotype.Service;
|
22
|
import org.springframework.transaction.annotation.Transactional;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.Language;
|
25
|
import eu.etaxonomy.cdm.model.description.Distribution;
|
26
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27
|
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
|
28
|
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
29
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
30
|
import eu.etaxonomy.cdm.model.location.Point;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnitBase;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.FieldObservation;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
34
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
35
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
36
|
import eu.etaxonomy.cdm.persistence.dao.description.IDescriptionDao;
|
37
|
import eu.etaxonomy.cdm.persistence.dao.occurrence.IOccurrenceDao;
|
38
|
|
39
|
/**
|
40
|
* @author a.kohlbecker
|
41
|
* @date 18.06.2009
|
42
|
*
|
43
|
*/
|
44
|
@Service
|
45
|
@Transactional(readOnly=true)
|
46
|
public class EditGeoService implements IEditGeoService{
|
47
|
public static final Logger logger = Logger.getLogger(EditGeoService.class);
|
48
|
|
49
|
private static final String DEFAULT_BACK_LAYER = "tdwg4";
|
50
|
|
51
|
@Autowired
|
52
|
private IDescriptionDao dao;
|
53
|
|
54
|
private IDefinedTermDao termDao;
|
55
|
|
56
|
@Autowired
|
57
|
public void setTermDao(IDefinedTermDao termDao) {
|
58
|
this.termDao = termDao;
|
59
|
EditGeoServiceUtilities.setTermDao(termDao);
|
60
|
}
|
61
|
|
62
|
@Autowired
|
63
|
private IOccurrenceDao occurrenceDao;
|
64
|
|
65
|
|
66
|
private Set<Feature> getDistributionFeatures() {
|
67
|
Set<Feature> distributionFeature = new HashSet<Feature>();
|
68
|
Feature feature = (Feature) termDao.findByUuid(Feature.DISTRIBUTION().getUuid());
|
69
|
distributionFeature.add(feature);
|
70
|
return distributionFeature;
|
71
|
}
|
72
|
|
73
|
/* (non-Javadoc)
|
74
|
* @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(java.util.List, java.util.Map, int, int, java.lang.String, java.lang.String, java.util.List)
|
75
|
*/
|
76
|
public String getDistributionServiceRequestParameterString(
|
77
|
List<TaxonDescription> taxonDescriptions,
|
78
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
|
79
|
int width, int height, String bbox, String backLayer,
|
80
|
List<Language> langs) {
|
81
|
Set<Distribution> distributions = new HashSet<Distribution>();
|
82
|
for(TaxonDescription taxonDescription : taxonDescriptions){
|
83
|
List<Distribution> result = (List)dao.getDescriptionElements(taxonDescription, getDistributionFeatures(), Distribution.class, null, null, null);
|
84
|
distributions.addAll(result);
|
85
|
}
|
86
|
|
87
|
if(backLayer == null){
|
88
|
backLayer = DEFAULT_BACK_LAYER;
|
89
|
}
|
90
|
String uriParams = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distributions, presenceAbsenceTermColors, width, height, bbox, backLayer, null, langs);
|
91
|
|
92
|
return uriParams;
|
93
|
}
|
94
|
|
95
|
/* (non-Javadoc)
|
96
|
* @see eu.etaxonomy.cdm.ext.IEditGeoService#getEditGeoServiceUrlParameterString(eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int, int, java.lang.String, java.lang.String)
|
97
|
*/
|
98
|
public String getDistributionServiceRequestParameterString(
|
99
|
TaxonDescription taxonDescription,
|
100
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors,
|
101
|
int width, int height, String bbox, String backLayer,
|
102
|
List<Language> langs) {
|
103
|
|
104
|
List<TaxonDescription> taxonDescriptions = new ArrayList<TaxonDescription>();
|
105
|
taxonDescriptions.add(taxonDescription);
|
106
|
|
107
|
return getDistributionServiceRequestParameterString(taxonDescriptions, presenceAbsenceTermColors, width, height, bbox, backLayer, langs);
|
108
|
}
|
109
|
|
110
|
/* (non-Javadoc)
|
111
|
* @see eu.etaxonomy.cdm.api.service.IEditGeoService#getEditGeoServiceUrlParameterString(eu.etaxonomy.cdm.model.taxon.Taxon, java.util.Map, int, int, java.lang.String, java.lang.String)
|
112
|
*/
|
113
|
public String getDistributionServiceRequestParameterString(Taxon taxon,
|
114
|
Map<PresenceAbsenceTermBase<?>, Color> presenceAbsenceTermColors, int width, int height, String bbox,
|
115
|
String backLayer,
|
116
|
List<Language> langs) {
|
117
|
|
118
|
List<TaxonDescription> taxonDescriptions = dao.getTaxonDescriptions(taxon, null, null, null, null, null);
|
119
|
|
120
|
Set<Distribution> distCollection = new HashSet<Distribution>();
|
121
|
// get descriptions elements for each description
|
122
|
for (TaxonDescription td : taxonDescriptions) {
|
123
|
List<Distribution> dists = (List)dao.getDescriptionElements(td, getDistributionFeatures(), Distribution.class, null, null, null);
|
124
|
distCollection.addAll(dists);
|
125
|
}
|
126
|
// generate the uri parameter string
|
127
|
if(backLayer == null){
|
128
|
backLayer = DEFAULT_BACK_LAYER;
|
129
|
}
|
130
|
String uriParams = EditGeoServiceUtilities.getDistributionServiceRequestParameterString(distCollection,
|
131
|
presenceAbsenceTermColors, width, height, bbox, backLayer, null, langs);
|
132
|
|
133
|
return uriParams;
|
134
|
}
|
135
|
|
136
|
/* (non-Javadoc)
|
137
|
* @see eu.etaxonomy.cdm.ext.geo.IEditGeoService#getOccurrenceServiceRequestParameterString(eu.etaxonomy.cdm.model.description.TaxonDescription, java.util.Map, int, int, java.lang.String, java.lang.String)
|
138
|
*/
|
139
|
@Override
|
140
|
public String getOccurrenceServiceRequestParameterString(
|
141
|
List<SpecimenOrObservationBase> specimensOrObersvations,
|
142
|
Map<Class<? extends SpecimenOrObservationBase>, Color> specimenOrObservationTypeColors, Boolean doReturnImage,
|
143
|
Integer width, Integer height, String bbox, String backLayer) {
|
144
|
|
145
|
List<Point> fieldObservationPoints = new ArrayList<Point>();
|
146
|
List<Point> derivedUnitPoints = new ArrayList<Point>();
|
147
|
|
148
|
IndividualsAssociation individualsAssociation;
|
149
|
DerivedUnitBase derivedUnit;
|
150
|
|
151
|
for(SpecimenOrObservationBase specimenOrObservationBase : specimensOrObersvations){
|
152
|
SpecimenOrObservationBase<?> specimenOrObservation = occurrenceDao.load(specimenOrObservationBase.getUuid());
|
153
|
|
154
|
if(specimenOrObservation instanceof FieldObservation){
|
155
|
fieldObservationPoints.add(((FieldObservation)specimenOrObservation).getGatheringEvent().getExactLocation());
|
156
|
}
|
157
|
if(specimenOrObservation instanceof DerivedUnitBase<?>){
|
158
|
registerDerivedUnitLocations((DerivedUnitBase)specimenOrObservation, derivedUnitPoints);
|
159
|
}
|
160
|
}
|
161
|
|
162
|
return EditGeoServiceUtilities.getOccurrenceServiceRequestParameterString(
|
163
|
fieldObservationPoints, derivedUnitPoints,
|
164
|
specimenOrObservationTypeColors, doReturnImage , width,
|
165
|
height, bbox, backLayer);
|
166
|
|
167
|
}
|
168
|
|
169
|
/**
|
170
|
* @param derivedUnit
|
171
|
* @param derivedUnitPoints
|
172
|
*/
|
173
|
private void registerDerivedUnitLocations(DerivedUnitBase<?> derivedUnit,
|
174
|
List<Point> derivedUnitPoints) {
|
175
|
|
176
|
Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
|
177
|
if(originals != null){
|
178
|
for (SpecimenOrObservationBase original : originals) {
|
179
|
if (original instanceof FieldObservation) {
|
180
|
Point point = ((FieldObservation) original).getGatheringEvent().getExactLocation();
|
181
|
if(point != null){
|
182
|
//FIXME: remove next statement after DerivedUnitFacade or ABCD import is fixed
|
183
|
if(point.getLatitude() == 0.0 && point.getLongitude() == 0.0){
|
184
|
continue;
|
185
|
}
|
186
|
derivedUnitPoints.add(point);
|
187
|
}
|
188
|
} else {
|
189
|
registerDerivedUnitLocations((DerivedUnitBase) original, derivedUnitPoints);
|
190
|
}
|
191
|
}
|
192
|
}
|
193
|
|
194
|
}
|
195
|
|
196
|
}
|