Unifiy name and taxon creation
[cdmlib-apps.git] / app-import / src / main / java / eu / etaxonomy / cdm / io / algaterra / AlgaTerraSpecimenImportBase.java
1 /**
2 * Copyright (C) 2007 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
10 package eu.etaxonomy.cdm.io.algaterra;
11
12 import java.net.URI;
13 import java.sql.Date;
14 import java.sql.ResultSet;
15 import java.sql.SQLException;
16 import java.util.HashMap;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.UUID;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.apache.log4j.Logger;
23 import org.springframework.transaction.TransactionStatus;
24
25 import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
26 import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase;
27 import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
28 import eu.etaxonomy.cdm.io.common.Source;
29 import eu.etaxonomy.cdm.io.common.TdwgAreaProvider;
30 import eu.etaxonomy.cdm.model.agent.Team;
31 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
32 import eu.etaxonomy.cdm.model.common.Annotation;
33 import eu.etaxonomy.cdm.model.common.AnnotationType;
34 import eu.etaxonomy.cdm.model.common.DefinedTerm;
35 import eu.etaxonomy.cdm.model.common.Language;
36 import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
37 import eu.etaxonomy.cdm.model.common.TermType;
38 import eu.etaxonomy.cdm.model.common.TermVocabulary;
39 import eu.etaxonomy.cdm.model.common.TimePeriod;
40 import eu.etaxonomy.cdm.model.description.DescriptionBase;
41 import eu.etaxonomy.cdm.model.description.Feature;
42 import eu.etaxonomy.cdm.model.description.SpecimenDescription;
43 import eu.etaxonomy.cdm.model.description.State;
44 import eu.etaxonomy.cdm.model.description.TaxonDescription;
45 import eu.etaxonomy.cdm.model.location.Country;
46 import eu.etaxonomy.cdm.model.location.NamedArea;
47 import eu.etaxonomy.cdm.model.location.NamedAreaType;
48 import eu.etaxonomy.cdm.model.location.Point;
49 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
50 import eu.etaxonomy.cdm.model.occurrence.Collection;
51 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
52 import eu.etaxonomy.cdm.model.reference.Reference;
53 import eu.etaxonomy.cdm.model.taxon.Taxon;
54
55 /**
56 * @author a.mueller
57 * @created 12.09.2012
58 */
59 public abstract class AlgaTerraSpecimenImportBase extends BerlinModelImportBase{
60 private static final Logger logger = Logger.getLogger(AlgaTerraSpecimenImportBase.class);
61
62 public static final String ECO_FACT_FIELD_OBSERVATION_NAMESPACE = "EcoFact_FieldObservation";
63 public static final String ECO_FACT_DERIVED_UNIT_NAMESPACE = "EcoFact_DerivedUnit";
64 public static final String TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE = "TypeSpecimen_FieldObservation";
65 public static final String TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE = "TypeSpecimen_DerivedUnit";
66 public static final String FACT_ECOLOGY_NAMESPACE = "Fact (Ecology)";
67
68
69 public static final String TERMS_NAMESPACE = "ALGA_TERRA_TERMS";
70
71 //TODO move to transformrer
72 final static UUID uuidMarkerAlkalinity = UUID.fromString("e52d0ea2-0c1f-4d95-ae6d-e21ab317c594");
73 final static UUID uuidRefSystemGps = UUID.fromString("c23e4928-c137-4e4a-b6ab-b430da3d0b94");
74 public final static UUID uuidFeatureSpecimenCommunity = UUID.fromString("3ff5b1ab-3999-4b5a-b8f7-01fd2f6c12c7");
75 public final static UUID uuidFeatureAdditionalData = UUID.fromString("0ac82ab8-2c2b-4953-98eb-a9f718eb9c57");
76 public final static UUID uuidFeatureHabitatExplanation = UUID.fromString("6fe32295-61a3-44fc-9fcf-a85790ea888f");
77
78 final static UUID uuidVocAlgaTerraClimate = UUID.fromString("b0a677c6-8bb6-43f4-b1b8-fc377a10feb5");
79 final static UUID uuidVocAlgaTerraHabitat = UUID.fromString("06f30114-e19c-4e7d-a8e5-5488c41fcbc5");
80 final static UUID uuidVocAlgaTerraLifeForm = UUID.fromString("3c0b194e-809c-4b42-9498-6ff034066ed7");
81
82 public final static UUID uuidFeatureAlgaTerraClimate = UUID.fromString("8754674c-9ab9-4f28-95f1-91eeee2314ee");
83 public final static UUID uuidFeatureAlgaTerraHabitat = UUID.fromString("7def3fc2-cdc5-4739-8e13-62edbd053415");
84 public final static UUID uuidFeatureAlgaTerraLifeForm = UUID.fromString("9b657901-1b0d-4a2a-8d21-dd8c1413e2e6");
85
86 final static UUID uuidVocParameter = UUID.fromString("45888b40-5bbb-4293-aa1e-02479796cd7c");
87 final static UUID uuidStatMeasureSingleValue = UUID.fromString("eb4c3d98-4d4b-4c37-8eb4-17315ce79920");
88 final static UUID uuidMeasurementValueModifier = UUID.fromString("0218a7a3-f6c0-4d06-a4f8-6b50b73aef5e");
89
90 final static UUID uuidModifierLowerThan = UUID.fromString("2b500085-6bef-4003-b6ea-e0ad0237d79d");
91 final static UUID uuidModifierGreaterThan = UUID.fromString("828df49d-c745-48f7-b083-0ada43356c34");
92
93 public AlgaTerraSpecimenImportBase(String tableName, String pluralString) {
94 super(tableName, pluralString);
95 }
96
97 /**
98 * Creates the vocabularies and the features for Climate, Habitat and Lifeform
99 * @param state
100 * @throws SQLException
101 */
102 protected void makeVocabulariesAndFeatures(AlgaTerraImportState state) throws SQLException {
103 String abbrevLabel = null;
104 URI uri = null;
105
106 if (! state.isSpecimenVocabulariesCreated()){
107
108 TransactionStatus txStatus = this.startTransaction();
109
110 boolean isOrdered = true;
111 State tmp = State.NewInstance();
112 OrderedTermVocabulary<State> climateVoc = (OrderedTermVocabulary<State>)getVocabulary(TermType.State, uuidVocAlgaTerraClimate, "Climate", "Climate", abbrevLabel, uri, isOrdered, tmp);
113 OrderedTermVocabulary<State> habitatVoc = (OrderedTermVocabulary<State>)getVocabulary(TermType.State, uuidVocAlgaTerraHabitat, "Habitat", "Habitat", abbrevLabel, uri, isOrdered, tmp);
114 OrderedTermVocabulary<State> lifeformVoc = (OrderedTermVocabulary<State>)getVocabulary(TermType.State, uuidVocAlgaTerraLifeForm, "Lifeform", "Lifeform", abbrevLabel, uri, isOrdered, tmp);
115
116 Feature feature = getFeature(state, uuidFeatureAlgaTerraClimate, "Climate","Climate", null, null);
117 feature.setSupportsCategoricalData(true);
118
119 feature = getFeature(state, uuidFeatureAlgaTerraLifeForm, "LifeForm","LifeForm", null, null);
120 feature.setSupportsCategoricalData(true);
121
122 feature = Feature.HABITAT();
123 feature.setSupportsCategoricalData(true);
124 getTermService().saveOrUpdate(feature);
125
126 Source source = state.getAlgaTerraConfigurator().getSource();
127
128 String climateSql = "SELECT * FROM EcoClimate";
129 ResultSet rs = source.getResultSet(climateSql);
130 while (rs.next()){
131 String climate = rs.getString("Climate");
132 String description = rs.getString("Description");
133 Integer id = rs.getInt("ClimateId");
134 UUID uuid = UUID.fromString(rs.getString("UUID"));
135 State stateTerm = getStateTerm(state, uuid, climate, description, null, climateVoc);
136 addOriginalSource(stateTerm, id.toString(), "EcoClimate", state.getTransactionalSourceReference());
137 getTermService().saveOrUpdate(stateTerm);
138 }
139
140 String habitatSql = "SELECT * FROM EcoHabitat";
141 rs = source.getResultSet(habitatSql);
142 while (rs.next()){
143 String habitat = rs.getString("Habitat");
144 String description = rs.getString("Description");
145 Integer id = rs.getInt("HabitatId");
146 UUID uuid = UUID.fromString(rs.getString("UUID"));
147 State stateTerm = getStateTerm(state, uuid, habitat, description, null, habitatVoc);
148 addOriginalSource(stateTerm, id.toString(), "EcoHabitat", state.getTransactionalSourceReference());
149 getTermService().saveOrUpdate(stateTerm);
150 }
151
152 String lifeformSql = "SELECT * FROM EcoLifeForm";
153 rs = source.getResultSet(lifeformSql);
154 while (rs.next()){
155 String lifeform = rs.getString("LifeForm");
156 String description = rs.getString("Description");
157 Integer id = rs.getInt("LifeFormId");
158 UUID uuid = UUID.fromString(rs.getString("UUID"));
159 State stateTerm = getStateTerm(state, uuid, lifeform, description, null, lifeformVoc);
160 addOriginalSource(stateTerm, id.toString(), "EcoLifeForm", state.getTransactionalSourceReference());
161 getTermService().saveOrUpdate(stateTerm);
162 }
163
164 //material category
165 TermVocabulary<DefinedTerm> materialCategoryVoc = getVocabulary(TermType.KindOfUnit, AlgaTerraImportTransformer.uuidKindOfUnitVoc, "Alga Terra Material Category", "Alga Terra Material Category", abbrevLabel, uri, false, DefinedTerm.NewKindOfUnitInstance(null, null, null));
166 getVocabularyService().save(materialCategoryVoc);
167
168 String materialSql = "SELECT * FROM MaterialCategory WHERE MaterialCategoryId <> 16 ";
169 rs = source.getResultSet(materialSql);
170 while (rs.next()){
171 Integer id = rs.getInt("MaterialCategoryId");
172 String category = rs.getString("MaterialCategory");
173 String description = rs.getString("Description");
174 UUID uuid = UUID.randomUUID();
175
176 DefinedTerm kindOfUnit = DefinedTerm.NewKindOfUnitInstance(description, category, null);
177 kindOfUnit.setUuid(uuid);
178 addOriginalSource(kindOfUnit, id.toString(), "MaterialCategory", state.getTransactionalSourceReference());
179 materialCategoryVoc.addTerm(kindOfUnit);
180 getTermService().saveOrUpdate(kindOfUnit);
181 materialCategoryMapping.put(id, uuid);
182 }
183
184 //areas
185 OrderedTermVocabulary<NamedArea> informalAreasVoc = (OrderedTermVocabulary<NamedArea>)getVocabulary(TermType.NamedArea, AlgaTerraImportTransformer.uuidNamedAreaVocAlgaTerraInformalAreas, "AlgaTerra Specific Areas", "AlgaTerra Specific Areas", abbrevLabel, uri, true, NamedArea.NewInstance());
186 getVocabularyService().save(informalAreasVoc);
187
188 String areaSql = "SELECT * FROM TDWGGazetteer WHERE subL4 = 1 ";
189 rs = source.getResultSet(areaSql);
190 while (rs.next()){
191 String l1Code = rs.getString("L1Code");
192 String l2Code = rs.getString("L2Code");
193 String l3Code = rs.getString("L3Code");
194 String l4Code = rs.getString("L4Code");
195 String gazetteer = rs.getString("Gazetteer");
196 Integer id = rs.getInt("ID");
197 String notes = rs.getString("Notes");
198 //TODO stable uuids
199 // UUID uuid = UUID.fromString(rs.getString("UUID"));
200 UUID uuid = UUID.randomUUID();
201 subL4Mapping.put(id, uuid);
202
203 String tdwgCode = (l4Code != null) ? l4Code : (l3Code != null) ? l3Code : (l2Code != null) ? l2Code : l1Code;
204
205 NamedArea tdwgArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(tdwgCode);
206 NamedArea newArea = getNamedArea(state, uuid ,gazetteer, gazetteer, null, null, null, informalAreasVoc, TermMatchMode.UUID_ONLY, null);
207 if (isNotBlank(notes)){
208 newArea.addAnnotation(Annotation.NewInstance(notes, AnnotationType.EDITORIAL(), Language.DEFAULT()));
209 }
210
211 addOriginalSource(newArea, id.toString(), "TDWGGazetteer", state.getTransactionalSourceReference());
212 getTermService().saveOrUpdate(newArea);
213 newArea.setPartOf(tdwgArea);
214 informalAreasVoc.addTerm(newArea);
215 }
216
217 this.commitTransaction(txStatus);
218
219 state.setSpecimenVocabulariesCreated(true);
220 }
221 }
222
223 //tmp
224 static Map<Integer, UUID> subL4Mapping = new HashMap<Integer, UUID>();
225 static Map<Integer, UUID> materialCategoryMapping = new HashMap<Integer, UUID>();
226
227 protected String getLocalityString(){
228 return "Locality";
229 }
230
231 protected void handleFieldObservationSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state, ResultSetPartitioner partitioner) throws SQLException {
232 //FIXME missing fields #3084, #3085, #3080
233 try {
234
235 Integer unitId = nullSafeInt(rs, "unitId");
236 String locality = rs.getString(getLocalityString());
237 Double latitude = nullSafeDouble(rs, "Latitude");
238 Double longitude = nullSafeDouble(rs, "Longitude");
239 Integer errorRadius = nullSafeInt(rs,"Prec");
240 String geoCodeMethod = rs.getString("GeoCodeMethod");
241
242 Integer altitude = nullSafeInt(rs, "Altitude");
243 Integer lowerAltitude = nullSafeInt(rs, "AltitudeLowerValue");
244 String altitudeUnit = rs.getString("AltitudeUnit");
245 Double depth = nullSafeDouble(rs, "Depth");
246 Double depthLow = nullSafeDouble(rs, "DepthLow");
247
248 String collectorsNumber = rs.getString("CollectorsNumber");
249 Date collectionDateStart = rs.getDate("CollectionDate");
250 Date collectionDateEnd = rs.getDate("CollectionDateEnd");
251
252 //location
253 facade.setLocality(locality);
254
255 //exact location
256 ReferenceSystem referenceSystem = makeRefrenceSystem(geoCodeMethod, state);
257 if (longitude != null || latitude != null || referenceSystem != null || errorRadius != null){
258 Point exactLocation = Point.NewInstance(longitude, latitude, referenceSystem, errorRadius);
259 facade.setExactLocation(exactLocation);
260 }
261
262 //altitude, depth
263 if (StringUtils.isNotBlank(altitudeUnit) && ! altitudeUnit.trim().equalsIgnoreCase("m")){
264 logger.warn("Altitude unit is not [m] but: " + altitudeUnit);
265 }
266 if ( altitude != null){
267 if (lowerAltitude == null){
268 facade.setAbsoluteElevation(altitude);
269 }else{
270 facade.setAbsoluteElevationRange(lowerAltitude,altitude);
271 }
272 }
273 if ( depth != null){
274 if (depthLow == null){
275 facade.setDistanceToWaterSurface(depth);
276 }else{
277 //TODO which direction is correct?
278 facade.setDistanceToWaterSurfaceRange(depth, depthLow);
279 }
280 }
281
282 //field
283 facade.setFieldNumber(collectorsNumber);
284 TimePeriod gatheringPeriod = TimePeriod.NewInstance(collectionDateStart, collectionDateEnd);
285 facade.setGatheringPeriod(gatheringPeriod);
286 handleCollectorTeam(state, facade, rs);
287
288 //areas
289 makeAreas(state, rs, facade);
290
291 //notes
292 //=> not required according to Henning
293
294 //id, created, updated, notes
295 if (unitId != null){
296 this.doIdCreatedUpdatedNotes(state, facade.innerFieldUnit(), rs, unitId, getFieldObservationNameSpace());
297 }else{
298 logger.warn("FieldObservation has no unitId: " + facade.innerFieldUnit() + ": " + getFieldObservationNameSpace());
299 }
300 } catch (Exception e) {
301 throw new RuntimeException(e);
302 }
303
304 }
305
306 protected void handleFirstDerivedSpecimen(ResultSet rs, DerivedUnitFacade facade, AlgaTerraImportState state, ResultSetPartitioner partitioner) throws SQLException {
307 Integer unitId = nullSafeInt(rs, "unitId");
308 Integer collectionFk = nullSafeInt(rs,"CollectionFk");
309 String label = rs.getString("Label");
310
311 //collection
312 if (collectionFk != null){
313 Collection subCollection = state.getRelatedObject(AlgaTerraCollectionImport.NAMESPACE_SUBCOLLECTION, String.valueOf(collectionFk), Collection.class);
314 if (subCollection != null){
315 facade.setCollection(subCollection);
316 }else{
317 Collection collection = state.getRelatedObject(AlgaTerraCollectionImport.NAMESPACE_COLLECTION, String.valueOf(collectionFk), Collection.class);
318 if (collection == null){
319 logger.warn("Collection for collectionFK " + collectionFk + " can not be found.");
320 }
321 facade.setCollection(collection);
322 }
323 }
324
325 //Label
326 if (isNotBlank(label)){
327 //TODO implement label #4218, #3090, #3084
328 logger.warn("Label not yet implemented for specimen, #4218, #3090, #3084");
329 }
330
331 //TODO id, created for fact + ecoFact
332 // this.doIdCreatedUpdatedNotes(state, descriptionElement, rs, id, namespace);
333 if (unitId != null){
334 this.doIdCreatedUpdatedNotes(state, facade.innerDerivedUnit(), rs, unitId, getDerivedUnitNameSpace());
335 }else{
336 logger.warn("Specimen has no unitId: " + facade.innerDerivedUnit() + ": " + getDerivedUnitNameSpace());
337 }
338 }
339
340
341
342 protected abstract String getDerivedUnitNameSpace();
343
344 protected abstract String getFieldObservationNameSpace();
345
346
347 protected DescriptionBase getFieldObservationDescription(DerivedUnitFacade facade) {
348 Set<DescriptionBase> descriptions = facade.innerFieldUnit().getDescriptions();
349 for (DescriptionBase desc : descriptions){
350 if (desc.isImageGallery() == false){
351 return desc;
352 }
353 }
354 SpecimenDescription specDesc = SpecimenDescription.NewInstance(facade.innerFieldUnit());
355 descriptions.add(specDesc);
356 return specDesc;
357 }
358
359
360 private void makeAreas(AlgaTerraImportState state, ResultSet rs, DerivedUnitFacade facade) throws SQLException {
361 Integer gazetteerId = nullSafeInt(rs, "GazetteerId");
362 if (gazetteerId != null){
363 //TDWG
364 NamedArea tdwgArea;
365 String tdwg4 = rs.getString("L4Code");
366 if (isNotBlank(tdwg4)){
367 tdwgArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(tdwg4);
368 }else{
369 String tdwg3 = rs.getString("L3Code");
370 if (isNotBlank(tdwg3)){
371 tdwgArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(tdwg3);
372 }else{
373 Number tdwg2D = nullSafeDouble(rs, "L2Code");
374 if (tdwg2D != null){
375 Integer tdwg2 = tdwg2D.intValue();
376 tdwgArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(String.valueOf(tdwg2));
377 }else{
378 Number tdwg1D = nullSafeDouble(rs, "L1Code");
379 if (tdwg1D != null){
380 Integer tdwg1 = tdwg1D.intValue();
381 tdwgArea = TdwgAreaProvider.getAreaByTdwgAbbreviation(String.valueOf(tdwg1));
382 }else{
383 tdwgArea = null;
384 }
385 }
386 }
387 }
388 if (tdwgArea == null){
389 logger.warn("TDWG area could not be defined for gazetterId: " + gazetteerId);
390 }else{
391 facade.addCollectingArea(tdwgArea);
392 }
393
394 //Countries
395 Country country = null;
396 String isoCountry = rs.getString("ISOCountry");
397 String countryStr = rs.getString("Country");
398 if (isNotBlank(isoCountry)){
399 country = Country.getCountryByIso3166A2(isoCountry);
400 }else if (isNotBlank(countryStr)){
401 logger.warn("Country exists but no ISO code");
402 }else{
403
404 }
405
406 NamedArea subL4Area = null;
407 Boolean subL4 = nullSafeBoolean(rs, "subL4");
408 if (subL4 != null && subL4.booleanValue() == true){
409 subL4Area = makeSubL4Area(state, gazetteerId);
410 if (subL4Area != null){
411 facade.addCollectingArea(subL4Area);
412 }else{
413 logger.warn("SubL4 area not found for gazetteerId: " + gazetteerId);
414 }
415 }
416
417 if (country == null ){
418 if (! gazetteerId.equals(40)){//special handling for Borneo, TDWG area is enough here as it matches exactly
419 if (subL4Area == null ){
420 logger.warn("Country does not exist and SubL4 could not be found for GazetteerID " + gazetteerId);
421 }else {
422 logger.info("Country could not be defined but subL4 area was added");
423 }
424 }
425 }else{
426 facade.setCountry(country);
427 }
428
429 }
430
431 //Waterbody
432 NamedArea waterbody = null;
433 String waterbodyStr = rs.getString("WaterBody");
434 if (isNotBlank(waterbodyStr)){
435 if (waterbodyStr.equals("Atlantic Ocean")){
436 waterbody = NamedArea.ATLANTICOCEAN();
437 }else if (waterbodyStr.equals("Pacific Ocean")){
438 waterbody = NamedArea.PACIFICOCEAN();
439 }else if (waterbodyStr.equals("Indian Ocean")){
440 waterbody = NamedArea.INDIANOCEAN();
441 }else if (waterbodyStr.equals("Arctic Ocean")){
442 waterbody = NamedArea.ARCTICOCEAN();
443 }else{
444 logger.warn("Waterbody not recognized: " + waterbody);
445 }
446 if (waterbody != null){
447 facade.addCollectingArea(waterbody);
448 }
449 }
450
451
452 //countries sub
453 //TODO -> SpecimenImport (not existing in TypeSpecimen)
454 }
455
456
457 private NamedArea makeSubL4Area(AlgaTerraImportState state, Integer gazetteerId) {
458 UUID uuid = subL4Mapping.get(gazetteerId);
459 NamedArea area = (NamedArea)getTermService().find(uuid);
460 if (area == null){
461 logger.warn("SubL4 area could not be found in repository");
462 }
463 return area;
464 }
465
466 private boolean handleMissingCountry(AlgaTerraImportState state, DerivedUnitFacade facade, Integer gazetteerId) {
467 NamedArea area = null;
468 if (gazetteerId != null){
469 if (gazetteerId.equals(42)){
470 area = getNamedArea(state, AlgaTerraImportTransformer.uuidNamedAreaBorneo, null, null, null, null, null);
471 }else if (gazetteerId.equals(1684)){
472 area = getNamedArea(state, AlgaTerraImportTransformer.uuidNamedAreaPatagonia, null, null, null, null, null);
473 }else if (gazetteerId.equals(2167)){
474 area = getNamedArea(state, AlgaTerraImportTransformer.uuidNamedAreaTierraDelFuego, null, null, null, null, null);
475 }
476 }
477 if (area != null){
478 facade.addCollectingArea(area);
479 return true;
480 }
481 return false;
482
483 }
484
485 protected SpecimenOrObservationType makeDerivedUnitType(String recordBasis) {
486 SpecimenOrObservationType result = null;
487 if (StringUtils.isBlank(recordBasis)){
488 result = SpecimenOrObservationType.DerivedUnit;
489 } else if (recordBasis.equalsIgnoreCase("FossileSpecimen")){
490 result = SpecimenOrObservationType.Fossil;
491 }else if (recordBasis.equalsIgnoreCase("HumanObservation")){
492 result = SpecimenOrObservationType.HumanObservation;
493 }else if (recordBasis.equalsIgnoreCase("Literature")){
494 //FIXME
495 logger.warn("Literature record basis not yet supported");
496 result = SpecimenOrObservationType.DerivedUnit;
497 }else if (recordBasis.equalsIgnoreCase("LivingSpecimen")){
498 result = SpecimenOrObservationType.LivingSpecimen;
499 }else if (recordBasis.equalsIgnoreCase("MachineObservation")){
500 result = SpecimenOrObservationType.MachineObservation;
501 }else if (recordBasis.equalsIgnoreCase("Observation")){
502 result = SpecimenOrObservationType.Observation;
503 }else if (recordBasis.equalsIgnoreCase("LivingCulture")){
504 //FIXME
505 logger.warn("LivingCulture record basis not yet supported");
506 result = SpecimenOrObservationType.DerivedUnit;
507 }else if (recordBasis.equalsIgnoreCase("PreservedSpecimen")){
508 result = SpecimenOrObservationType.PreservedSpecimen;
509 }
510 return result;
511 }
512
513
514 protected Feature makeFeature(SpecimenOrObservationType type, AlgaTerraImportState state) {
515 if (type.equals(SpecimenOrObservationType.DerivedUnit)){
516 return Feature.INDIVIDUALS_ASSOCIATION();
517 }else if (type.isFeatureObservation()){
518 return Feature.OBSERVATION();
519 }else if (type.isPreservedSpecimen()){
520 return Feature.SPECIMEN();
521 }else if (type.equals(SpecimenOrObservationType.LivingSpecimen)){
522 UUID uuid = AlgaTerraImportTransformer.uuidFeatureLivingSpecimen;
523 Feature feature = getFeature(state, uuid, "Living Specimen", "Living Specimen", null, Feature.SPECIMEN().getVocabulary());
524 if (feature == null){
525 logger.warn("Living Specimen Feature could not be created");
526 }
527 return feature;
528 }
529 logger.warn("No feature defined for derived unit type: " + type);
530 return null;
531 }
532
533 private ReferenceSystem makeRefrenceSystem(String geoCodeMethod, AlgaTerraImportState state) {
534 if (StringUtils.isBlank(geoCodeMethod)){
535 return null;
536 }else if(geoCodeMethod.startsWith("GPS")){
537 getReferenceSystem(state, uuidRefSystemGps, "GPS", "GPS", "GPS", ReferenceSystem.GOOGLE_EARTH().getVocabulary());
538 return ReferenceSystem.WGS84();
539 }else if(geoCodeMethod.startsWith("Google")){
540 return ReferenceSystem.GOOGLE_EARTH();
541 }else if(geoCodeMethod.startsWith("Map")){
542 return ReferenceSystem.MAP();
543 }else if(geoCodeMethod.startsWith("WikiProjekt Georeferenzierung") || geoCodeMethod.startsWith("http://toolserver.org/~geohack/geohack.php") ){
544 return ReferenceSystem.WGS84();
545 }else {
546 logger.warn("Reference system " + geoCodeMethod + " not yet supported.");
547 return null;
548 }
549 }
550
551
552
553
554 private void handleCollectorTeam(AlgaTerraImportState state, DerivedUnitFacade facade, ResultSet rs) throws SQLException {
555 String collector = rs.getString("Collector");
556 TeamOrPersonBase<?> author = getAuthor(collector);
557 facade.setCollector(author);
558 }
559
560 /**
561 * @param facade
562 * @param collector
563 */
564 protected TeamOrPersonBase<?> getAuthor(String author) {
565 // FIXME TODO parsen und deduplizieren
566 Team team = Team.NewTitledInstance(author, author);
567 return team;
568 }
569
570
571 /**
572 * Use same TaxonDescription if two records belong to the same taxon
573 * @param state
574 * @param newTaxonId
575 * @param oldTaxonId
576 * @param oldDescription
577 * @param taxonMap
578 * @return
579 */
580 protected TaxonDescription getTaxonDescription(AlgaTerraImportState state, Taxon taxon, Reference<?> sourceSec){
581 TaxonDescription result = null;
582 Set<TaxonDescription> descriptionSet= taxon.getDescriptions();
583 if (descriptionSet.size() > 0) {
584 result = descriptionSet.iterator().next();
585 }else{
586 result = TaxonDescription.NewInstance();
587 result.setTitleCache(sourceSec.getTitleCache(), true);
588 taxon.addDescription(result);
589 }
590 return result;
591 }
592
593
594
595
596 }