private int modCount = 10000;\r
/* The highest taxon index in the FauEu database */\r
private int highestTaxonIndex = 0;\r
+ private int callCount = 0;\r
private Map<Integer, FaunaEuropaeaTaxon> fauEuTaxonMap = new HashMap();\r
\r
\r
\r
if(logger.isInfoEnabled()) { logger.info("Start making taxa..."); }\r
\r
-// success = retrieveTaxa(fauEuConfig, stores, fauEuTaxonMap, true);\r
- success = retrieveTaxa(fauEuConfig, stores, fauEuTaxonMap);\r
+ success = retrieveTaxa(fauEuConfig, stores, fauEuTaxonMap, T_STATUS_ACCEPTED);\r
+// success = retrieveTaxa(fauEuConfig, stores, fauEuTaxonMap);\r
success = processTaxaSecondPass(fauEuConfig, stores, fauEuTaxonMap);\r
success = saveTaxa(stores);\r
\r
\r
private boolean retrieveTaxa(FaunaEuropaeaImportConfigurator fauEuConfig, \r
Map<String, MapWrapper<? extends CdmBase>> stores,\r
- Map<Integer, FaunaEuropaeaTaxon> fauEuTaxonMap, boolean valid) {\r
+ Map<Integer, FaunaEuropaeaTaxon> fauEuTaxonMap, int valid) {\r
\r
MapWrapper<TaxonBase> taxonStore = (MapWrapper<TaxonBase>)stores.get(ICdmIO.TAXON_STORE);\r
\r
}\r
\r
String validClause = "";\r
- if (valid == true) {\r
- validClause = " TAX_VALID = " + valid + " AND ";\r
+ if (valid == T_STATUS_ACCEPTED || valid == T_STATUS_NOT_ACCEPTED) {\r
+ validClause = " AND " + " TAX_VALID = " + valid;\r
}\r
\r
- String where = " WHERE ";\r
- String whereClause = where + validClause + "(1=1)";\r
- \r
- \r
strQuery = \r
" SELECT " + top + " Taxon.*, rank.*, author.* " + \r
" FROM dbo.Taxon " +\r
" LEFT OUTER JOIN dbo.author ON dbo.Taxon.TAX_AUT_ID = dbo.author.aut_id " +\r
" LEFT OUTER JOIN dbo.rank ON dbo.Taxon.TAX_RNK_ID = dbo.rank.rnk_id " +\r
- whereClause;\r
+ " WHERE (1=1)" +\r
+ validClause;\r
\r
if (logger.isInfoEnabled()) {\r
logger.info("Query: " + strQuery);\r
}\r
taxonStore.put(taxonId, taxonBase);\r
fauEuTaxonMap.put(taxonId, fauEuTaxon);\r
- if (logger.isDebugEnabled()) { \r
- logger.debug("Stored taxon base (" + taxonId + ") " + taxonName); \r
- }\r
+// if (logger.isDebugEnabled()) { \r
+// logger.debug("Stored taxon base (" + taxonId + ") " + taxonName); \r
+// }\r
} else {\r
logger.warn("Not imported taxon base with duplicated TAX_ID (" + taxonId + \r
") " + taxonName);\r
\r
if (logger.isInfoEnabled()) { logger.info("Taxon # " + id); }\r
String nameString = calculateTaxonName(fauEuTaxon, taxonBase, taxonStore, true);\r
-// String nameString = constructTaxonName("", fauEuTaxon, taxonBase, taxonStore, true);\r
setTaxonName(nameString, fauEuTaxon, taxonBase);\r
\r
}\r
}\r
\r
\r
- /* Build taxon name */\r
- private String buildTaxonName(FaunaEuropaeaTaxon fauEuTaxon,\r
- TaxonBase<?> taxonBase, MapWrapper<TaxonBase> taxonStore, boolean firstLevel) {\r
-\r
- String localString = "";\r
- String parentString = "";\r
- String parentNameCache = null;\r
- \r
- FaunaEuropaeaTaxon parent = null;\r
- \r
- TaxonNameBase<?,?> taxonName = taxonBase.getName();\r
- TaxonBase<?> parentTaxonBase = null;\r
-\r
- ZoologicalName zooName = (ZoologicalName)taxonName;\r
- TaxonNameBase<?,?> parentName = null;\r
- \r
- boolean parentComplete = false;\r
-\r
- if (zooName != null) {\r
- localString = zooName.getNameCache();\r
- }\r
-\r
- int rank = fauEuTaxon.getRankId();\r
- if (rank == R_SPECIES || rank == R_SUBSPECIES) { // For Species, Subspecies\r
- //if (rank > R_GENUS) {\r
- StringBuilder parentStringBuilder = new StringBuilder();\r
- if(logger.isInfoEnabled()) { \r
- logger.info("Local taxon name (rank = " + rank + "): " + localString); \r
- }\r
-\r
- // The scientific name in FaunaEuropaeaTaxon is set only once it has been built completely,\r
- // including parent(s) parts.\r
-\r
- int parentId = fauEuTaxon.getParentId();\r
- parent = fauEuTaxonMap.get(parentId);\r
- if (parent != null) {\r
- UUID parentUuid = parent.getUuid();\r
- if (parentUuid != null) { \r
- parentTaxonBase = taxonStore.get(parentId);\r
-// parentNameCache = parent.getScientificName();\r
-// if (parentNameCache == null) { // parent name has not been built yet\r
- if (parentTaxonBase != null) {\r
- parentName = parentTaxonBase.getName();\r
- if(parentName != null) {\r
- parentNameCache = ((ZoologicalName)parentName).getNameCache();\r
- } else {\r
- logger.warn("Parent taxon name of taxon (uuid= " + parentUuid.toString() + "), id = " +\r
- parent.getId() + ") is null");\r
- }\r
- } else {\r
- logger.warn("Parent taxon (uuid= " + parentUuid.toString() + "), id = " +\r
- parent.getId() + ") is null");\r
- } \r
- if (parent.getRankId() == R_SUBGENUS) {\r
- parentStringBuilder.append("(");\r
- }\r
- parentStringBuilder.append(parentNameCache);\r
- if (parent.getRankId() == R_SUBGENUS) {\r
- parentStringBuilder.append(")");\r
- }\r
-// parentStringBuilder.append(" ");\r
-// parentStringBuilder.append(((ZoologicalName)taxonName).getNameCache());\r
- parentString = parentStringBuilder.toString();\r
- if (logger.isInfoEnabled()) { logger.info("Parent name part built: " + parentString); }\r
-// } else { // parent name is already complete\r
-// parentComplete = true;\r
-// parentString = parent.getScientificName();\r
-// if (logger.isInfoEnabled()) { logger.info("Parent name is complete: " + parentString); }\r
-// }\r
- } else {\r
- logger.warn("Parent uuid of " + localString + " is null");\r
- }\r
- } else {\r
- logger.warn("Parent of " + localString + " is null");\r
- }\r
-// if (parent != null && parent.getRankId() >= R_GENUS && parentComplete == false) { \r
-// if (parent != null && parentComplete == false) {\r
- if (parent != null) {\r
- if ((rank == R_SPECIES) || (rank == R_SUBSPECIES) || (rank == R_SUBGENUS && firstLevel == false)) { \r
- parentString = buildTaxonName(parent, parentTaxonBase, taxonStore, false);\r
- }\r
- }\r
+ public static int maxCallsPerRank(int rankId) {\r
+\r
+ int result;\r
+ switch(rankId) {\r
+ case R_GENUS: \r
+ result = 1;\r
+ break;\r
+ case R_SUBGENUS: \r
+ result = 2;\r
+ break;\r
+ case R_SPECIES: \r
+ result = 3;\r
+ break;\r
+ case R_SUBSPECIES: \r
+ result = 4;\r
+ break;\r
+ default: \r
+ result = 1;\r
}\r
- \r
- StringBuilder concatStringBuilder = new StringBuilder(parentString);\r
- if (!parentString.equals("")) {\r
- \r
- if (!fauEuTaxon.isValid()) { // for synonyms remove the local name of the parent (accepted taxon)\r
- parentString = removeEpithet(parentString);\r
- }\r
- concatStringBuilder.append(" ");\r
- }\r
- \r
- concatStringBuilder.append(localString);\r
- String concatString = concatStringBuilder.toString();\r
- concatString = (String) CdmUtils.removeDuplicateWhitespace(concatString.trim());\r
- \r
- zooName.setNameCache(concatString);\r
- String titleCache = buildNameTitleCache(concatString, fauEuTaxon);\r
- zooName.setTitleCache(titleCache);\r
- zooName.setFullTitleCache(titleCache); // TODO: Add reference, NC status\r
- \r
- fauEuTaxon.setScientificName(concatString);\r
- if (logger.isInfoEnabled()) { \r
- logger.info("Name stored: " + concatString); \r
- }\r
- return concatString;\r
+ return result;\r
}\r
- \r
- \r
- /* Build taxon name */\r
- private String constructTaxonName(String string, FaunaEuropaeaTaxon fauEuTaxon,\r
- TaxonBase<?> taxonBase, MapWrapper<TaxonBase> taxonStore, boolean firstLevel) {\r
+ \r
+ \r
+ /* Build parent's taxon name */\r
+ private String buildParentName(int originalTaxonRank, String concatString, FaunaEuropaeaTaxon fauEuTaxon,\r
+ MapWrapper<TaxonBase> taxonStore) {\r
\r
- String localString = "";\r
- String parentString = "";\r
- String parentNameCache = null;\r
- \r
- FaunaEuropaeaTaxon parent = null;\r
+ callCount++;\r
\r
- TaxonNameBase<?,?> taxonName = taxonBase.getName();\r
- TaxonBase<?> parentTaxonBase = null;\r
+ /* Concatenated name string of parent */\r
+// String parentConcatString = "";\r
+ String parentConcatString = concatString;\r
\r
- ZoologicalName zooName = (ZoologicalName)taxonName;\r
+ StringBuilder parentConcatStringBuilder = new StringBuilder();\r
+ /* Local name of parent */\r
+ String parentString = null;\r
+\r
+ int parentId = fauEuTaxon.getParentId();\r
+ int rankId = fauEuTaxon.getRankId();\r
+ FaunaEuropaeaTaxon parent = fauEuTaxonMap.get(parentId);\r
+ TaxonBase<?> parentTaxonBase = null;\r
TaxonNameBase<?,?> parentName = null;\r
- \r
- boolean parentComplete = false;\r
\r
- if (zooName != null) {\r
- localString = zooName.getNameCache();\r
+ if (parent == null) {\r
+ logger.warn("Parent of taxon (" + fauEuTaxon.getId() + ") is null");\r
+ return parentConcatString;\r
+ }\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Concat string: " + concatString); \r
}\r
\r
- int rank = fauEuTaxon.getRankId();\r
- if (rank == R_SPECIES || rank == R_SUBSPECIES) { // For Species, Subspecies\r
- //if ((rank == R_SPECIES || rank == R_SUBSPECIES) || (rank == R_SUBGENUS && firstLevel == false)) { \r
- //if (rank > R_GENUS) {\r
- StringBuilder parentStringBuilder = new StringBuilder();\r
- if(logger.isInfoEnabled()) { \r
- logger.info("Local taxon name (rank = " + rank + "): " + localString); \r
- }\r
-\r
- // The scientific name in FaunaEuropaeaTaxon is set only once it has been built completely,\r
- // including parent(s) parts.\r
-\r
- int parentId = fauEuTaxon.getParentId();\r
- parent = fauEuTaxonMap.get(parentId);\r
- if (parent != null) {\r
- UUID parentUuid = parent.getUuid();\r
- if (parentUuid != null) { \r
- parentTaxonBase = taxonStore.get(parentId);\r
-// parentNameCache = parent.getScientificName();\r
-// if (parentNameCache == null) { // parent name has not been built yet\r
- if (parentTaxonBase != null) {\r
- parentName = parentTaxonBase.getName();\r
- if(parentName != null) {\r
- parentNameCache = ((ZoologicalName)parentName).getNameCache();\r
- } else {\r
- logger.warn("Parent taxon name of taxon (uuid= " + parentUuid.toString() + "), id = " +\r
- parent.getId() + ") is null");\r
- }\r
- } else {\r
- logger.warn("Parent taxon (uuid= " + parentUuid.toString() + "), id = " +\r
- parent.getId() + ") is null");\r
- } \r
- if (parent.getRankId() == R_SUBGENUS) {\r
- parentStringBuilder.append("(");\r
- }\r
- parentStringBuilder.append(parentNameCache);\r
- if (parent.getRankId() == R_SUBGENUS) {\r
- parentStringBuilder.append(")");\r
+// if (rankId > R_GENUS && callCounter <= maxCalls) {\r
+ if ((rankId == R_SPECIES || rankId == R_SUBSPECIES) || (rankId == R_SUBGENUS && callCount > 1)) { \r
+ UUID parentUuid = parent.getUuid();\r
+ if (parentUuid != null) { \r
+ parentTaxonBase = taxonStore.get(parentId);\r
+ if (parentTaxonBase != null) {\r
+ parentName = parentTaxonBase.getName();\r
+ if(parentName != null) {\r
+ parentString = ((ZoologicalName)parentName).getNameCache();\r
+ // parentString is either already complete or just local, depending on whether the\r
+ // parent taxon has already processed\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Parent string: " + parentString); \r
}\r
-// parentStringBuilder.append(" ");\r
-// parentStringBuilder.append(((ZoologicalName)taxonName).getNameCache());\r
- parentString = parentStringBuilder.toString();\r
- if (logger.isInfoEnabled()) { logger.info("Parent name part built: " + parentString); }\r
-// } else { // parent name is already complete\r
-// parentComplete = true;\r
-// parentString = parent.getScientificName();\r
-// if (logger.isInfoEnabled()) { logger.info("Parent name is complete: " + parentString); }\r
-// }\r
+ } else {\r
+ logger.warn("Parent taxon name of taxon (uuid= " + parentUuid.toString() + "), id = " +\r
+ parent.getId() + ") is null");\r
+ }\r
} else {\r
- logger.warn("Parent uuid of " + localString + " is null");\r
+ logger.warn("Parent taxon (uuid= " + parentUuid.toString() + "), id = " +\r
+ parent.getId() + ") is null");\r
+ } \r
+ if (parent.isNameComplete()) {\r
+ \r
+ }\r
+ if (parent.getRankId() == R_SUBGENUS) {\r
+ parentConcatStringBuilder.append("(");\r
+ }\r
+ parentConcatStringBuilder.append(parentString);\r
+ if (parent.getRankId() == R_SUBGENUS) {\r
+ parentConcatStringBuilder.append(")");\r
+ }\r
+ parentConcatStringBuilder.append(" ");\r
+ parentConcatStringBuilder.append(concatString);\r
+ parentConcatString = parentConcatStringBuilder.toString();\r
+ if (logger.isInfoEnabled()) { \r
+ logger.info("Concatenated name: " + parentConcatString); \r
}\r
} else {\r
- logger.warn("Parent of " + localString + " is null");\r
+ logger.warn("Parent uuid of " + parentId + " is null");\r
}\r
-// if (parent != null && parent.getRankId() >= R_GENUS && parentComplete == false) { \r
-// if (parent != null && parentComplete == false) {\r
- if (parent != null) {\r
- if ((rank == R_SPECIES || rank == R_SUBSPECIES) || (rank == R_SUBGENUS && firstLevel == false)) { \r
- parentString = constructTaxonName(parentString, parent, parentTaxonBase, taxonStore, false);\r
- }\r
+\r
+ } else {\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Name complete for taxon rank (" + rankId + ")");\r
}\r
+ return parentConcatString;\r
}\r
- \r
- StringBuilder concatStringBuilder = new StringBuilder(parentString);\r
-// concatStringBuilder.append(string);\r
- if (!parentString.equals("")) {\r
- \r
- if (!fauEuTaxon.isValid()) { // for synonyms remove the local name of the parent (accepted taxon)\r
- parentString = removeEpithet(parentString);\r
- }\r
- concatStringBuilder.append(" ");\r
+// if ((rankId == R_SPECIES || rankId == R_SUBSPECIES) || (rankId == R_SUBGENUS && firstLevel == false)) { \r
+ int maxCalls = maxCallsPerRank(originalTaxonRank);\r
+ if (logger.isDebugEnabled()) { \r
+ logger.debug("Call counter: " + callCount);\r
+ logger.debug("Max calls: " + maxCalls);\r
}\r
- \r
- concatStringBuilder.append(localString);\r
- String concatString = concatStringBuilder.toString();\r
- concatString = (String) CdmUtils.removeDuplicateWhitespace(concatString.trim());\r
- \r
- return concatString;\r
+ if (callCount <= maxCalls) {\r
+ if ((rankId == R_SPECIES || rankId == R_SUBSPECIES) || (rankId == R_SUBGENUS && callCount > 1)) { \r
+// parentConcatString = buildParentName(originalTaxonRank, parentConcatString, parent, taxonStore, callCounter++);\r
+ parentConcatString = buildParentName(originalTaxonRank, parentConcatString, parent, taxonStore);\r
+ }\r
}\r
\r
+ return parentConcatString;\r
+ }\r
+ \r
\r
/* Build parent's taxon name */\r
- private String buildParentName(String concatString, FaunaEuropaeaTaxon fauEuTaxon,\r
+ private String buildParentName_(String concatString, FaunaEuropaeaTaxon fauEuTaxon,\r
MapWrapper<TaxonBase> taxonStore, boolean firstLevel) {\r
\r
/* Concatenated name string of parent */\r
\r
int parentId = fauEuTaxon.getParentId();\r
int rankId = fauEuTaxon.getRankId();\r
- FaunaEuropaeaTaxon parent = fauEuTaxonMap.get(parentId);;\r
+ FaunaEuropaeaTaxon parent = fauEuTaxonMap.get(parentId);\r
TaxonBase<?> parentTaxonBase = null;\r
TaxonNameBase<?,?> parentName = null;\r
\r
return parentConcatString;\r
}\r
\r
- if (rankId > R_GENUS) {\r
+// if (rankId > R_GENUS) {\r
+ if ((rankId == R_SPECIES || rankId == R_SUBSPECIES) || (rankId == R_SUBGENUS && firstLevel == false)) { \r
UUID parentUuid = parent.getUuid();\r
if (parentUuid != null) { \r
parentTaxonBase = taxonStore.get(parentId);\r
return parentConcatString;\r
}\r
if ((rankId == R_SPECIES || rankId == R_SUBSPECIES) || (rankId == R_SUBGENUS && firstLevel == false)) { \r
- parentConcatString = buildParentName(parentConcatString, parent, taxonStore, false);\r
+ parentConcatString = buildParentName_(parentConcatString, parent, taxonStore, false);\r
}\r
\r
return parentConcatString;\r
}\r
- \r
+ \r
\r
/* Build taxon's concatenated name string */\r
private String calculateTaxonName(FaunaEuropaeaTaxon fauEuTaxon,\r
// The scientific name in FaunaEuropaeaTaxon is set only once it has been built completely,\r
// including parent(s) parts.\r
\r
- parentString = buildParentName(localString, fauEuTaxon, taxonStore, true);\r
+// parentString = buildParentName(localString, fauEuTaxon, taxonStore, true);\r
+ callCount = 0;\r
+ parentString = buildParentName(rank, localString, fauEuTaxon, taxonStore);\r
\r
StringBuilder concatStringBuilder = new StringBuilder(parentString);\r
\r
zooName.setFullTitleCache(titleCache); // TODO: Add reference, NC status\r
\r
fauEuTaxon.setScientificName(concatString);\r
+ fauEuTaxon.setNameComplete(true);\r
+\r
if (logger.isInfoEnabled()) { \r
logger.info("Name stored: " + concatString); \r
}\r