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
;
13 import java
.sql
.ResultSet
;
14 import java
.sql
.SQLException
;
15 import java
.util
.HashMap
;
18 import java
.util
.UUID
;
20 import org
.apache
.commons
.lang3
.StringUtils
;
21 import org
.apache
.logging
.log4j
.LogManager
;
22 import org
.apache
.logging
.log4j
.Logger
;
23 import org
.springframework
.transaction
.TransactionStatus
;
25 import eu
.etaxonomy
.cdm
.common
.URI
;
26 import eu
.etaxonomy
.cdm
.facade
.DerivedUnitFacade
;
27 import eu
.etaxonomy
.cdm
.io
.berlinModel
.in
.BerlinModelImportBase
;
28 import eu
.etaxonomy
.cdm
.io
.common
.ResultSetPartitioner
;
29 import eu
.etaxonomy
.cdm
.io
.common
.Source
;
30 import eu
.etaxonomy
.cdm
.io
.common
.TdwgAreaProvider
;
31 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
32 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
33 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
34 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
35 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
36 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
37 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
38 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
39 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
40 import eu
.etaxonomy
.cdm
.model
.description
.State
;
41 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
42 import eu
.etaxonomy
.cdm
.model
.location
.Country
;
43 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
44 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
45 import eu
.etaxonomy
.cdm
.model
.location
.ReferenceSystem
;
46 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
47 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationType
;
48 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
49 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
50 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
51 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermVocabulary
;
52 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
53 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
59 public abstract class AlgaTerraSpecimenImportBase
extends BerlinModelImportBase
{
60 private static final long serialVersionUID
= -1741703900571072861L;
62 private static final Logger logger
= LogManager
.getLogger();
64 public static final String ECO_FACT_FIELD_OBSERVATION_NAMESPACE
= "EcoFact_FieldObservation";
65 public static final String ECO_FACT_DERIVED_UNIT_NAMESPACE
= "EcoFact_DerivedUnit";
66 public static final String TYPE_SPECIMEN_FIELD_OBSERVATION_NAMESPACE
= "TypeSpecimen_FieldObservation";
67 public static final String TYPE_SPECIMEN_DERIVED_UNIT_NAMESPACE
= "TypeSpecimen_DerivedUnit";
68 public static final String FACT_ECOLOGY_NAMESPACE
= "Fact (Ecology)";
71 public static final String TERMS_NAMESPACE
= "ALGA_TERRA_TERMS";
73 //TODO move to transformrer
74 final static UUID uuidMarkerAlkalinity
= UUID
.fromString("e52d0ea2-0c1f-4d95-ae6d-e21ab317c594");
75 final static UUID uuidRefSystemGps
= UUID
.fromString("c23e4928-c137-4e4a-b6ab-b430da3d0b94");
76 public final static UUID uuidFeatureSpecimenCommunity
= UUID
.fromString("3ff5b1ab-3999-4b5a-b8f7-01fd2f6c12c7");
77 public final static UUID uuidFeatureAdditionalData
= UUID
.fromString("0ac82ab8-2c2b-4953-98eb-a9f718eb9c57");
78 public final static UUID uuidFeatureHabitatExplanation
= UUID
.fromString("6fe32295-61a3-44fc-9fcf-a85790ea888f");
80 final static UUID uuidVocAlgaTerraClimate
= UUID
.fromString("b0a677c6-8bb6-43f4-b1b8-fc377a10feb5");
81 final static UUID uuidVocAlgaTerraHabitat
= UUID
.fromString("06f30114-e19c-4e7d-a8e5-5488c41fcbc5");
82 final static UUID uuidVocAlgaTerraLifeForm
= UUID
.fromString("3c0b194e-809c-4b42-9498-6ff034066ed7");
84 public final static UUID uuidFeatureAlgaTerraClimate
= UUID
.fromString("8754674c-9ab9-4f28-95f1-91eeee2314ee");
85 public final static UUID uuidFeatureAlgaTerraHabitat
= UUID
.fromString("7def3fc2-cdc5-4739-8e13-62edbd053415");
86 public final static UUID uuidFeatureAlgaTerraLifeForm
= UUID
.fromString("9b657901-1b0d-4a2a-8d21-dd8c1413e2e6");
88 final static UUID uuidVocParameter
= UUID
.fromString("45888b40-5bbb-4293-aa1e-02479796cd7c");
89 final static UUID uuidStatMeasureSingleValue
= UUID
.fromString("eb4c3d98-4d4b-4c37-8eb4-17315ce79920");
90 final static UUID uuidMeasurementValueModifier
= UUID
.fromString("0218a7a3-f6c0-4d06-a4f8-6b50b73aef5e");
92 final static UUID uuidModifierLowerThan
= UUID
.fromString("2b500085-6bef-4003-b6ea-e0ad0237d79d");
93 final static UUID uuidModifierGreaterThan
= UUID
.fromString("828df49d-c745-48f7-b083-0ada43356c34");
95 public AlgaTerraSpecimenImportBase(String tableName
, String pluralString
) {
96 super(tableName
, pluralString
);
100 * Creates the vocabularies and the features for Climate, Habitat and Lifeform
102 * @throws SQLException
104 protected void makeVocabulariesAndFeatures(AlgaTerraImportState state
) throws SQLException
{
105 String abbrevLabel
= null;
108 if (! state
.isSpecimenVocabulariesCreated()){
110 TransactionStatus txStatus
= this.startTransaction();
112 boolean isOrdered
= true;
113 State tmp
= State
.NewInstance();
114 OrderedTermVocabulary
<State
> climateVoc
= (OrderedTermVocabulary
<State
>)getVocabulary(state
, TermType
.State
, uuidVocAlgaTerraClimate
, "Climate", "Climate", abbrevLabel
, uri
, isOrdered
, tmp
);
115 OrderedTermVocabulary
<State
> habitatVoc
= (OrderedTermVocabulary
<State
>)getVocabulary(state
, TermType
.State
, uuidVocAlgaTerraHabitat
, "Habitat", "Habitat", abbrevLabel
, uri
, isOrdered
, tmp
);
116 OrderedTermVocabulary
<State
> lifeformVoc
= (OrderedTermVocabulary
<State
>)getVocabulary(state
, TermType
.State
, uuidVocAlgaTerraLifeForm
, "Lifeform", "Lifeform", abbrevLabel
, uri
, isOrdered
, tmp
);
118 Feature feature
= getFeature(state
, uuidFeatureAlgaTerraClimate
, "Climate","Climate", null, null);
119 feature
.setSupportsCategoricalData(true);
121 feature
= getFeature(state
, uuidFeatureAlgaTerraLifeForm
, "LifeForm","LifeForm", null, null);
122 feature
.setSupportsCategoricalData(true);
124 feature
= Feature
.HABITAT();
125 feature
.setSupportsCategoricalData(true);
126 getTermService().saveOrUpdate(feature
);
128 Source source
= state
.getAlgaTerraConfigurator().getSource();
130 String climateSql
= "SELECT * FROM EcoClimate";
131 ResultSet rs
= source
.getResultSet(climateSql
);
133 String climate
= rs
.getString("Climate");
134 String description
= rs
.getString("Description");
135 Integer id
= rs
.getInt("ClimateId");
136 UUID uuid
= UUID
.fromString(rs
.getString("UUID"));
137 State stateTerm
= getStateTerm(state
, uuid
, climate
, description
, null, climateVoc
);
138 addOriginalSource(stateTerm
, id
.toString(), "EcoClimate", state
.getTransactionalSourceReference());
139 getTermService().saveOrUpdate(stateTerm
);
142 String habitatSql
= "SELECT * FROM EcoHabitat";
143 rs
= source
.getResultSet(habitatSql
);
145 String habitat
= rs
.getString("Habitat");
146 String description
= rs
.getString("Description");
147 Integer id
= rs
.getInt("HabitatId");
148 UUID uuid
= UUID
.fromString(rs
.getString("UUID"));
149 State stateTerm
= getStateTerm(state
, uuid
, habitat
, description
, null, habitatVoc
);
150 addOriginalSource(stateTerm
, id
.toString(), "EcoHabitat", state
.getTransactionalSourceReference());
151 getTermService().saveOrUpdate(stateTerm
);
154 String lifeformSql
= "SELECT * FROM EcoLifeForm";
155 rs
= source
.getResultSet(lifeformSql
);
157 String lifeform
= rs
.getString("LifeForm");
158 String description
= rs
.getString("Description");
159 Integer id
= rs
.getInt("LifeFormId");
160 UUID uuid
= UUID
.fromString(rs
.getString("UUID"));
161 State stateTerm
= getStateTerm(state
, uuid
, lifeform
, description
, null, lifeformVoc
);
162 addOriginalSource(stateTerm
, id
.toString(), "EcoLifeForm", state
.getTransactionalSourceReference());
163 getTermService().saveOrUpdate(stateTerm
);
167 TermVocabulary
<DefinedTerm
> materialCategoryVoc
= getVocabulary(state
, TermType
.KindOfUnit
, AlgaTerraImportTransformer
.uuidKindOfUnitVoc
, "Alga Terra Material Category", "Alga Terra Material Category", abbrevLabel
, uri
, false, DefinedTerm
.NewKindOfUnitInstance(null, null, null));
168 getVocabularyService().save(materialCategoryVoc
);
170 String materialSql
= "SELECT * FROM MaterialCategory WHERE MaterialCategoryId <> 16 ";
171 rs
= source
.getResultSet(materialSql
);
173 Integer id
= rs
.getInt("MaterialCategoryId");
174 String category
= rs
.getString("MaterialCategory");
175 String description
= rs
.getString("Description");
176 UUID uuid
= UUID
.randomUUID();
178 DefinedTerm kindOfUnit
= DefinedTerm
.NewKindOfUnitInstance(description
, category
, null);
179 kindOfUnit
.setUuid(uuid
);
180 addOriginalSource(kindOfUnit
, id
.toString(), "MaterialCategory", state
.getTransactionalSourceReference());
181 materialCategoryVoc
.addTerm(kindOfUnit
);
182 getTermService().saveOrUpdate(kindOfUnit
);
183 materialCategoryMapping
.put(id
, uuid
);
187 OrderedTermVocabulary
<NamedArea
> informalAreasVoc
= (OrderedTermVocabulary
<NamedArea
>)getVocabulary(state
, TermType
.NamedArea
, AlgaTerraImportTransformer
.uuidNamedAreaVocAlgaTerraInformalAreas
, "AlgaTerra Specific Areas", "AlgaTerra Specific Areas", abbrevLabel
, uri
, true, NamedArea
.NewInstance());
188 getVocabularyService().save(informalAreasVoc
);
190 String areaSql
= "SELECT * FROM TDWGGazetteer WHERE subL4 = 1 ";
191 rs
= source
.getResultSet(areaSql
);
193 String l1Code
= rs
.getString("L1Code");
194 String l2Code
= rs
.getString("L2Code");
195 String l3Code
= rs
.getString("L3Code");
196 String l4Code
= rs
.getString("L4Code");
197 String gazetteer
= rs
.getString("Gazetteer");
198 Integer id
= rs
.getInt("ID");
199 String notes
= rs
.getString("Notes");
201 // UUID uuid = UUID.fromString(rs.getString("UUID"));
202 UUID uuid
= UUID
.randomUUID();
203 subL4Mapping
.put(id
, uuid
);
205 String tdwgCode
= (l4Code
!= null) ? l4Code
: (l3Code
!= null) ? l3Code
: (l2Code
!= null) ? l2Code
: l1Code
;
207 NamedArea tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(tdwgCode
);
208 NamedArea newArea
= getNamedArea(state
, uuid
,gazetteer
, gazetteer
, null, null, null, informalAreasVoc
, TermMatchMode
.UUID_ONLY
, null);
209 if (isNotBlank(notes
)){
210 newArea
.addAnnotation(Annotation
.NewInstance(notes
, AnnotationType
.EDITORIAL(), Language
.DEFAULT()));
213 addOriginalSource(newArea
, id
.toString(), "TDWGGazetteer", state
.getTransactionalSourceReference());
214 getTermService().saveOrUpdate(newArea
);
215 newArea
.setPartOf(tdwgArea
);
216 informalAreasVoc
.addTerm(newArea
);
219 this.commitTransaction(txStatus
);
221 state
.setSpecimenVocabulariesCreated(true);
226 static Map
<Integer
, UUID
> subL4Mapping
= new HashMap
<>();
227 static Map
<Integer
, UUID
> materialCategoryMapping
= new HashMap
<>();
229 protected String
getLocalityString(){
233 protected void handleFieldObservationSpecimen(ResultSet rs
, DerivedUnitFacade facade
, AlgaTerraImportState state
, ResultSetPartitioner partitioner
) throws SQLException
{
234 //FIXME missing fields #3084, #3085, #3080
237 Integer unitId
= nullSafeInt(rs
, "unitId");
238 String locality
= rs
.getString(getLocalityString());
239 Double latitude
= nullSafeDouble(rs
, "Latitude");
240 Double longitude
= nullSafeDouble(rs
, "Longitude");
241 Integer errorRadius
= nullSafeInt(rs
,"Prec");
242 String geoCodeMethod
= rs
.getString("GeoCodeMethod");
244 Integer altitude
= nullSafeInt(rs
, "Altitude");
245 Integer lowerAltitude
= nullSafeInt(rs
, "AltitudeLowerValue");
246 String altitudeUnit
= rs
.getString("AltitudeUnit");
247 Double depth
= nullSafeDouble(rs
, "Depth");
248 Double depthLow
= nullSafeDouble(rs
, "DepthLow");
250 String collectorsNumber
= rs
.getString("CollectorsNumber");
251 Date collectionDateStart
= rs
.getDate("CollectionDate");
252 Date collectionDateEnd
= rs
.getDate("CollectionDateEnd");
255 facade
.setLocality(locality
);
258 ReferenceSystem referenceSystem
= makeRefrenceSystem(geoCodeMethod
, state
);
259 if (longitude
!= null || latitude
!= null || referenceSystem
!= null || errorRadius
!= null){
260 Point exactLocation
= Point
.NewInstance(longitude
, latitude
, referenceSystem
, errorRadius
);
261 facade
.setExactLocation(exactLocation
);
265 if (StringUtils
.isNotBlank(altitudeUnit
) && ! altitudeUnit
.trim().equalsIgnoreCase("m")){
266 logger
.warn("Altitude unit is not [m] but: " + altitudeUnit
);
268 if ( altitude
!= null){
269 if (lowerAltitude
== null){
270 facade
.setAbsoluteElevation(altitude
);
272 facade
.setAbsoluteElevationRange(lowerAltitude
,altitude
);
276 if (depthLow
== null){
277 facade
.setDistanceToWaterSurface(depth
);
279 //TODO which direction is correct?
280 facade
.setDistanceToWaterSurfaceRange(depth
, depthLow
);
285 facade
.setFieldNumber(collectorsNumber
);
286 TimePeriod gatheringPeriod
= TimePeriod
.NewInstance(collectionDateStart
, collectionDateEnd
);
287 facade
.setGatheringPeriod(gatheringPeriod
);
288 handleCollectorTeam(state
, facade
, rs
);
291 makeAreas(state
, rs
, facade
);
294 //=> not required according to Henning
296 //id, created, updated, notes
298 this.doIdCreatedUpdatedNotes(state
, facade
.innerFieldUnit(), rs
, unitId
, getFieldObservationNameSpace());
300 logger
.warn("FieldObservation has no unitId: " + facade
.innerFieldUnit() + ": " + getFieldObservationNameSpace());
302 } catch (Exception e
) {
303 throw new RuntimeException(e
);
308 protected void handleFirstDerivedSpecimen(ResultSet rs
, DerivedUnitFacade facade
, AlgaTerraImportState state
, ResultSetPartitioner partitioner
) throws SQLException
{
309 Integer unitId
= nullSafeInt(rs
, "unitId");
310 Integer collectionFk
= nullSafeInt(rs
,"CollectionFk");
311 String label
= rs
.getString("Label");
314 if (collectionFk
!= null){
315 Collection subCollection
= state
.getRelatedObject(AlgaTerraCollectionImport
.NAMESPACE_SUBCOLLECTION
, String
.valueOf(collectionFk
), Collection
.class);
316 if (subCollection
!= null){
317 facade
.setCollection(subCollection
);
319 Collection collection
= state
.getRelatedObject(AlgaTerraCollectionImport
.NAMESPACE_COLLECTION
, String
.valueOf(collectionFk
), Collection
.class);
320 if (collection
== null){
321 logger
.warn("Collection for collectionFK " + collectionFk
+ " can not be found.");
323 facade
.setCollection(collection
);
328 if (isNotBlank(label
)){
329 //TODO implement label #4218, #3090, #3084
330 logger
.warn("Label not yet implemented for specimen, #4218, #3090, #3084");
333 //TODO id, created for fact + ecoFact
334 // this.doIdCreatedUpdatedNotes(state, descriptionElement, rs, id, namespace);
336 this.doIdCreatedUpdatedNotes(state
, facade
.innerDerivedUnit(), rs
, unitId
, getDerivedUnitNameSpace());
338 logger
.warn("Specimen has no unitId: " + facade
.innerDerivedUnit() + ": " + getDerivedUnitNameSpace());
344 protected abstract String
getDerivedUnitNameSpace();
346 protected abstract String
getFieldObservationNameSpace();
349 protected DescriptionBase
<?
> getFieldObservationDescription(DerivedUnitFacade facade
) {
350 Set
<DescriptionBase
<?
>> descriptions
= (Set
)facade
.innerFieldUnit().getDescriptions();
351 for (DescriptionBase
<?
> desc
: descriptions
){
352 if (desc
.isImageGallery() == false){
356 SpecimenDescription specDesc
= SpecimenDescription
.NewInstance(facade
.innerFieldUnit());
357 descriptions
.add(specDesc
);
362 private void makeAreas(AlgaTerraImportState state
, ResultSet rs
, DerivedUnitFacade facade
) throws SQLException
{
363 Integer gazetteerId
= nullSafeInt(rs
, "GazetteerId");
364 if (gazetteerId
!= null){
367 String tdwg4
= rs
.getString("L4Code");
368 if (isNotBlank(tdwg4
)){
369 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(tdwg4
);
371 String tdwg3
= rs
.getString("L3Code");
372 if (isNotBlank(tdwg3
)){
373 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(tdwg3
);
375 Number tdwg2D
= nullSafeDouble(rs
, "L2Code");
377 Integer tdwg2
= tdwg2D
.intValue();
378 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(String
.valueOf(tdwg2
));
380 Number tdwg1D
= nullSafeDouble(rs
, "L1Code");
382 Integer tdwg1
= tdwg1D
.intValue();
383 tdwgArea
= TdwgAreaProvider
.getAreaByTdwgAbbreviation(String
.valueOf(tdwg1
));
390 if (tdwgArea
== null){
391 logger
.warn("TDWG area could not be defined for gazetterId: " + gazetteerId
);
393 facade
.addCollectingArea(tdwgArea
);
397 Country country
= null;
398 String isoCountry
= rs
.getString("ISOCountry");
399 String countryStr
= rs
.getString("Country");
400 if (isNotBlank(isoCountry
)){
401 country
= Country
.getCountryByIso3166A2(isoCountry
);
402 }else if (isNotBlank(countryStr
)){
403 logger
.warn("Country exists but no ISO code");
408 NamedArea subL4Area
= null;
409 Boolean subL4
= nullSafeBoolean(rs
, "subL4");
410 if (subL4
!= null && subL4
.booleanValue() == true){
411 subL4Area
= makeSubL4Area(state
, gazetteerId
);
412 if (subL4Area
!= null){
413 facade
.addCollectingArea(subL4Area
);
415 logger
.warn("SubL4 area not found for gazetteerId: " + gazetteerId
);
419 if (country
== null ){
420 if (! gazetteerId
.equals(40)){//special handling for Borneo, TDWG area is enough here as it matches exactly
421 if (subL4Area
== null ){
422 logger
.warn("Country does not exist and SubL4 could not be found for GazetteerID " + gazetteerId
);
424 logger
.info("Country could not be defined but subL4 area was added");
428 facade
.setCountry(country
);
434 NamedArea waterbody
= null;
435 String waterbodyStr
= rs
.getString("WaterBody");
436 if (isNotBlank(waterbodyStr
)){
437 if (waterbodyStr
.equals("Atlantic Ocean")){
438 waterbody
= NamedArea
.ATLANTICOCEAN();
439 }else if (waterbodyStr
.equals("Pacific Ocean")){
440 waterbody
= NamedArea
.PACIFICOCEAN();
441 }else if (waterbodyStr
.equals("Indian Ocean")){
442 waterbody
= NamedArea
.INDIANOCEAN();
443 }else if (waterbodyStr
.equals("Arctic Ocean")){
444 waterbody
= NamedArea
.ARCTICOCEAN();
446 logger
.warn("Waterbody not recognized: " + waterbody
);
448 if (waterbody
!= null){
449 facade
.addCollectingArea(waterbody
);
455 //TODO -> SpecimenImport (not existing in TypeSpecimen)
459 private NamedArea
makeSubL4Area(AlgaTerraImportState state
, Integer gazetteerId
) {
460 UUID uuid
= subL4Mapping
.get(gazetteerId
);
461 NamedArea area
= (NamedArea
)getTermService().find(uuid
);
463 logger
.warn("SubL4 area could not be found in repository");
468 private boolean handleMissingCountry(AlgaTerraImportState state
, DerivedUnitFacade facade
, Integer gazetteerId
) {
469 NamedArea area
= null;
470 if (gazetteerId
!= null){
471 if (gazetteerId
.equals(42)){
472 area
= getNamedArea(state
, AlgaTerraImportTransformer
.uuidNamedAreaBorneo
, null, null, null, null, null);
473 }else if (gazetteerId
.equals(1684)){
474 area
= getNamedArea(state
, AlgaTerraImportTransformer
.uuidNamedAreaPatagonia
, null, null, null, null, null);
475 }else if (gazetteerId
.equals(2167)){
476 area
= getNamedArea(state
, AlgaTerraImportTransformer
.uuidNamedAreaTierraDelFuego
, null, null, null, null, null);
480 facade
.addCollectingArea(area
);
487 protected SpecimenOrObservationType
makeDerivedUnitType(String recordBasis
) {
488 SpecimenOrObservationType result
= null;
489 if (StringUtils
.isBlank(recordBasis
)){
490 result
= SpecimenOrObservationType
.DerivedUnit
;
491 } else if (recordBasis
.equalsIgnoreCase("FossileSpecimen")){
492 result
= SpecimenOrObservationType
.Fossil
;
493 }else if (recordBasis
.equalsIgnoreCase("HumanObservation")){
494 result
= SpecimenOrObservationType
.HumanObservation
;
495 }else if (recordBasis
.equalsIgnoreCase("Literature")){
497 logger
.warn("Literature record basis not yet supported");
498 result
= SpecimenOrObservationType
.DerivedUnit
;
499 }else if (recordBasis
.equalsIgnoreCase("LivingSpecimen")){
500 result
= SpecimenOrObservationType
.LivingSpecimen
;
501 }else if (recordBasis
.equalsIgnoreCase("MachineObservation")){
502 result
= SpecimenOrObservationType
.MachineObservation
;
503 }else if (recordBasis
.equalsIgnoreCase("Observation")){
504 result
= SpecimenOrObservationType
.Observation
;
505 }else if (recordBasis
.equalsIgnoreCase("LivingCulture")){
507 logger
.warn("LivingCulture record basis not yet supported");
508 result
= SpecimenOrObservationType
.DerivedUnit
;
509 }else if (recordBasis
.equalsIgnoreCase("PreservedSpecimen")){
510 result
= SpecimenOrObservationType
.PreservedSpecimen
;
516 protected Feature
makeFeature(SpecimenOrObservationType type
, AlgaTerraImportState state
) {
517 if (type
.equals(SpecimenOrObservationType
.DerivedUnit
)){
518 return Feature
.INDIVIDUALS_ASSOCIATION();
519 }else if (type
.isFeatureObservation()){
520 return Feature
.OBSERVATION();
521 }else if (type
.isPreservedSpecimen()){
522 return Feature
.SPECIMEN();
523 }else if (type
.equals(SpecimenOrObservationType
.LivingSpecimen
)){
524 UUID uuid
= AlgaTerraImportTransformer
.uuidFeatureLivingSpecimen
;
525 Feature feature
= getFeature(state
, uuid
, "Living Specimen", "Living Specimen", null, Feature
.SPECIMEN().getVocabulary());
526 if (feature
== null){
527 logger
.warn("Living Specimen Feature could not be created");
531 logger
.warn("No feature defined for derived unit type: " + type
);
535 private ReferenceSystem
makeRefrenceSystem(String geoCodeMethod
, AlgaTerraImportState state
) {
536 if (StringUtils
.isBlank(geoCodeMethod
)){
538 }else if(geoCodeMethod
.startsWith("GPS")){
539 getReferenceSystem(state
, uuidRefSystemGps
, "GPS", "GPS", "GPS", ReferenceSystem
.GOOGLE_EARTH().getVocabulary());
540 return ReferenceSystem
.WGS84();
541 }else if(geoCodeMethod
.startsWith("Google")){
542 return ReferenceSystem
.GOOGLE_EARTH();
543 }else if(geoCodeMethod
.startsWith("Map")){
544 return ReferenceSystem
.MAP();
545 }else if(geoCodeMethod
.startsWith("WikiProjekt Georeferenzierung") || geoCodeMethod
.startsWith("http://toolserver.org/~geohack/geohack.php") ){
546 return ReferenceSystem
.WGS84();
548 logger
.warn("Reference system " + geoCodeMethod
+ " not yet supported.");
556 private void handleCollectorTeam(AlgaTerraImportState state
, DerivedUnitFacade facade
, ResultSet rs
) throws SQLException
{
557 String collector
= rs
.getString("Collector");
558 TeamOrPersonBase
<?
> author
= getAuthor(collector
);
559 facade
.setCollector(author
);
566 protected TeamOrPersonBase
<?
> getAuthor(String author
) {
567 // FIXME TODO parsen und deduplizieren
568 Team team
= Team
.NewTitledInstance(author
, author
);
574 * Use same TaxonDescription if two records belong to the same taxon
578 * @param oldDescription
582 protected TaxonDescription
getTaxonDescription(AlgaTerraImportState state
, Taxon taxon
, Reference sourceSec
){
583 TaxonDescription result
= null;
584 Set
<TaxonDescription
> descriptionSet
= taxon
.getDescriptions();
585 if (descriptionSet
.size() > 0) {
586 result
= descriptionSet
.iterator().next();
588 result
= TaxonDescription
.NewInstance();
589 result
.setTitleCache(sourceSec
.getTitleCache(), true);
590 taxon
.addDescription(result
);