Revision 84a5c63d
Added by Andreas Müller over 11 years ago
app-import/src/main/java/eu/etaxonomy/cdm/io/algaterra/AlgaTerraSpecimenImport.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.cdm.io.algaterra; |
11 | 11 |
|
12 |
import java.net.URI; |
|
13 |
import java.sql.Date; |
|
14 | 12 |
import java.sql.ResultSet; |
15 | 13 |
import java.sql.SQLException; |
16 | 14 |
import java.util.HashMap; |
... | ... | |
22 | 20 |
import org.apache.commons.lang.StringUtils; |
23 | 21 |
import org.apache.log4j.Logger; |
24 | 22 |
import org.springframework.stereotype.Component; |
25 |
import org.springframework.transaction.TransactionStatus; |
|
26 | 23 |
|
27 | 24 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade; |
28 | 25 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade.DerivedUnitType; |
29 | 26 |
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacadeNotSupportedException; |
30 | 27 |
import eu.etaxonomy.cdm.io.algaterra.validation.AlgaTerraSpecimenImportValidator; |
31 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase; |
|
32 | 28 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator; |
33 | 29 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState; |
34 | 30 |
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonImport; |
35 | 31 |
import eu.etaxonomy.cdm.io.common.IOValidator; |
36 | 32 |
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner; |
37 |
import eu.etaxonomy.cdm.io.common.Source; |
|
38 |
import eu.etaxonomy.cdm.model.agent.Team; |
|
39 | 33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
40 | 34 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
41 | 35 |
import eu.etaxonomy.cdm.model.common.Language; |
42 | 36 |
import eu.etaxonomy.cdm.model.common.Marker; |
43 | 37 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
44 |
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; |
|
45 | 38 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
46 |
import eu.etaxonomy.cdm.model.common.TimePeriod; |
|
47 | 39 |
import eu.etaxonomy.cdm.model.description.CategoricalData; |
48 | 40 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
49 | 41 |
import eu.etaxonomy.cdm.model.description.Feature; |
... | ... | |
51 | 43 |
import eu.etaxonomy.cdm.model.description.MeasurementUnit; |
52 | 44 |
import eu.etaxonomy.cdm.model.description.Modifier; |
53 | 45 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
54 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
55 | 46 |
import eu.etaxonomy.cdm.model.description.State; |
56 | 47 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasure; |
57 | 48 |
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue; |
58 | 49 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
59 | 50 |
import eu.etaxonomy.cdm.model.description.TextData; |
60 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
|
61 |
import eu.etaxonomy.cdm.model.location.Point; |
|
62 |
import eu.etaxonomy.cdm.model.location.ReferenceSystem; |
|
63 |
import eu.etaxonomy.cdm.model.location.TdwgArea; |
|
64 |
import eu.etaxonomy.cdm.model.location.WaterbodyOrCountry; |
|
65 | 51 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
66 | 52 |
import eu.etaxonomy.cdm.model.name.Rank; |
67 | 53 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
... | ... | |
73 | 59 |
|
74 | 60 |
/** |
75 | 61 |
* @author a.mueller |
76 |
* @created 20.03.2008 |
|
77 |
* @version 1.0 |
|
62 |
* @created 01.09.2012 |
|
78 | 63 |
*/ |
79 | 64 |
@Component |
80 |
public class AlgaTerraSpecimenImport extends BerlinModelImportBase {
|
|
65 |
public class AlgaTerraSpecimenImport extends AlgaTerraSpecimenImportBase {
|
|
81 | 66 |
private static final Logger logger = Logger.getLogger(AlgaTerraSpecimenImport.class); |
82 | 67 |
|
83 |
public static final String ECO_FACT_NAMESPACE = "EcoFact"; |
|
84 |
public static final String TERMS_NAMESPACE = "ALGA_TERRA_TERMS"; |
|
85 |
|
|
86 |
//TODO move to transformrer |
|
87 |
final static UUID uuidMarkerAlkalinity = UUID.fromString("e52d0ea2-0c1f-4d95-ae6d-e21ab317c594"); |
|
88 |
final static UUID uuidRefSystemGps = UUID.fromString("c23e4928-c137-4e4a-b6ab-b430da3d0b94"); |
|
89 |
final static UUID uuidFeatureSpecimenCommunity = UUID.fromString("3ff5b1ab-3999-4b5a-b8f7-01fd2f6c12c7"); |
|
90 |
final static UUID uuidFeatureAdditionalData = UUID.fromString("0ac82ab8-2c2b-4953-98eb-a9f718eb9c57"); |
|
91 |
final static UUID uuidFeatureHabitatExplanation = UUID.fromString("6fe32295-61a3-44fc-9fcf-a85790ea888f"); |
|
92 |
|
|
93 |
final static UUID uuidVocAlgaTerraClimate = UUID.fromString("b0a677c6-8bb6-43f4-b1b8-fc377a10feb5"); |
|
94 |
final static UUID uuidVocAlgaTerraHabitat = UUID.fromString("06f30114-e19c-4e7d-a8e5-5488c41fcbc5"); |
|
95 |
final static UUID uuidVocAlgaTerraLifeForm = UUID.fromString("3c0b194e-809c-4b42-9498-6ff034066ed7"); |
|
96 |
|
|
97 |
final static UUID uuidFeatureAlgaTerraClimate = UUID.fromString("8754674c-9ab9-4f28-95f1-91eeee2314ee"); |
|
98 |
final static UUID uuidFeatureAlgaTerraHabitat = UUID.fromString("7def3fc2-cdc5-4739-8e13-62edbd053415"); |
|
99 |
final static UUID uuidFeatureAlgaTerraLifeForm = UUID.fromString("9b657901-1b0d-4a2a-8d21-dd8c1413e2e6"); |
|
100 |
|
|
101 |
final static UUID uuidVocParameter = UUID.fromString("45888b40-5bbb-4293-aa1e-02479796cd7c"); |
|
102 |
final static UUID uuidStatMeasureSingleValue = UUID.fromString("eb4c3d98-4d4b-4c37-8eb4-17315ce79920"); |
|
103 |
final static UUID uuidMeasurementValueModifier = UUID.fromString("0218a7a3-f6c0-4d06-a4f8-6b50b73aef5e"); |
|
104 |
|
|
105 |
final static UUID uuidModifierLowerThan = UUID.fromString("2b500085-6bef-4003-b6ea-e0ad0237d79d"); |
|
106 |
final static UUID uuidModifierGreaterThan = UUID.fromString("828df49d-c745-48f7-b083-0ada43356c34"); |
|
107 | 68 |
|
108 | 69 |
private static int modCount = 5000; |
109 | 70 |
private static final String pluralString = "specimen and observation"; |
... | ... | |
135 | 96 |
*/ |
136 | 97 |
@Override |
137 | 98 |
protected String getRecordQuery(BerlinModelImportConfigurator config) { |
138 |
String strQuery = //DISTINCT because otherwise emOccurrenceSource creates multiple records for a single distribution
|
|
99 |
String strQuery = |
|
139 | 100 |
" SELECT PTaxon.RIdentifier as taxonId, Fact.FactId, Fact.RecordBasis, EcoFact.*, " + |
140 | 101 |
" tg.ID AS GazetteerId, tg.L2Code, tg.L3Code, tg.L4Code, tg.Country, tg.ISOCountry, " + |
141 | 102 |
" ec.UUID as climateUuid, eh.UUID as habitatUuid, elf.UUID as lifeFormUuid" + |
... | ... | |
198 | 159 |
//field observation |
199 | 160 |
handleSingleSpecimen(rs, facade, state); |
200 | 161 |
|
162 |
handleEcoFactSpecificSpecimen(rs,facade, state); |
|
163 |
|
|
201 | 164 |
state.setCurrentFieldObservationNotNew(false); |
202 | 165 |
|
203 | 166 |
//description element |
... | ... | |
232 | 195 |
|
233 | 196 |
|
234 | 197 |
|
198 |
private void handleEcoFactSpecificSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state) throws SQLException { |
|
199 |
|
|
200 |
Object alkalinityFlag = rs.getBoolean("AlkalinityFlag"); |
|
201 |
|
|
202 |
//alkalinity marker |
|
203 |
if (alkalinityFlag != null){ |
|
204 |
MarkerType alkalinityMarkerType = getMarkerType(state, uuidMarkerAlkalinity, "Alkalinity", "Alkalinity", null); |
|
205 |
boolean alkFlag = Boolean.valueOf(alkalinityFlag.toString()); |
|
206 |
Marker alkalinityMarker = Marker.NewInstance(alkalinityMarkerType, alkFlag); |
|
207 |
facade.getFieldObservation(true).addMarker(alkalinityMarker); |
|
208 |
} |
|
209 |
|
|
210 |
|
|
211 |
DescriptionBase<?> fieldDescription = getFieldObservationDescription(facade); |
|
235 | 212 |
|
236 |
/** |
|
237 |
* Creates the vocabularies and the features for Climate, Habitat and Lifeform |
|
238 |
* @param state |
|
239 |
* @throws SQLException |
|
240 |
*/ |
|
241 |
private void makeVocabulariesAndFeatures(AlgaTerraImportState state) throws SQLException { |
|
242 |
String abbrevLabel = null; |
|
243 |
URI uri = null; |
|
213 |
//habitat, ecology, community, etc. |
|
214 |
String habitat = rs.getString("HabitatExplanation"); |
|
244 | 215 |
|
245 |
if (! state.isSpecimenVocabulariesCreated()){ |
|
246 |
|
|
247 |
TransactionStatus txStatus = this.startTransaction(); |
|
216 |
if (isNotBlank(habitat)){ |
|
217 |
Feature habitatExplanation = getFeature(state, uuidFeatureHabitatExplanation, "Habitat Explanation", "HabitatExplanation", null, null); |
|
218 |
TextData textData = TextData.NewInstance(habitatExplanation); |
|
219 |
textData.putText(Language.DEFAULT(), habitat); |
|
220 |
fieldDescription.addElement(textData); |
|
221 |
} |
|
248 | 222 |
|
249 |
boolean isOrdered = true; |
|
250 |
OrderedTermVocabulary<State> climateVoc = (OrderedTermVocabulary)getVocabulary(uuidVocAlgaTerraClimate, "Climate", "Climate", abbrevLabel, uri, isOrdered, null); |
|
251 |
OrderedTermVocabulary<State> habitatVoc = (OrderedTermVocabulary)getVocabulary(uuidVocAlgaTerraHabitat, "Habitat", "Habitat", abbrevLabel, uri, isOrdered, null); |
|
252 |
OrderedTermVocabulary<State> lifeformVoc = (OrderedTermVocabulary)getVocabulary(uuidVocAlgaTerraLifeForm, "Lifeform", "Lifeform", abbrevLabel, uri, isOrdered, null); |
|
253 |
|
|
254 |
|
|
255 |
Feature feature = getFeature(state, uuidFeatureAlgaTerraClimate, "Climate","Climate", null, null); |
|
256 |
feature.setSupportsCategoricalData(true); |
|
257 |
|
|
258 |
feature = getFeature(state, uuidFeatureAlgaTerraLifeForm, "LifeForm","LifeForm", null, null); |
|
259 |
feature.setSupportsCategoricalData(true); |
|
260 |
|
|
261 |
feature = Feature.HABITAT(); |
|
262 |
feature.setSupportsCategoricalData(true); |
|
263 |
getTermService().saveOrUpdate(feature); |
|
264 |
|
|
265 |
Source source = state.getAlgaTerraConfigurator().getSource(); |
|
266 |
|
|
267 |
String climateSql = "SELECT * FROM EcoClimate"; |
|
268 |
ResultSet rs = source.getResultSet(climateSql); |
|
269 |
while (rs.next()){ |
|
270 |
String climate = rs.getString("Climate"); |
|
271 |
String description = rs.getString("Description"); |
|
272 |
Integer id = rs.getInt("ClimateId"); |
|
273 |
UUID uuid = UUID.fromString(rs.getString("UUID")); |
|
274 |
State stateTerm = getStateTerm(state, uuid, climate, description, null, climateVoc); |
|
275 |
addOriginalSource(stateTerm, id.toString(), "EcoClimate", state.getTransactionalSourceReference()); |
|
276 |
getTermService().saveOrUpdate(stateTerm); |
|
277 |
} |
|
278 |
|
|
279 |
String habitatSql = "SELECT * FROM EcoHabitat"; |
|
280 |
rs = source.getResultSet(habitatSql); |
|
281 |
while (rs.next()){ |
|
282 |
String habitat = rs.getString("Habitat"); |
|
283 |
String description = rs.getString("Description"); |
|
284 |
Integer id = rs.getInt("HabitatId"); |
|
285 |
UUID uuid = UUID.fromString(rs.getString("UUID")); |
|
286 |
State stateTerm = getStateTerm(state, uuid, habitat, description, null, habitatVoc); |
|
287 |
addOriginalSource(stateTerm, id.toString(), "EcoHabitat", state.getTransactionalSourceReference()); |
|
288 |
getTermService().saveOrUpdate(stateTerm); |
|
289 |
} |
|
290 |
|
|
291 |
String lifeformSql = "SELECT * FROM EcoLifeForm"; |
|
292 |
rs = source.getResultSet(lifeformSql); |
|
293 |
while (rs.next()){ |
|
294 |
String lifeform = rs.getString("LifeForm"); |
|
295 |
String description = rs.getString("Description"); |
|
296 |
Integer id = rs.getInt("LifeFormId"); |
|
297 |
UUID uuid = UUID.fromString(rs.getString("UUID")); |
|
298 |
State stateTerm = getStateTerm(state, uuid, lifeform, description, null, lifeformVoc); |
|
299 |
addOriginalSource(stateTerm, id.toString(), "EcoLifeForm", state.getTransactionalSourceReference()); |
|
300 |
getTermService().saveOrUpdate(stateTerm); |
|
301 |
} |
|
302 |
|
|
303 |
this.commitTransaction(txStatus); |
|
304 |
|
|
305 |
state.setSpecimenVocabulariesCreated(true); |
|
223 |
String community = rs.getString("Comunity"); |
|
224 |
if (isNotBlank(community)){ |
|
225 |
Feature communityFeature = getFeature(state, uuidFeatureSpecimenCommunity, "Community", "The community of a specimen (e.g. other algae in the same sample)", null, null); |
|
226 |
TextData textData = TextData.NewInstance(communityFeature); |
|
227 |
textData.putText(Language.DEFAULT(), community); |
|
228 |
fieldDescription.addElement(textData); |
|
229 |
} |
|
230 |
|
|
231 |
String additionalData = rs.getString("AdditionalData"); |
|
232 |
if (isNotBlank(additionalData)){ //or handle it as Annotation ?? |
|
233 |
Feature additionalDataFeature = getFeature(state, uuidFeatureAdditionalData, "Additional Data", "Additional Data", null, null); |
|
234 |
TextData textData = TextData.NewInstance(additionalDataFeature); |
|
235 |
textData.putText(Language.DEFAULT(), additionalData); |
|
236 |
fieldDescription.addElement(textData); |
|
237 |
} |
|
238 |
|
|
239 |
String climateUuid = rs.getString("climateUuid"); |
|
240 |
String habitatUuid = rs.getString("habitatUuid"); |
|
241 |
String lifeFormUuid = rs.getString("lifeFormUuid"); |
|
242 |
|
|
243 |
addCategoricalValue(state, fieldDescription, climateUuid, uuidFeatureAlgaTerraClimate); |
|
244 |
addCategoricalValue(state, fieldDescription, habitatUuid, Feature.HABITAT().getUuid()); |
|
245 |
addCategoricalValue(state, fieldDescription, lifeFormUuid, uuidFeatureAlgaTerraLifeForm); |
|
246 |
|
|
247 |
|
|
248 |
//collection |
|
249 |
String voucher = rs.getString("Voucher"); |
|
250 |
if (StringUtils.isNotBlank(voucher)){ |
|
251 |
facade.setAccessionNumber(voucher); |
|
306 | 252 |
} |
307 | 253 |
|
254 |
//parameters |
|
255 |
makeParameter(state, rs, getFieldObservationDescription(facade)); |
|
256 |
|
|
308 | 257 |
} |
309 | 258 |
|
310 | 259 |
|
311 | 260 |
|
312 |
private void handleSingleSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state) throws SQLException { |
|
313 |
//FIXME missing fields #3084, #3085, #3080 |
|
314 |
try { |
|
315 |
Object alkalinityFlag = rs.getBoolean("AlkalinityFlag"); |
|
316 |
|
|
317 |
String locality = rs.getString("Locality"); |
|
318 |
Double latitude = nullSafeDouble(rs, "Latitude"); |
|
319 |
Double longitude = nullSafeDouble(rs, "Longitude"); |
|
320 |
Integer errorRadius = nullSafeInt(rs,"Prec"); |
|
321 |
String geoCodeMethod = rs.getString("GeoCodeMethod"); |
|
322 |
|
|
323 |
Integer altitude = nullSafeInt(rs, "Altitude"); |
|
324 |
Integer lowerAltitude = nullSafeInt(rs,"AltitudeLowerValue"); |
|
325 |
String altitudeUnit = rs.getString("AltitudeUnit"); |
|
326 |
Double depth = nullSafeDouble(rs, "Depth"); |
|
327 |
Double depthLow = nullSafeDouble(rs, "DepthLow"); |
|
328 |
|
|
329 |
String collectorsNumber = rs.getString("CollectorsNumber"); |
|
330 |
Date collectionDateStart = rs.getDate("CollectionDate"); |
|
331 |
Date collectionDateEnd = rs.getDate("CollectionDateEnd"); |
|
332 |
|
|
333 |
String climateUuid = rs.getString("climateUuid"); |
|
334 |
String habitatUuid = rs.getString("habitatUuid"); |
|
335 |
String lifeFormUuid = rs.getString("lifeFormUuid"); |
|
336 |
|
|
337 |
String habitat = rs.getString("HabitatExplanation"); |
|
338 |
String community = rs.getString("Comunity"); |
|
339 |
String additionalData = rs.getString("AdditionalData"); |
|
340 |
|
|
341 |
|
|
342 |
|
|
343 |
FieldObservation fieldObservation = facade.getFieldObservation(true); |
|
344 |
|
|
345 |
//alkalinity marker |
|
346 |
if (alkalinityFlag != null){ |
|
347 |
MarkerType alkalinityMarkerType = getMarkerType(state, uuidMarkerAlkalinity, "Alkalinity", "Alkalinity", null); |
|
348 |
boolean alkFlag = Boolean.valueOf(alkalinityFlag.toString()); |
|
349 |
Marker alkalinityMarker = Marker.NewInstance(alkalinityMarkerType, alkFlag); |
|
350 |
fieldObservation.addMarker(alkalinityMarker); |
|
351 |
} |
|
352 |
|
|
353 |
//location |
|
354 |
facade.setLocality(locality); |
|
355 |
|
|
356 |
//exact location |
|
357 |
ReferenceSystem referenceSystem = makeRefrenceSystem(geoCodeMethod, state); |
|
358 |
Point exactLocation = Point.NewInstance(longitude, latitude, referenceSystem, errorRadius); |
|
359 |
facade.setExactLocation(exactLocation); |
|
360 |
|
|
361 |
//altitude, depth |
|
362 |
if (StringUtils.isNotBlank(altitudeUnit) && ! altitudeUnit.trim().equalsIgnoreCase("m")){ |
|
363 |
logger.warn("Altitude unit is not [m] but: " + altitudeUnit); |
|
364 |
} |
|
365 |
if ( altitude != null){ |
|
366 |
if (lowerAltitude == null){ |
|
367 |
facade.setAbsoluteElevation(altitude); |
|
368 |
}else{ |
|
369 |
if (! facade.isEvenDistance(lowerAltitude, altitude)){ |
|
370 |
//FIXME there is a ticket for this |
|
371 |
altitude = altitude + 1; |
|
372 |
logger.warn("Current implementation of altitude does not allow uneven distances"); |
|
373 |
} |
|
374 |
facade.setAbsoluteElevationRange(lowerAltitude,altitude); |
|
375 |
} |
|
376 |
} |
|
377 |
if ( depth != null){ |
|
378 |
//FIXME needs model change to accept double #3072 |
|
379 |
Integer intDepth = depth.intValue(); |
|
380 |
if (depthLow == null){ |
|
381 |
facade.setDistanceToWaterSurface(intDepth); |
|
382 |
}else{ |
|
383 |
//FIXME range not yet in model #3074 |
|
384 |
facade.setDistanceToWaterSurface(intDepth); |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
//habitat, ecology, community, etc. |
|
389 |
DescriptionBase<?> fieldDescription = getFieldObservationDescription(facade); |
|
390 |
|
|
391 |
addCategoricalValue(state, fieldDescription, climateUuid, uuidFeatureAlgaTerraClimate); |
|
392 |
addCategoricalValue(state, fieldDescription, habitatUuid, Feature.HABITAT().getUuid()); |
|
393 |
addCategoricalValue(state, fieldDescription, lifeFormUuid, uuidFeatureAlgaTerraLifeForm); |
|
394 |
|
|
395 |
if (isNotBlank(habitat)){ |
|
396 |
Feature habitatExplanation = getFeature(state, uuidFeatureHabitatExplanation, "Habitat Explanation", "HabitatExplanation", null, null); |
|
397 |
TextData textData = TextData.NewInstance(habitatExplanation); |
|
398 |
textData.putText(Language.DEFAULT(), habitat); |
|
399 |
getFieldObservationDescription(facade).addElement(textData); |
|
400 |
} |
|
401 |
if (isNotBlank(community)){ |
|
402 |
Feature communityFeature = getFeature(state, uuidFeatureSpecimenCommunity, "Community", "The community of a specimen (e.g. other algae in the same sample)", null, null); |
|
403 |
TextData textData = TextData.NewInstance(communityFeature); |
|
404 |
textData.putText(Language.DEFAULT(), community); |
|
405 |
getFieldObservationDescription(facade).addElement(textData); |
|
406 |
} |
|
407 |
if (isNotBlank(additionalData)){ //or handle it as Annotation ?? |
|
408 |
Feature additionalDataFeature = getFeature(state, uuidFeatureAdditionalData, "Additional Data", "Additional Data", null, null); |
|
409 |
TextData textData = TextData.NewInstance(additionalDataFeature); |
|
410 |
textData.putText(Language.DEFAULT(), additionalData); |
|
411 |
getFieldObservationDescription(facade).addElement(textData); |
|
412 |
} |
|
413 |
|
|
414 |
//field |
|
415 |
facade.setFieldNumber(collectorsNumber); |
|
416 |
TimePeriod gatheringPeriod = TimePeriod.NewInstance(collectionDateStart, collectionDateEnd); |
|
417 |
facade.setGatheringPeriod(gatheringPeriod); |
|
418 |
handleCollectorTeam(state, facade, rs); |
|
419 |
|
|
420 |
//areas |
|
421 |
makeAreas(state, rs, facade); |
|
422 |
|
|
423 |
//parameters |
|
424 |
makeParameter(state, rs, getFieldObservationDescription(facade)); |
|
425 |
|
|
426 |
//collection |
|
427 |
String voucher = rs.getString("Voucher"); |
|
428 |
if (StringUtils.isNotBlank(voucher)){ |
|
429 |
facade.setAccessionNumber(voucher); |
|
430 |
} |
|
431 |
|
|
432 |
|
|
433 |
//notes |
|
434 |
//TODO is this an annotation on field observation or on the derived unit? |
|
435 |
|
|
436 |
//TODO id, created for fact + ecoFact |
|
437 |
// this.doIdCreatedUpdatedNotes(state, descriptionElement, rs, id, namespace); |
|
438 |
|
|
439 |
} catch (Exception e) { |
|
440 |
throw new RuntimeException(e); |
|
261 |
|
|
262 |
private void addCategoricalValue(AlgaTerraImportState importState, DescriptionBase description, String uuidTerm, UUID featureUuid) { |
|
263 |
if (uuidTerm != null){ |
|
264 |
State state = this.getStateTerm(importState, UUID.fromString(uuidTerm)); |
|
265 |
Feature feature = getFeature(importState, featureUuid); |
|
266 |
CategoricalData categoricalData = CategoricalData.NewInstance(state, feature); |
|
267 |
description.addElement(categoricalData); |
|
441 | 268 |
} |
442 |
|
|
443 | 269 |
} |
444 | 270 |
|
445 |
|
|
446 | 271 |
private void makeParameter(AlgaTerraImportState state, ResultSet rs, DescriptionBase<?> descriptionBase) throws SQLException { |
447 | 272 |
for (int i = 1; i <= 10; i++){ |
448 | 273 |
String valueStr = rs.getString(String.format("P%dValue", i)); |
... | ... | |
526 | 351 |
* @return |
527 | 352 |
*/ |
528 | 353 |
private MeasurementUnit getMeasurementUnit(AlgaTerraImportState state, String unitStr) { |
529 |
MeasurementUnit result = null; |
|
530 | 354 |
if (StringUtils.isNotBlank(unitStr)){ |
531 | 355 |
UUID uuidMeasurementUnitMgL = UUID.fromString("7ac302c5-3cbd-4334-964a-bf5d11eb9ead"); |
532 | 356 |
UUID uuidMeasurementUnitMolMol = UUID.fromString("96b78d78-3e49-448f-8100-e7779b71dd53"); |
... | ... | |
539 | 363 |
|
540 | 364 |
|
541 | 365 |
if (unitStr.equalsIgnoreCase("mg/L")){ |
542 |
return getMeasurementUnit(state, uuidMeasurementUnitMgL, unitStr, unitStr, unitStr, null);
|
|
366 |
return getMeasurementUnit(state, uuidMeasurementUnitMgL, unitStr, unitStr, unitStr, null); |
|
543 | 367 |
}else if (unitStr.equalsIgnoreCase("mol/mol")){ |
544 |
return result = getMeasurementUnit(state, uuidMeasurementUnitMolMol, unitStr, unitStr, unitStr, null);
|
|
368 |
return getMeasurementUnit(state, uuidMeasurementUnitMolMol, unitStr, unitStr, unitStr, null); |
|
545 | 369 |
}else if (unitStr.equalsIgnoreCase("\u00B5mol Si/L")){ //µmol Si/L |
546 | 370 |
return getMeasurementUnit(state, uuidMeasurementUnitMicroMolSiL, unitStr, unitStr, unitStr, null); |
547 | 371 |
}else if (unitStr.equalsIgnoreCase("\u00B5mol/L")){ //µmol/L |
... | ... | |
565 | 389 |
|
566 | 390 |
|
567 | 391 |
|
568 |
private void addCategoricalValue(AlgaTerraImportState importState, DescriptionBase description, String uuidTerm, UUID featureUuid) { |
|
569 |
if (uuidTerm != null){ |
|
570 |
State state = this.getStateTerm(importState, UUID.fromString(uuidTerm)); |
|
571 |
Feature feature = getFeature(importState, featureUuid); |
|
572 |
CategoricalData categoricalData = CategoricalData.NewInstance(state, feature); |
|
573 |
description.addElement(categoricalData); |
|
574 |
} |
|
575 |
} |
|
576 |
|
|
577 |
|
|
578 |
private void handleCollectorTeam(AlgaTerraImportState state, DerivedUnitFacade facade, ResultSet rs) throws SQLException { |
|
579 |
// FIXME parsen |
|
580 |
String collector = rs.getString("Collector"); |
|
581 |
Team team = Team.NewTitledInstance(collector, collector); |
|
582 |
facade.setCollector(team); |
|
583 |
|
|
584 |
|
|
585 |
|
|
586 |
} |
|
587 | 392 |
|
588 |
private void makeAreas(AlgaTerraImportState state, ResultSet rs, DerivedUnitFacade facade) throws SQLException { |
|
589 |
Object gazetteerId = rs.getObject("GazetteerId"); |
|
590 |
if (gazetteerId != null){ |
|
591 |
//TDWG |
|
592 |
NamedArea tdwgArea; |
|
593 |
String tdwg4 = rs.getString("L4Code"); |
|
594 |
if (isNotBlank(tdwg4)){ |
|
595 |
tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwg4); |
|
596 |
}else{ |
|
597 |
String tdwg3 = rs.getString("L3Code"); |
|
598 |
if (isNotBlank(tdwg3)){ |
|
599 |
tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(tdwg3); |
|
600 |
}else{ |
|
601 |
Integer tdwg2 = rs.getInt("L2Code"); |
|
602 |
tdwgArea = TdwgArea.getAreaByTdwgAbbreviation(String.valueOf(tdwg2)); |
|
603 |
} |
|
604 |
} |
|
605 |
if (tdwgArea == null){ |
|
606 |
logger.warn("TDWG area could not be defined for gazetterId: " + gazetteerId); |
|
607 |
}else{ |
|
608 |
facade.addCollectingArea(tdwgArea); |
|
609 |
} |
|
610 |
|
|
611 |
//Countries |
|
612 |
WaterbodyOrCountry country = null; |
|
613 |
String isoCountry = rs.getString("ISOCountry"); |
|
614 |
String countryStr = rs.getString("Country"); |
|
615 |
if (isNotBlank(isoCountry)){ |
|
616 |
country = WaterbodyOrCountry.getWaterbodyOrCountryByIso3166A2(isoCountry); |
|
617 |
}else if (isNotBlank(countryStr)){ |
|
618 |
logger.warn("Country exists but no ISO code"); |
|
619 |
} |
|
620 |
if (country == null){ |
|
621 |
logger.warn("Country does not exist for GazetteerID " + gazetteerId); |
|
622 |
}else{ |
|
623 |
facade.setCountry(country); |
|
624 |
} |
|
625 |
|
|
626 |
} |
|
627 |
|
|
628 |
//Waterbody |
|
629 |
WaterbodyOrCountry waterbody = null; |
|
630 |
String waterbodyStr = rs.getString("WaterBody"); |
|
631 |
if (isNotBlank(waterbodyStr)){ |
|
632 |
if (waterbodyStr.equals("Atlantic Ocean")){ |
|
633 |
waterbody = WaterbodyOrCountry.ATLANTICOCEAN(); |
|
634 |
}else{ |
|
635 |
logger.warn("Waterbody not recognized: " + waterbody); |
|
636 |
} |
|
637 |
if (waterbody != null){ |
|
638 |
facade.addCollectingArea(waterbody); |
|
639 |
} |
|
640 |
} |
|
641 |
|
|
642 |
|
|
643 |
//countries sub |
|
644 |
//TODO |
|
645 |
} |
|
646 |
|
|
647 |
private DescriptionBase getFieldObservationDescription(DerivedUnitFacade facade) { |
|
648 |
Set<DescriptionBase> descriptions = facade.innerFieldObservation().getDescriptions(); |
|
649 |
for (DescriptionBase desc : descriptions){ |
|
650 |
if (desc.isImageGallery() == false){ |
|
651 |
return desc; |
|
652 |
} |
|
653 |
} |
|
654 |
SpecimenDescription specDesc = SpecimenDescription.NewInstance(facade.innerFieldObservation()); |
|
655 |
descriptions.add(specDesc); |
|
656 |
return specDesc; |
|
657 |
} |
|
658 |
|
|
659 |
private ReferenceSystem makeRefrenceSystem(String geoCodeMethod, AlgaTerraImportState state) { |
|
660 |
if (StringUtils.isBlank(geoCodeMethod)){ |
|
661 |
return null; |
|
662 |
}else if(geoCodeMethod.startsWith("GPS")){ |
|
663 |
getReferenceSystem(state, uuidRefSystemGps, "GPS", "GPS", "GPS", ReferenceSystem.GOOGLE_EARTH().getVocabulary()); |
|
664 |
return ReferenceSystem.WGS84(); |
|
665 |
}else if(geoCodeMethod.startsWith("Google")){ |
|
666 |
return ReferenceSystem.GOOGLE_EARTH(); |
|
667 |
}else if(geoCodeMethod.startsWith("Map")){ |
|
668 |
logger.warn("Reference system " + geoCodeMethod + " not yet supported."); |
|
669 |
return null; |
|
670 |
}else if(geoCodeMethod.startsWith("WikiProjekt Georeferenzierung") || geoCodeMethod.startsWith("http://toolserver.org/~geohack/geohack.php") ){ |
|
671 |
return ReferenceSystem.WGS84(); |
|
672 |
}else { |
|
673 |
logger.warn("Reference system " + geoCodeMethod + " not yet supported."); |
|
674 |
return null; |
|
675 |
} |
|
676 |
} |
|
677 | 393 |
|
678 | 394 |
/** |
679 | 395 |
* @param state |
... | ... | |
768 | 484 |
//field observation map map |
769 | 485 |
nameSpace = AlgaTerraSpecimenImport.ECO_FACT_NAMESPACE; |
770 | 486 |
cdmClass = FieldObservation.class; |
771 |
idSet = taxonIdSet;
|
|
487 |
idSet = fieldObservationIdSet;
|
|
772 | 488 |
Map<String, FieldObservation> fieldObservationMap = (Map<String, FieldObservation>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
773 | 489 |
result.put(nameSpace, fieldObservationMap); |
774 | 490 |
|
775 | 491 |
//terms |
776 | 492 |
nameSpace = AlgaTerraSpecimenImport.TERMS_NAMESPACE; |
777 | 493 |
cdmClass = FieldObservation.class; |
778 |
idSet = taxonIdSet;
|
|
494 |
idSet = termsIdSet;
|
|
779 | 495 |
Map<String, DefinedTermBase> termMap = (Map<String, DefinedTermBase>)getCommonService().getSourcedObjectsByIdInSource(cdmClass, idSet, nameSpace); |
780 | 496 |
result.put(nameSpace, termMap); |
781 |
|
|
782 |
|
|
783 |
|
|
784 | 497 |
|
785 | 498 |
} catch (SQLException e) { |
786 | 499 |
throw new RuntimeException(e); |
Also available in: Unified diff
first implementation of Types in AlgaTerra