2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.algaterra
;
14 import java
.sql
.ResultSet
;
15 import java
.sql
.SQLException
;
16 import java
.util
.HashMap
;
19 import java
.util
.UUID
;
21 import org
.apache
.commons
.lang
.StringUtils
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.springframework
.transaction
.TransactionStatus
;
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
;
59 public abstract class AlgaTerraSpecimenImportBase
extends BerlinModelImportBase
{
60 private static final Logger logger
= Logger
.getLogger(AlgaTerraSpecimenImportBase
.class);
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)";
69 public static final String TERMS_NAMESPACE
= "ALGA_TERRA_TERMS";
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");
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");
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");
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");
90 final static UUID uuidModifierLowerThan
= UUID
.fromString("2b500085-6bef-4003-b6ea-e0ad0237d79d");
91 final static UUID uuidModifierGreaterThan
= UUID
.fromString("828df49d-c745-48f7-b083-0ada43356c34");
93 public AlgaTerraSpecimenImportBase(String tableName
, String pluralString
) {
94 super(tableName
, pluralString
);
98 * Creates the vocabularies and the features for Climate, Habitat and Lifeform
100 * @throws SQLException
102 protected void makeVocabulariesAndFeatures(AlgaTerraImportState state
) throws SQLException
{
103 String abbrevLabel
= null;
106 if (! state
.isSpecimenVocabulariesCreated()){
108 TransactionStatus txStatus
= this.startTransaction();
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
);
116 Feature feature
= getFeature(state
, uuidFeatureAlgaTerraClimate
, "Climate","Climate", null, null);
117 feature
.setSupportsCategoricalData(true);
119 feature
= getFeature(state
, uuidFeatureAlgaTerraLifeForm
, "LifeForm","LifeForm", null, null);
120 feature
.setSupportsCategoricalData(true);
122 feature
= Feature
.HABITAT();
123 feature
.setSupportsCategoricalData(true);
124 getTermService().saveOrUpdate(feature
);
126 Source source
= state
.getAlgaTerraConfigurator().getSource();
128 String climateSql
= "SELECT * FROM EcoClimate";
129 ResultSet rs
= source
.getResultSet(climateSql
);
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
);
140 String habitatSql
= "SELECT * FROM EcoHabitat";
141 rs
= source
.getResultSet(habitatSql
);
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
);
152 String lifeformSql
= "SELECT * FROM EcoLifeForm";
153 rs
= source
.getResultSet(lifeformSql
);
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
);
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
);
168 String materialSql
= "SELECT * FROM MaterialCategory WHERE MaterialCategoryId <> 16 ";
169 rs
= source
.getResultSet(materialSql
);
171 Integer id
= rs
.getInt("MaterialCategoryId");
172 String category
= rs
.getString("MaterialCategory");
173 String description
= rs
.getString("Description");
174 UUID uuid
= UUID
.randomUUID();
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
);
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
);
188 String areaSql
= "SELECT * FROM TDWGGazetteer WHERE subL4 = 1 ";
189 rs
= source
.getResultSet(areaSql
);
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");
199 // UUID uuid = UUID.fromString(rs.getString("UUID"));
200 UUID uuid
= UUID
.randomUUID();
201 subL4Mapping
.put(id
, uuid
);
203 String tdwgCode
= (l4Code
!= null) ? l4Code
: (l3Code
!= null) ? l3Code
: (l2Code
!= null) ? l2Code
: l1Code
;
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()));
211 addOriginalSource(newArea
, id
.toString(), "TDWGGazetteer", state
.getTransactionalSourceReference());
212 getTermService().saveOrUpdate(newArea
);
213 newArea
.setPartOf(tdwgArea
);
214 informalAreasVoc
.addTerm(newArea
);
217 this.commitTransaction(txStatus
);
219 state
.setSpecimenVocabulariesCreated(true);
224 static Map
<Integer
, UUID
> subL4Mapping
= new HashMap
<Integer
, UUID
>();
225 static Map
<Integer
, UUID
> materialCategoryMapping
= new HashMap
<Integer
, UUID
>();
227 protected String
getLocalityString(){
231 protected void handleFieldObservationSpecimen(ResultSet rs
, DerivedUnitFacade facade
, AlgaTerraImportState state
, ResultSetPartitioner partitioner
) throws SQLException
{
232 //FIXME missing fields #3084, #3085, #3080
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");
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");
248 String collectorsNumber
= rs
.getString("CollectorsNumber");
249 Date collectionDateStart
= rs
.getDate("CollectionDate");
250 Date collectionDateEnd
= rs
.getDate("CollectionDateEnd");
253 facade
.setLocality(locality
);
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
);
263 if (StringUtils
.isNotBlank(altitudeUnit
) && ! altitudeUnit
.trim().equalsIgnoreCase("m")){
264 logger
.warn("Altitude unit is not [m] but: " + altitudeUnit
);
266 if ( altitude
!= null){
267 if (lowerAltitude
== null){
268 facade
.setAbsoluteElevation(altitude
);
270 facade
.setAbsoluteElevationRange(lowerAltitude
,altitude
);
274 if (depthLow
== null){
275 facade
.setDistanceToWaterSurface(depth
);
277 //TODO which direction is correct?
278 facade
.setDistanceToWaterSurfaceRange(depth
, depthLow
);
283 facade
.setFieldNumber(collectorsNumber
);
284 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(collectionDateStart
, collectionDateEnd
);
285 facade
.setGatheringPeriod(gatheringPeriod
);
286 handleCollectorTeam(state
, facade
, rs
);
289 makeAreas(state
, rs
, facade
);
292 //=> not required according to Henning
294 //id, created, updated, notes
296 this.doIdCreatedUpdatedNotes(state
, facade
.innerFieldUnit(), rs
, unitId
, getFieldObservationNameSpace());
298 logger
.warn("FieldObservation has no unitId: " + facade
.innerFieldUnit() + ": " + getFieldObservationNameSpace());
300 } catch (Exception e
) {
301 throw new RuntimeException(e
);
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");
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
);
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.");
321 facade
.setCollection(collection
);
326 if (isNotBlank(label
)){
327 //TODO implement label #4218, #3090, #3084
328 logger
.warn("Label not yet implemented for specimen, #4218, #3090, #3084");
331 //TODO id, created for fact + ecoFact
332 // this.doIdCreatedUpdatedNotes(state, descriptionElement, rs, id, namespace);
334 this.doIdCreatedUpdatedNotes(state
, facade
.innerDerivedUnit(), rs
, unitId
, getDerivedUnitNameSpace());
336 logger
.warn("Specimen has no unitId: " + facade
.innerDerivedUnit() + ": " + getDerivedUnitNameSpace());
342 protected abstract String
getDerivedUnitNameSpace();
344 protected abstract String
getFieldObservationNameSpace();
347 protected DescriptionBase
getFieldObservationDescription(DerivedUnitFacade facade
) {
348 Set
<DescriptionBase
> descriptions
= facade
.innerFieldUnit().getDescriptions();
349 for (DescriptionBase desc
: descriptions
){
350 if (desc
.isImageGallery() == false){
354 SpecimenDescription specDesc
= SpecimenDescription
.NewInstance(facade
.innerFieldUnit());
355 descriptions
.add(specDesc
);
360 private void makeAreas(AlgaTerraImportState state
, ResultSet rs
, DerivedUnitFacade facade
) throws SQLException
{
361 Integer gazetteerId
= nullSafeInt(rs
, "GazetteerId");
362 if (gazetteerId
!= null){
365 String tdwg4
= rs
.getString("L4Code");
366 if (isNotBlank(tdwg4
)){
367 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(tdwg4
);
369 String tdwg3
= rs
.getString("L3Code");
370 if (isNotBlank(tdwg3
)){
371 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(tdwg3
);
373 Number tdwg2D
= nullSafeDouble(rs
, "L2Code");
375 Integer tdwg2
= tdwg2D
.intValue();
376 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(String
.valueOf(tdwg2
));
378 Number tdwg1D
= nullSafeDouble(rs
, "L1Code");
380 Integer tdwg1
= tdwg1D
.intValue();
381 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(String
.valueOf(tdwg1
));
388 if (tdwgArea
== null){
389 logger
.warn("TDWG area could not be defined for gazetterId: " + gazetteerId
);
391 facade
.addCollectingArea(tdwgArea
);
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");
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
);
413 logger
.warn("SubL4 area not found for gazetteerId: " + gazetteerId
);
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
);
422 logger
.info("Country could not be defined but subL4 area was added");
426 facade
.setCountry(country
);
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();
444 logger
.warn("Waterbody not recognized: " + waterbody
);
446 if (waterbody
!= null){
447 facade
.addCollectingArea(waterbody
);
453 //TODO -> SpecimenImport (not existing in TypeSpecimen)
457 private NamedArea
makeSubL4Area(AlgaTerraImportState state
, Integer gazetteerId
) {
458 UUID uuid
= subL4Mapping
.get(gazetteerId
);
459 NamedArea area
= (NamedArea
)getTermService().find(uuid
);
461 logger
.warn("SubL4 area could not be found in repository");
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);
478 facade
.addCollectingArea(area
);
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")){
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")){
505 logger
.warn("LivingCulture record basis not yet supported");
506 result
= SpecimenOrObservationType
.DerivedUnit
;
507 }else if (recordBasis
.equalsIgnoreCase("PreservedSpecimen")){
508 result
= SpecimenOrObservationType
.PreservedSpecimen
;
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");
529 logger
.warn("No feature defined for derived unit type: " + type
);
533 private ReferenceSystem
makeRefrenceSystem(String geoCodeMethod
, AlgaTerraImportState state
) {
534 if (StringUtils
.isBlank(geoCodeMethod
)){
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();
546 logger
.warn("Reference system " + geoCodeMethod
+ " not yet supported.");
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
);
564 protected TeamOrPersonBase
<?
> getAuthor(String author
) {
565 // FIXME TODO parsen und deduplizieren
566 Team team
= Team
.NewTitledInstance(author
, author
);
572 * Use same TaxonDescription if two records belong to the same taxon
576 * @param oldDescription
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();
586 result
= TaxonDescription
.NewInstance();
587 result
.setTitleCache(sourceSec
.getTitleCache(), true);
588 taxon
.addDescription(result
);