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
.eflora
.centralAfrica
.ferns
;
12 import java
.sql
.ResultSet
;
13 import java
.sql
.SQLException
;
14 import java
.util
.HashMap
;
15 import java
.util
.HashSet
;
18 import java
.util
.UUID
;
19 import java
.util
.regex
.Matcher
;
20 import java
.util
.regex
.Pattern
;
22 import org
.apache
.commons
.lang
.StringUtils
;
23 import org
.apache
.log4j
.Logger
;
24 import org
.springframework
.stereotype
.Component
;
26 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
;
27 import eu
.etaxonomy
.cdm
.api
.facade
.DerivedUnitFacade
.DerivedUnitType
;
28 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
29 import eu
.etaxonomy
.cdm
.io
.common
.IOValidator
;
30 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportAnnotationMapper
;
31 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportMapping
;
32 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportMethodMapper
;
33 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbImportObjectCreationMapper
;
34 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.DbNotYetImplementedMapper
;
35 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IMappingImport
;
36 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
37 import eu
.etaxonomy
.cdm
.io
.eflora
.centralAfrica
.ferns
.validation
.CentralAfricaFernsTaxonImportValidator
;
38 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
39 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
40 import eu
.etaxonomy
.cdm
.model
.common
.AnnotationType
;
41 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
42 import eu
.etaxonomy
.cdm
.model
.common
.ExtensionType
;
43 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
44 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
45 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
46 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
47 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
48 import eu
.etaxonomy
.cdm
.model
.description
.PresenceTerm
;
49 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
51 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
52 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
53 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaType
;
54 import eu
.etaxonomy
.cdm
.model
.location
.TdwgArea
;
55 import eu
.etaxonomy
.cdm
.model
.location
.WaterbodyOrCountry
;
56 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
57 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
58 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
59 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
60 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
61 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
62 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
63 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
64 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
65 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
74 public class CentralAfricaFernsTaxonImport
extends CentralAfricaFernsImportBase
<TaxonBase
> implements IMappingImport
<TaxonBase
, CentralAfricaFernsImportState
>{
75 private static final Logger logger
= Logger
.getLogger(CentralAfricaFernsTaxonImport
.class);
77 public static final UUID TNS_EXT_UUID
= UUID
.fromString("41cb0450-ac84-4d73-905e-9c7773c23b05");
80 private DbImportMapping mapping
;
82 //second path is not used anymore, there is now an ErmsTaxonRelationImport class instead
83 private boolean isSecondPath
= false;
85 private static final String pluralString
= "taxa";
86 private static final String dbTableName
= "[African pteridophytes]";
87 private static final Class cdmTargetClass
= TaxonBase
.class;
89 public CentralAfricaFernsTaxonImport(){
90 super(pluralString
, dbTableName
, cdmTargetClass
);
96 * @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getIdQuery()
99 protected String
getIdQuery() {
100 String strQuery
= " SELECT [Taxon number] FROM " + dbTableName
;
106 * @see eu.etaxonomy.cdm.io.erms.ErmsImportBase#getMapping()
108 protected DbImportMapping
getMapping() {
109 if (mapping
== null){
110 mapping
= new DbImportMapping();
112 mapping
.addMapper(DbImportObjectCreationMapper
.NewInstance(this, "Taxon number", TAXON_NAMESPACE
)); //id + tu_status
114 // mapping.addMapper(DbImportMethodMapper.NewInstance(this, "makeTypes", ResultSet.class, TaxonBase.class, CentralAfricaFernsImportState.class));
115 mapping
.addMapper(DbImportAnnotationMapper
.NewInstance("Notes", AnnotationType
.EDITORIAL()));
117 mapping
.addMapper(DbImportMethodMapper
.NewInstance(this, "makeCommonName", ResultSet
.class, CentralAfricaFernsImportState
.class));
118 mapping
.addMapper(DbImportMethodMapper
.NewInstance(this, "makeReferences", ResultSet
.class, CentralAfricaFernsImportState
.class));
119 mapping
.addMapper(DbImportMethodMapper
.NewInstance(this, "makeEcology", ResultSet
.class, CentralAfricaFernsImportState
.class));
120 mapping
.addMapper(DbImportMethodMapper
.NewInstance(this, "makeDistribution", ResultSet
.class, CentralAfricaFernsImportState
.class ));
122 // mapping.addMapper(DbImportTextDataCreationMapper.NewInstance(dbIdAttribute, objectToCreateNamespace, dbTaxonFkAttribute, taxonNamespace, dbTextAttribute, Language.ENGLISH(), Feature.ECOLOGY(), null));
124 //not yet implemented or ignore
125 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Types XXX", "Method Mapper does not work yet. Needs implementation for all 5 types. FIXMEs in implementation"));
127 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Basionym of", "Needs better understanding"));
128 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Synonym of", "Needs better understanding. Strange values like "));
131 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Chromosome number" , "Wrong data. Seems to be 'reference full'"));
133 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Book / Paper title" , "Needs implementation. Inreferences?"));
135 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Book Publisher & Place" , "How to access the reference via String mapper?"));
137 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Nom remarks" , "Needs parsing for status, homonyms etc., the rest goes to a name annotation"));
139 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Reprint no" , "What's this?"));
140 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Date verified" , "Needed?"));
142 mapping
.addMapper(DbNotYetImplementedMapper
.NewInstance("Illustrations - non-original" , "What's this?"));
145 // UUID credibilityUuid = ErmsTransformer.uuidCredibility;
146 // mapping.addMapper(DbImportExtensionMapper.NewInstance("tu_credibility", credibilityUuid, "credibility", "credibility", "credibility")); //Werte: null, unknown, marked for deletion
149 // mapping.addMapper(DbIgnoreMapper.NewInstance("cache_citation", "citation cache not needed in PESI"));
151 //not yet implemented or ignore
152 // mapping.addMapper(DbNotYetImplementedMapper.NewInstance("tu_hidden", "Needs DbImportMarkerMapper implemented"));
159 * @see eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportBase#getRecordQuery(eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator)
162 protected String
getRecordQuery(CentralAfricaFernsImportConfigurator config
) {
163 String strSelect
= " SELECT * ";
164 String strFrom
= " FROM [African pteridophytes] as ap";
165 String strWhere
= " WHERE ( ap.[taxon number] IN (" + ID_LIST_TOKEN
+ ") )";
166 String strOrderBy
= " ORDER BY [Taxon number]";
167 String strRecordQuery
= strSelect
+ strFrom
+ strWhere
+ strOrderBy
;
168 return strRecordQuery
;
173 * @see eu.etaxonomy.cdm.io.berlinModel.in.IPartitionedIO#getRelatedObjectsForPartition(java.sql.ResultSet)
175 public Map
<Object
, Map
<String
, ?
extends CdmBase
>> getRelatedObjectsForPartition(ResultSet rs
) {
179 Map
<Object
, Map
<String
, ?
extends CdmBase
>> result
= new HashMap
<Object
, Map
<String
, ?
extends CdmBase
>>();
182 Set
<String
> nameIdSet
= new HashSet
<String
>();
183 Set
<String
> referenceIdSet
= new HashSet
<String
>();
185 // handleForeignKey(rs, nameIdSet, "PTNameFk");
186 // handleForeignKey(rs, referenceIdSet, "PTRefFk");
190 // nameSpace = "Reference";
191 // cdmClass = Reference.class;
192 // Map<String, Person> referenceMap = (Map<String, Person>)getCommonService().getSourcedObjectsByIdInSource(Person.class, teamIdSet, nameSpace);
193 // result.put(Reference.class, referenceMap);
195 } catch (SQLException e
) {
196 throw new RuntimeException(e
);
201 private TaxonBase
makeTypes(ResultSet rs
, TaxonBase taxonBase
, CentralAfricaFernsImportState state
) throws SQLException
{
202 TaxonNameBase name
= taxonBase
.getName();
203 String typeString
= rs
.getString("Type");
204 String typeCollectorString
= rs
.getString("Type collector and number");
205 String typeLocationString
= rs
.getString("Type location");
206 makeSingleType(name
, typeString
, typeCollectorString
, typeLocationString
);
211 private void makeSingleType(TaxonNameBase name
, String typeString
, String typeCollectorString
, String typeLocationString
) {
212 DerivedUnitFacade type
= DerivedUnitFacade
.NewInstance(DerivedUnitType
.Specimen
);
213 makeTypeCollectorInfo(type
, typeCollectorString
);
214 type
.setLocality(typeString
);
216 // type.addDuplicate(duplicateSpecimen);
217 //FIXME handle also NameTypeDesignations
218 SpecimenTypeDesignation designation
= SpecimenTypeDesignation
.NewInstance();
219 designation
.setTypeSpecimen(type
.innerDerivedUnit());
220 name
.addTypeDesignation(designation
, false);
225 private void makeTypeCollectorInfo(DerivedUnitFacade type
, String collectorAndNumberString
) {
226 String reNumber
= "(s\\.n\\.|\\d.*)";
227 Pattern reNumberPattern
= Pattern
.compile(reNumber
);
228 Matcher matcher
= reNumberPattern
.matcher(collectorAndNumberString
);
230 if ( matcher
.find()){
231 int numberStart
= matcher
.start();
232 String number
= collectorAndNumberString
.substring(numberStart
).trim();
233 String collectorString
= collectorAndNumberString
.substring(0, numberStart
-1).trim();
234 type
.setCollectorsNumber(number
);
235 Team team
= Team
.NewTitledInstance(collectorString
, collectorString
);
236 type
.setCollector(team
);
239 logger
.warn("collector string did not match number pattern: " + collectorAndNumberString
);
245 * for internal use only, used by MethodMapper
247 private TaxonBase
makeDistribution(ResultSet rs
, CentralAfricaFernsImportState state
) throws SQLException
{
249 String taxonNumber
= state
.getTaxonNumber();
250 // logger.info(taxonNumber);
251 TaxonBase
<?
> taxonBase
= state
.getRelatedObject(state
.CURRENT_OBJECT_NAMESPACE
, state
.CURRENT_OBJECT_ID
, TaxonBase
.class);
252 String countriesString
= rs
.getString("Distribution - Country");
253 String province
= rs
.getString("Distribution - Province");
254 String distributionDetailed
= rs
.getString("Distribution - detailed");
255 TaxonNameBase nameUsedInSource
= taxonBase
.getName();
257 if (taxonBase
.isInstanceOf(Taxon
.class)){
258 taxon
= CdmBase
.deproxy(taxonBase
, Taxon
.class);
260 logger
.warn("Distributions for synonyms not yet supported");
261 taxon
= Taxon
.NewInstance(null, null);
264 if (StringUtils
.isNotBlank(countriesString
) ){
265 makeCountries(state
, taxonNumber
, taxon
, nameUsedInSource
, countriesString
, province
, distributionDetailed
);
267 makeProvince(taxon
, province
);
268 makeDistributionDetailed(taxon
, distributionDetailed
);
271 } catch (Exception e
) {
283 * @param countriesString
285 private void makeCountries(CentralAfricaFernsImportState state
, String taxonNumber
, Taxon taxon
, TaxonNameBase nameUsedInSource
, String countriesString
, String province
, String distributionDetailed
) {
286 countriesString
= countriesString
.replaceAll("\\*", "");
287 countriesString
= countriesString
.replace(" ", " ");
288 countriesString
= countriesString
.replace(", endemic", " - endemic");
289 countriesString
= countriesString
.replace("(endemic)", " - endemic");
290 countriesString
= countriesString
.replace("(introduced)", " - introduced");
291 countriesString
= countriesString
.replace("(naturalised)", " - naturalised");
292 countriesString
= countriesString
.replace("Madagascar-", "Madagascar -");
293 countriesString
= countriesString
.replace("Mahé", "Mahe");
295 String
[] split
= countriesString
.split("[,;]");
296 String remainingString
= null;
297 for (String countryString
: split
){
298 countryString
= CdmUtils
.concat(", ", remainingString
, countryString
);
299 if (countryString
.matches(".*\\(.*") && ! countryString
.matches(".*\\).*")){
300 remainingString
= countryString
;
303 remainingString
= null;
305 makeSingleCountry(state
, taxonNumber
, taxon
, nameUsedInSource
, countryString
.trim());
306 } catch (UndefinedTransformerMethodException e
) {
312 private void makeDistributionDetailed(Taxon taxon
, String distributionDetailed
) {
313 if (StringUtils
.isNotBlank(distributionDetailed
)){
314 TaxonDescription description
= getTaxonDescription(taxon
, false, true);
315 TextData distribution
= TextData
.NewInstance(Feature
.DISTRIBUTION());
316 description
.addElement(distribution
);
317 distribution
.putText(distributionDetailed
, Language
.ENGLISH());
321 private void makeProvince(Taxon taxon
, String province
) {
322 if (StringUtils
.isNotBlank(province
)){
323 TaxonDescription description
= getTaxonDescription(taxon
, false, true);
324 TextData distribution
= TextData
.NewInstance(Feature
.DISTRIBUTION());
325 description
.addElement(distribution
);
326 distribution
.putText(province
, Language
.ENGLISH());
332 private void makeSingleCountry(CentralAfricaFernsImportState state
, String taxonNumber
, Taxon taxon
, TaxonNameBase nameUsedInSource
, String country
) throws UndefinedTransformerMethodException
{
333 boolean areaDoubtful
= false;
334 Distribution distribution
= Distribution
.NewInstance(null, PresenceTerm
.PRESENT());
335 distribution
.addSource(taxonNumber
, "Distribution_Country", state
.getConfig().getSourceReference(), null, nameUsedInSource
, null);
336 NamedArea area
= null;
338 if (StringUtils
.isBlank(country
)){
341 country
= country
.trim();
343 if (country
.startsWith("?")){
345 country
= country
.substring(1).trim();
348 country
= makeCountryStatus(state
, country
, distribution
);
351 country
= makeCountryBrackets(state
, taxonNumber
, taxon
, nameUsedInSource
, country
);
352 String countryWithoutIslands
= null;
353 String countryWithoutDot
= null;
354 if (country
.endsWith(" Isl.") || country
.endsWith(" isl.") ){
355 countryWithoutIslands
= country
.substring(0, country
.length()-5);
357 if (country
.endsWith(".")){
358 countryWithoutDot
= country
.substring(0, country
.length()-1);
360 if (country
.endsWith("*")){
361 country
= country
.substring(0, country
.length()-1);
363 if (country
.endsWith("Islands")){
364 country
= country
.replace("Islands", "Is.");
369 if (TdwgArea
.isTdwgAreaLabel(country
)){
371 area
= TdwgArea
.getAreaByTdwgLabel(country
);
372 }else if (TdwgArea
.isTdwgAreaLabel(countryWithoutIslands
)){
374 area
= TdwgArea
.getAreaByTdwgLabel(countryWithoutIslands
);
375 }else if (TdwgArea
.isTdwgAreaLabel(countryWithoutDot
)){
377 area
= TdwgArea
.getAreaByTdwgLabel(countryWithoutDot
);
378 }else if ( (area
= state
.getTransformer().getNamedAreaByKey(country
)) != null) {
380 }else if (WaterbodyOrCountry
.isWaterbodyOrCountryLabel(country
)){
382 area
= WaterbodyOrCountry
.getWaterbodyOrCountryByLabel(country
);
385 NamedAreaLevel level
= null;
386 NamedAreaType areaType
= null;
388 UUID uuid
= state
.getTransformer().getNamedAreaUuid(country
);
390 logger
.error(taxonNumber
+ " - Unknown country: " + country
);
392 area
= getNamedArea(state
, uuid
, country
, country
, country
, areaType
, level
);
395 distribution
.setArea(area
);
396 if (areaDoubtful
== true){
397 if (distribution
.getStatus().equals(PresenceTerm
.PRESENT())){
398 distribution
.setStatus(PresenceTerm
.PRESENT_DOUBTFULLY());
401 TaxonDescription description
= getTaxonDescription(taxon
, false, true);
402 description
.addElement(distribution
);
407 private String
makeCountryBrackets(CentralAfricaFernsImportState state
, String taxonNumber
, Taxon taxon
, TaxonNameBase nameUsedInSource
, String country
) {
408 String
[] split
= (country
+ " ").split("\\(.*\\)");
409 if (split
.length
== 2){
410 String bracket
= country
.substring(split
[0].length()+1, country
.indexOf(")"));
411 country
= split
[0].trim();
412 makeCountries(state
, taxonNumber
, taxon
, nameUsedInSource
, bracket
, null, null);
413 }else if (split
.length
==1){
416 logger
.warn("Illegal length");
423 private String
makeCountryStatus(CentralAfricaFernsImportState state
, String country
, Distribution distribution
) throws UndefinedTransformerMethodException
{
424 PresenceTerm status
= null;
425 String
[] split
= country
.split(" - ");
427 if (split
.length
== 2){
428 country
= split
[0].trim();
429 String statusString
= split
[1];
430 statusString
= statusString
.replace(".", "");
431 status
= state
.getTransformer().getPresenceTermByKey(statusString
);
433 logger
.warn("No status found: "+ statusString
);
436 // status = getPresenceTerm(state, uuid, statusString, statusString, null);
437 }else if (split
.length
== 1){
440 logger
.warn("Invalid length: " + split
.length
);
443 distribution
.setStatus(status
);
451 * for internal use only, used by MethodMapper
453 private TaxonBase
makeReferences(ResultSet rs
, CentralAfricaFernsImportState state
) throws SQLException
{
454 String taxonNumber
= state
.getTaxonNumber();
455 String referenceFullString
= rs
.getString("Reference full");
456 String referenceAbbreviatedString
= rs
.getString("Reference - abbreviated");
457 String volume
= rs
.getString("Book / Journal volume");
458 String pages
= rs
.getString("Book / Journal pages");
459 String illustrations
= rs
.getString("Illustration/s");
461 String fascicle
= rs
.getString("Book / Journal fascicle");
462 String part
= rs
.getString("Book / Journal part");
463 String paperTitle
= rs
.getString("Book / Paper title");
467 String datePublishedString
= rs
.getString("Date published");
468 String referenceString
= referenceFullString
;
469 if (StringUtils
.isBlank(referenceString
)){
470 referenceString
= referenceAbbreviatedString
;
473 TaxonBase
<?
> taxonBase
= state
.getRelatedObject(state
.CURRENT_OBJECT_NAMESPACE
, state
.CURRENT_OBJECT_ID
, TaxonBase
.class);
474 if (StringUtils
.isNotBlank(referenceString
) || StringUtils
.isNotBlank(volume
) ||
475 StringUtils
.isNotBlank(pages
) || StringUtils
.isNotBlank(illustrations
) ||
476 StringUtils
.isNotBlank(datePublishedString
) || StringUtils
.isNotBlank(paperTitle
)){
477 NonViralName name
= CdmBase
.deproxy(taxonBase
.getName(), NonViralName
.class);
478 Reference reference
= ReferenceFactory
.newGeneric();
479 reference
.setAuthorTeam((TeamOrPersonBase
)name
.getCombinationAuthorTeam());
480 reference
.setTitle(referenceString
);
481 reference
.setVolume(volume
);
482 reference
.setEdition(part
);
483 Reference inrefernce
= null;
485 TimePeriod datePublished
= TimePeriod
.parseString(datePublishedString
);
486 reference
.setDatePublished(datePublished
);
487 if (StringUtils
.isNotBlank(paperTitle
)){
488 Reference innerReference
= ReferenceFactory
.newGeneric();
489 innerReference
.setDatePublished(datePublished
);
490 name
.setNomenclaturalReference(innerReference
);
491 innerReference
.setInReference(reference
);
492 reference
= innerReference
;
494 name
.setNomenclaturalReference(reference
);
498 String details
= CdmUtils
.concat(", ", pages
, illustrations
);
499 details
= StringUtils
.isBlank(details
) ?
null : details
.trim();
500 name
.setNomenclaturalMicroReference(details
);
502 UUID uuidFascicle
= state
.getTransformer().getExtensionTypeUuid("fascicle");
503 ExtensionType extensionType
= getExtensionType(state
, uuidFascicle
, "Fascicle", "Fascicle", null);
504 reference
.addExtension(fascicle
, extensionType
);
505 } catch (UndefinedTransformerMethodException e
) {
510 logger
.warn(taxonNumber
+ " - Taxon has no reference");
516 * for internal use only, used by MethodMapper
518 private TaxonBase
makeCommonName(ResultSet rs
, CentralAfricaFernsImportState state
) throws SQLException
{
519 String taxonNumber
= state
.getTaxonNumber();
520 String commonNames
= rs
.getString("Common names");
521 TaxonBase
<?
> taxonBase
= state
.getRelatedObject(state
.CURRENT_OBJECT_NAMESPACE
, state
.CURRENT_OBJECT_ID
, TaxonBase
.class);
522 if (StringUtils
.isNotBlank(commonNames
)){
523 if (taxonBase
.isInstanceOf(Taxon
.class)){
524 Taxon taxon
= (Taxon
)taxonBase
;
525 TaxonDescription description
= getTaxonDescription(taxon
, false, true);
526 String
[] split
= commonNames
.split(",");
527 for (String commonNameString
: split
){
528 CommonTaxonName commonName
= CommonTaxonName
.NewInstance(commonNameString
.trim(), Language
.ENGLISH());
529 description
.addElement(commonName
);
532 logger
.warn(taxonNumber
+ " - Taxon with common name is of type synonym but must be accepted taxon: " + taxonBase
.getName().getTitleCache());
539 * for internal use only, used by MethodMapper
542 private TaxonBase
makeEcology(ResultSet rs
, CentralAfricaFernsImportState state
) throws SQLException
{
543 String taxonNumber
= state
.getTaxonNumber();
544 String ecologyString
= rs
.getString("Ecology");
545 TaxonBase
<?
> taxonBase
= state
.getRelatedObject(state
.CURRENT_OBJECT_NAMESPACE
, state
.CURRENT_OBJECT_ID
, TaxonBase
.class);
546 if (StringUtils
.isNotBlank(ecologyString
)){
547 if (taxonBase
.isInstanceOf(Taxon
.class)){
548 Taxon taxon
= (Taxon
)taxonBase
;
549 TaxonDescription description
= getTaxonDescription(taxon
, false, true);
550 TextData ecology
= TextData
.NewInstance(Feature
.ECOLOGY());
551 ecology
.putText(ecologyString
.trim(), Language
.ENGLISH());
552 description
.addElement(ecology
);
554 logger
.warn(taxonNumber
+ " - Taxon with ecology is of type synonym but must be accepted taxon: " + taxonBase
.getName().getTitleCache());
562 * @see eu.etaxonomy.cdm.io.common.mapping.IMappingImport#createObject(java.sql.ResultSet)
564 public TaxonBase
createObject(ResultSet rs
, CentralAfricaFernsImportState state
) throws SQLException
{
565 BotanicalName taxonName
= BotanicalName
.NewInstance(null);
566 Reference sec
= state
.getConfig().getSourceReference();
568 String taxonNumber
= rs
.getString("Taxon number");
569 state
.setTaxonNumber(taxonNumber
);
571 String orderName
= rs
.getString("Order name");
572 String subOrderName
= rs
.getString("Suborder name");
573 String familyName
= rs
.getString("Family name");
574 String subFamilyName
= rs
.getString("Subfamily name");
575 String tribusName
= rs
.getString("Tribus name");
576 String subTribusName
= rs
.getString("Subtribus name");
577 String sectionName
= rs
.getString("Section name");
578 String genusName
= rs
.getString("Genus name");
579 String subGenusName
= rs
.getString("Subgenus name");
580 String seriesName
= rs
.getString("Series name");
581 String specificEpihet
= rs
.getString("Specific epihet");
582 String subspeciesName
= rs
.getString("Subspecies name");
583 String varietyName
= rs
.getString("Variety name");
584 String subFormaName
= rs
.getString("Subforma");
585 String subVariety
= rs
.getString("Subvariery");
586 String formaName
= rs
.getString("Forma name");
587 String subsectionName
= rs
.getString("Subsection name");
589 String status
= rs
.getString("Current/Synonym");
591 TaxonBase taxon
= makeTaxon(taxonName
, sec
, taxonNumber
, status
);
593 // Integer parent3Rank = rs.getInt("parent3rank");
596 Rank lowestRank
= setLowestUninomial(taxonName
, orderName
, subOrderName
, familyName
, subFamilyName
, tribusName
, subTribusName
,genusName
);
597 lowestRank
= setLowestInfraGeneric(taxonName
, lowestRank
, subGenusName
, sectionName
, subsectionName
, seriesName
);
598 if (StringUtils
.isNotBlank(specificEpihet
)){
599 taxonName
.setSpecificEpithet(specificEpihet
);
600 lowestRank
= Rank
.SPECIES();
602 lowestRank
= setLowestInfraSpecific(taxonName
, lowestRank
, subspeciesName
, varietyName
, subVariety
, formaName
,subFormaName
);
604 taxonName
.setRank(lowestRank
);
605 setAuthor(taxonName
, rs
, taxonNumber
, false);
607 //add original source for taxon name (taxon original source is added in mapper
608 Reference citation
= state
.getConfig().getSourceReference();
609 // addOriginalSource(taxonName, taxonNumber, TAXON_NAMESPACE, citation);
617 * Creates the taxon object depending on name, sec and status
624 private TaxonBase
makeTaxon(BotanicalName taxonName
, Reference sec
, String taxonNumber
, String status
) {
626 if ("c".equalsIgnoreCase(status
)|| "incertus".equalsIgnoreCase(status
) ){
627 taxon
= Taxon
.NewInstance(taxonName
, sec
);
628 if ("incertus".equalsIgnoreCase(status
)){
629 taxon
.setDoubtful(true);
631 }else if ("s".equalsIgnoreCase(status
)){
632 taxon
= Synonym
.NewInstance(taxonName
, sec
);
634 logger
.warn(taxonNumber
+ ": Status not given for taxon " );
635 taxon
= Taxon
.NewUnknownStatusInstance(taxonName
, sec
);
641 private Rank
setLowestInfraSpecific(BotanicalName taxonName
, Rank lowestRank
, String subspeciesName
, String varietyName
,
642 String subVariety
, String formaName
, String subFormaName
) {
643 if (StringUtils
.isNotBlank(subFormaName
)){
644 taxonName
.setInfraSpecificEpithet(subFormaName
);
645 return Rank
.SUBFORM();
646 }else if (StringUtils
.isNotBlank(formaName
)){
647 taxonName
.setInfraSpecificEpithet(formaName
);
649 }else if (StringUtils
.isNotBlank(subVariety
)){
650 taxonName
.setInfraSpecificEpithet(subVariety
);
651 return Rank
.SUBVARIETY();
652 }else if (StringUtils
.isNotBlank(varietyName
)){
653 taxonName
.setInfraSpecificEpithet(varietyName
);
654 return Rank
.VARIETY();
655 }else if (StringUtils
.isNotBlank(subspeciesName
)){
656 taxonName
.setInfraSpecificEpithet(subspeciesName
);
657 return Rank
.SUBSPECIES();
665 private Rank
setLowestInfraGeneric(BotanicalName taxonName
, Rank lowestRank
, String subGenusName
, String sectionName
, String subSectionName
, String seriesName
) {
666 if (StringUtils
.isNotBlank(seriesName
)){
667 taxonName
.setInfraGenericEpithet(seriesName
);
668 return Rank
.SERIES();
669 }else if (StringUtils
.isNotBlank(subSectionName
)){
670 taxonName
.setInfraGenericEpithet(subSectionName
);
671 return Rank
.SUBSECTION_BOTANY();
672 }else if (StringUtils
.isNotBlank(sectionName
)){
673 taxonName
.setInfraGenericEpithet(sectionName
);
674 return Rank
.SECTION_BOTANY();
675 }else if (StringUtils
.isNotBlank(subGenusName
)){
676 taxonName
.setInfraGenericEpithet(subGenusName
);
677 return Rank
.SUBGENUS();
685 private Rank
setLowestUninomial(BotanicalName taxonName
, String orderName
, String subOrderName
, String familyName
, String subFamilyName
,
686 String tribusName
, String subTribusName
, String genusName
) {
688 if (StringUtils
.isNotBlank(genusName
)){
689 taxonName
.setGenusOrUninomial(genusName
);
691 }else if (StringUtils
.isNotBlank(subTribusName
)){
692 taxonName
.setGenusOrUninomial(subTribusName
);
693 return Rank
.SUBTRIBE();
694 }else if (StringUtils
.isNotBlank(tribusName
)){
695 taxonName
.setGenusOrUninomial(tribusName
);
697 }else if (StringUtils
.isNotBlank(subFamilyName
)){
698 taxonName
.setGenusOrUninomial(subFamilyName
);
699 return Rank
.SUBFAMILY();
700 }else if (StringUtils
.isNotBlank(familyName
)){
701 taxonName
.setGenusOrUninomial(familyName
);
702 return Rank
.FAMILY();
703 }else if (StringUtils
.isNotBlank(subOrderName
)){
704 taxonName
.setGenusOrUninomial(subOrderName
);
705 return Rank
.SUBORDER();
706 }else if (StringUtils
.isNotBlank(orderName
)){
707 taxonName
.setGenusOrUninomial(orderName
);
716 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doCheck(eu.etaxonomy.cdm.io.common.IoStateBase)
719 protected boolean doCheck(CentralAfricaFernsImportState state
){
720 IOValidator
<CentralAfricaFernsImportState
> validator
= new CentralAfricaFernsTaxonImportValidator();
721 return validator
.validate(state
);
726 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IoStateBase)
729 protected boolean isIgnore(CentralAfricaFernsImportState state
){
730 return ! state
.getConfig().isDoTaxa();