import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_IS_TYPE_OF;\r
import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.NAME_REL_TYPE_NOT_DESIGNATED;\r
\r
-import java.lang.reflect.InvocationTargetException;\r
import java.lang.reflect.Method;\r
import java.sql.ResultSet;\r
import java.sql.SQLException;\r
import java.util.HashSet;\r
-import java.util.Map;\r
import java.util.Set;\r
\r
import org.apache.log4j.Logger;\r
import eu.etaxonomy.cdm.io.common.IImportConfigurator;\r
import eu.etaxonomy.cdm.io.common.MapWrapper;\r
import eu.etaxonomy.cdm.io.common.Source;\r
-import eu.etaxonomy.cdm.model.common.CdmBase;\r
import eu.etaxonomy.cdm.model.name.BotanicalName;\r
import eu.etaxonomy.cdm.model.name.HybridRelationshipType;\r
import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
protected boolean doCheck(IImportConfigurator config){\r
boolean result = true;\r
logger.warn("Checking for TaxonNameRelations not yet implemented");\r
- //result &= checkArticlesWithoutJournal(bmiConfig);\r
- //result &= checkPartOfJournal(bmiConfig);\r
+ BerlinModelImportConfigurator bmiConfig = (BerlinModelImportConfigurator)config;\r
+ result &= checkUnrelatedHomotypicSynonyms(bmiConfig);\r
\r
return result;\r
}\r
*/\r
@Override\r
protected boolean doInvoke(BerlinModelImportState state){ \r
- \r
+ boolean success = true; \r
MapWrapper<TaxonNameBase> taxonNameMap = (MapWrapper<TaxonNameBase>)state.getStore(ICdmIO.TAXONNAME_STORE);\r
MapWrapper<ReferenceBase> referenceMap = (MapWrapper<ReferenceBase>)state.getStore(ICdmIO.REFERENCE_STORE);\r
+ MapWrapper<ReferenceBase> nomRefMap = (MapWrapper<ReferenceBase>)state.getStore(ICdmIO.NOMREF_STORE);\r
+ MapWrapper<ReferenceBase> nomRefDetailMap = (MapWrapper<ReferenceBase>)state.getStore(ICdmIO.NOMREF_DETAIL_STORE);\r
\r
Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>();\r
BerlinModelImportConfigurator config = state.getConfig();\r
TaxonNameBase nameFrom = taxonNameMap.get(name1Id);\r
TaxonNameBase nameTo = taxonNameMap.get(name2Id);\r
\r
- ReferenceBase citation = referenceMap.get(relRefFk);\r
+ ReferenceBase citation = nomRefDetailMap.get(relRefFk);\r
+ if (citation == null){\r
+ citation = referenceMap.get(relRefFk);\r
+ }\r
+ if (citation == null){\r
+ citation = nomRefMap.get(relRefFk);\r
+ }\r
+ \r
//TODO (preliminaryFlag = true testen\r
String microcitation = details;\r
- String rule = null; //TODO\r
+ String rule = null; \r
\r
if (nameFrom != null && nameTo != null){\r
if (relQualifierFk == NAME_REL_IS_BASIONYM_FOR){\r
}else if (relQualifierFk == NAME_REL_HAS_SAME_TYPE_AS){\r
nameTo.getHomotypicalGroup().merge(nameFrom.getHomotypicalGroup());//nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ;\r
}else if (relQualifierFk == NAME_REL_IS_TYPE_OF || relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF || relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF || relQualifierFk == NAME_REL_IS_LECTOTYPE_OF || relQualifierFk == NAME_REL_TYPE_NOT_DESIGNATED ){\r
- //TODO\r
- String originalNameString = null;\r
boolean isRejectedType = (relQualifierFk == NAME_REL_IS_REJECTED_TYPE_OF);\r
boolean isConservedType = (relQualifierFk == NAME_REL_IS_CONSERVED_TYPE_OF);\r
boolean isLectoType = (relQualifierFk == NAME_REL_IS_LECTOTYPE_OF);\r
boolean isNotDesignated = (relQualifierFk == NAME_REL_TYPE_NOT_DESIGNATED);\r
\r
+ String originalNameString = null;\r
//TODO addToAllNames true or false?\r
- nameTo.addNameTypeDesignation(nameFrom, citation, microcitation, originalNameString, isRejectedType, isConservedType, isLectoType, isNotDesignated, false);\r
+ boolean addToAllNames = false;\r
+ nameTo.addNameTypeDesignation(nameFrom, citation, microcitation, originalNameString, isRejectedType, isConservedType, isLectoType, isNotDesignated, addToAllNames);\r
\r
}else if (relQualifierFk == NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF){\r
nameFrom.addRelationshipToName(nameTo, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), citation, microcitation, rule) ;\r
//HybridRelationships\r
if (! (nameTo instanceof BotanicalName) || ! (nameFrom instanceof BotanicalName)){\r
logger.warn("HybridrelationshipNames ("+name1Id +"," + name2Id +") must be of type BotanicalName but are not");\r
+ success = false;\r
}\r
try {\r
HybridRelationshipType hybridRelType = BerlinModelTransformer.relNameId2HybridRel(relQualifierFk);\r
//parent.addHybridChild(child, hybridRelType, rule);\r
logger.warn("HybridRelationships not yet implemented");\r
\r
- //TODO reference\r
} catch (UnknownCdmTypeException e) {\r
- //TODO\r
logger.warn(e);\r
+ success = false;\r
}\r
}else {\r
//TODO\r
} catch (Exception e) {\r
logger.error(e.getMessage());\r
logger.warn("NameRelationship could not be imported");\r
- return false;\r
+ success = false;\r
} \r
}else{\r
- logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented"); \r
+ logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented");\r
+ success = false;\r
}\r
}\r
nameStore.add(nameFrom);\r
if (nameTo == null){\r
logger.warn("to TaxonNames for RelName (" + relNameId + ") does not exist in store");\r
}\r
+ success = false;\r
}\r
}\r
logger.info("TaxonName to save: " + nameStore.size());\r
getNameService().saveTaxonNameAll(nameStore);\r
\r
- logger.info("end makeNameRelationships ...");\r
- return true;\r
+ logger.info("end makeNameRelationships ..." + getSuccessString(success));\r
+ return success;\r
} catch (SQLException e) {\r
logger.error("SQLException:" + e);\r
return false;\r
return ! config.isDoRelNames();\r
}\r
\r
+ private boolean checkUnrelatedHomotypicSynonyms(BerlinModelImportConfigurator bmiConfig){\r
+ \r
+ try {\r
+ boolean result = true;\r
+ Source source = bmiConfig.getSource();\r
+ String strSQL = " SELECT Name.NameId AS NameId1, Name2.NameId AS NameId2, Name.FullNameCache AS NameCache1, Name2.FullNameCache AS NameCache2 " +\r
+ " FROM RelPTaxon INNER JOIN Name ON RelPTaxon.PTNameFk1 = Name.NameId " +\r
+ " INNER JOIN Name AS Name2 ON RelPTaxon.PTNameFk2 = Name2.NameId " +\r
+ " WHERE RelPTaxon.RelQualifierFk = 7 AND " + \r
+ " RelPTaxon.PTNameFk1 NOT IN " + \r
+ " (SELECT NameFk1 " + \r
+ " FROM RelName " +\r
+ " WHERE RelNameQualifierFk = 1 OR RelNameQualifierFk = 3 " +\r
+ " UNION " + \r
+ " SELECT NameFk2 " +\r
+ " FROM RelName AS RelName2 " + \r
+ " WHERE RelNameQualifierFk = 1 OR RelNameQualifierFk = 3)";\r
+ \r
+ ResultSet rs = source.getResultSet(strSQL);\r
+ boolean firstRow = true;\r
+ int i = 0;\r
+ while (rs.next()){\r
+ i++;\r
+ if (firstRow){\r
+ System.out.println("========================================================");\r
+ logger.warn("There are names that have a homotypic relationship as taxa but no 'is basionym' or 'is replaced synonym' relationship");\r
+ System.out.println("========================================================");\r
+ }\r
+ \r
+ int nameId1 = rs.getInt("NameId1");\r
+ String nameCache1 = rs.getString("NameCache1");\r
+ int nameId2 = rs.getInt("NameId2");\r
+ String nameCache2 = rs.getString("NameCache2");\r
+ \r
+ System.out.println("NameId1:" + nameId1 + \r
+ "\n NameCache1: " + nameCache1 + "\n NameId2: " + nameId2 + "\n NameCache2: " + nameCache2) ;\r
+ result = firstRow = false;\r
+ }\r
+ if (i > 0){\r
+ System.out.println(" ");\r
+ }\r
+ \r
+ return result;\r
+ } catch (SQLException e) {\r
+ e.printStackTrace();\r
+ return false;\r
+ }\r
+ }\r
+ \r
}\r