package eu.etaxonomy.cdm.io.berlinModel;\r
\r
+import static eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer.*;\r
+\r
import java.sql.ResultSet;\r
import java.sql.SQLException;\r
-import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.Map;\r
-import java.util.UUID;\r
+import java.util.HashSet;\r
+import java.util.Set;\r
\r
import org.apache.log4j.Logger;\r
\r
import eu.etaxonomy.cdm.api.application.CdmApplicationController;\r
import eu.etaxonomy.cdm.api.service.INameService;\r
-import eu.etaxonomy.cdm.api.service.IReferenceService;\r
import eu.etaxonomy.cdm.io.source.Source;\r
import eu.etaxonomy.cdm.model.agent.Agent;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
+import eu.etaxonomy.cdm.model.common.Annotation;\r
+import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.Marker;\r
+import eu.etaxonomy.cdm.model.common.MarkerType;\r
import eu.etaxonomy.cdm.model.name.BotanicalName;\r
+import eu.etaxonomy.cdm.model.name.NameRelationshipType;\r
import eu.etaxonomy.cdm.model.name.Rank;\r
import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;\r
import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
-import eu.etaxonomy.cdm.strategy.exceptions.UnknownRankException;\r
+import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;\r
+\r
\r
public class BerlinModelTaxonNameIO {\r
private static final Logger logger = Logger.getLogger(BerlinModelTaxonNameIO.class);\r
\r
- private static int modCount = 1000;\r
+ private static int modCount = 5000;\r
\r
- //TODO\r
- static boolean invokeRelations(Source source, CdmApplicationController cdmApp, \r
- boolean deleteAll, MapWrapper<TaxonNameBase> taxonNameMap,\r
- MapWrapper<ReferenceBase> referenceMap, MapWrapper<Agent> authorMap){\r
- return false;\r
+ public static boolean check(BerlinModelImportConfigurator bmiConfig){\r
+ boolean result = true;\r
+ logger.warn("Checking for TaxonNames not yet implemented");\r
+ //result &= checkArticlesWithoutJournal(bmiConfig);\r
+ //result &= checkPartOfJournal(bmiConfig);\r
+ \r
+ return result;\r
+ }\r
+ \r
+ public static boolean checkRelations(BerlinModelImportConfigurator bmiConfig){\r
+ boolean result = true;\r
+ logger.warn("Checking for TaxonNameRelations not yet implemented");\r
+ //result &= checkArticlesWithoutJournal(bmiConfig);\r
+ //result &= checkPartOfJournal(bmiConfig);\r
+ \r
+ return result;\r
}\r
\r
//TODO\r
- static boolean invokeStatus(Source source, CdmApplicationController cdmApp, \r
+ static boolean invokeStatus(ReferenceBase berlinModelRef, Source source, CdmApplicationController cdmApp, \r
boolean deleteAll, MapWrapper<TaxonNameBase> taxonNameMap,\r
MapWrapper<ReferenceBase> referenceMap, MapWrapper<Agent> authorMap){\r
return false;\r
}\r
\r
- public static boolean invoke(Source source, CdmApplicationController cdmApp, \r
- boolean deleteAll, MapWrapper<TaxonNameBase> taxonNameMap,\r
- MapWrapper<ReferenceBase> referenceMap, MapWrapper<Agent> authorMap){\r
- \r
+ public static boolean invoke(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp, \r
+ MapWrapper<TaxonNameBase> taxonNameMap, MapWrapper<ReferenceBase> referenceMap, MapWrapper<Team> authorMap){\r
\r
+ Source source = bmiConfig.getSource();\r
String dbAttrName;\r
String cdmAttrName;\r
boolean success = true ;\r
\r
logger.info("start makeTaxonNames ...");\r
INameService nameService = cdmApp.getNameService();\r
- boolean delete = deleteAll;\r
- \r
- \r
-// if (delete){\r
-// List<TaxonNameBase> listAllNames = nameService.getAllNames(0, 1000);\r
-// while(listAllNames.size() > 0 ){\r
-// for (TaxonNameBase name : listAllNames ){\r
-// //FIXME\r
-// //nameService.remove(name);\r
-// }\r
-// listAllNames = nameService.getAllNames(0, 1000);\r
-// }\r
-// }\r
+ boolean delete = bmiConfig.isDeleteAll();\r
\r
try {\r
\r
\r
//get data from database\r
String strQuery = \r
- "SELECT TOP 2000 Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +\r
+ "SELECT Name.* , RefDetail.RefDetailId, RefDetail.RefFk, " +\r
" RefDetail.FullRefCache, RefDetail.FullNomRefCache, RefDetail.PreliminaryFlag AS RefDetailPrelim, RefDetail.Details, " + \r
" RefDetail.SecondarySources, RefDetail.IdInSource " +\r
" FROM Name LEFT OUTER JOIN RefDetail ON Name.NomRefDetailFk = RefDetail.RefDetailId AND Name.NomRefDetailFk = RefDetail.RefDetailId AND " +\r
" Name.NomRefFk = RefDetail.RefFk AND Name.NomRefFk = RefDetail.RefFk" +\r
- " WHERE (1=1) AND Name.Created_When > '03.03.2004'";\r
+ " WHERE (1=1) ";\r
+ //strQuery += " AND Name.Created_When > '03.03.2004' ";\r
\r
\r
ResultSet rs = source.getResultSet(strQuery) ;\r
//create TaxonName element\r
int nameId = rs.getInt("nameId");\r
int rankId = rs.getInt("rankFk");\r
- Object nomRefFk = rs.getInt("NomRefFk");\r
+ Object authorFk = rs.getObject("AuthorTeamFk");\r
+ Object exAuthorFk = rs.getObject("ExAuthorTeamFk");\r
+ Object basAuthorFk = rs.getObject("BasAuthorTeamFk");\r
+ Object exBasAuthorFk = rs.getObject("ExBasAuthorTeamFk");\r
+ Object nomRefFk = rs.getObject("NomRefFk");\r
+ \r
+ Object createdWhen = rs.getObject("Created_When");\r
+ Object createdWho = rs.getObject("Created_Who");\r
+// Object updatedWhen = rs.getObject("Updated_When");\r
+// Object updatedWho = rs.getObject("Updated_who");\r
+ Object updatedWhen = "";\r
+ Object updatedWho = "";\r
+ Object notes = rs.getObject("notes");\r
\r
try {\r
if (logger.isDebugEnabled()){logger.debug(rankId);}\r
Rank rank = BerlinModelTransformer.rankId2Rank(rankId);\r
//FIXME\r
//BotanicalName name = BotanicalName.NewInstance(BerlinModelTransformer.rankId2Rank(rankId));\r
- BotanicalName botanicalName = new BotanicalName(rank);\r
+ BotanicalName botanicalName = BotanicalName.NewInstance(rank);\r
\r
if (rankId < 40){\r
dbAttrName = "supraGenericName";\r
//TODO\r
//preliminaryFlag\r
\r
+ //authorTeams\r
+ if (authorMap != null){\r
+ botanicalName.setCombinationAuthorTeam(getAuthorTeam(authorMap, authorFk, nameId));\r
+ botanicalName.setExCombinationAuthorTeam(getAuthorTeam(authorMap, exAuthorFk, nameId));\r
+ botanicalName.setBasionymAuthorTeam(getAuthorTeam(authorMap, basAuthorFk, nameId));\r
+ botanicalName.setExBasionymAuthorTeam(getAuthorTeam(authorMap, exBasAuthorFk, nameId));\r
+ }\r
+ \r
+ //nomenclatural Reference\r
if (referenceMap != null){\r
if (nomRefFk != null){\r
int nomRefFkInt = (Integer)nomRefFk;\r
ReferenceBase nomenclaturalReference = referenceMap.get(nomRefFkInt);\r
if (nomenclaturalReference == null){\r
+ //TODO\r
logger.warn("Nomenclatural reference (nomRefFk = " + nomRefFkInt + ") for TaxonName (nameId = " + nameId + ")"+\r
" was not found in reference store. Relation was not set!!");\r
}else if (! INomenclaturalReference.class.isAssignableFrom(nomenclaturalReference.getClass())){\r
}\r
}\r
\r
- \r
- //name ID\r
//refId\r
- //TODO\r
- // Annotation annotation = new Annotation("Berlin Model nameId: " + String.valueOf(refId), Language.DEFAULT());\r
- // botanicalName.addAnnotations(annotation);\r
+ String createdAnnotationString = "Berlin Model record was created By: " + String.valueOf(createdWho) + " (" + String.valueOf(createdWhen) + ") " +\r
+ " and updated By: " + String.valueOf(updatedWho) + " (" + String.valueOf(updatedWhen) + ")";\r
+ Annotation annotation = Annotation.NewInstance(createdAnnotationString, Language.ENGLISH());\r
+ annotation.setCommentator(bmiConfig.getCommentator());\r
+// try {\r
+// URL linkbackUrl = new URL("http:\\www.abc.de");\r
+// annotation.setLinkbackUrl(linkbackUrl);\r
+// } catch (MalformedURLException e) {\r
+// logger.warn("MalformedURLException");\r
+// }\r
+ botanicalName.addAnnotation(annotation);\r
+ \r
+ if (notes != null){\r
+ String notesString = String.valueOf(notes);\r
+ if (notesString.length() > 254 ){\r
+ notesString = notesString.substring(0, 250) + "...";\r
+ }\r
+ Annotation notesAnnotation = Annotation.NewInstance(notesString, null);\r
+ //notes.setCommentator(bmiConfig.getCommentator());\r
+ botanicalName.addAnnotation(notesAnnotation);\r
+ }\r
+ \r
+ \r
+ boolean flag = true;\r
+ Marker marker = Marker.NewInstance(MarkerType.TO_BE_CHECKED() ,flag);\r
+ botanicalName.addMarker(marker);\r
+ \r
+ \r
+ //nameId\r
+ ImportHelper.setOriginalSource(botanicalName, bmiConfig.getSourceReference(), nameId);\r
\r
taxonNameMap.put(nameId, botanicalName);\r
\r
- } catch (UnknownRankException e) {\r
+ }\r
+ catch (UnknownCdmTypeException e) {\r
logger.warn("Name with id " + nameId + " has unknown rankId " + rankId + " and could not be saved.");\r
success = false; \r
}\r
\r
} //while rs.hasNext()\r
+ logger.info(i + " names handled");\r
nameService.saveTaxonNameAll(taxonNameMap.objects());\r
\r
- \r
-// //insert related Names (Basionyms, ReplacedSyns, etc.\r
-// makeSpellingCorrections(nameMap);\r
-// makeBasionyms(nameMap);\r
-// makeLaterHomonyms(nameMap);\r
-// makeReplacedNames(nameMap);\r
-// \r
-// //insert Status infos\r
// makeNameSpecificData(nameMap);\r
- //cdmApp.flush();\r
+\r
logger.info("end makeTaxonNames ...");\r
return success;\r
} catch (SQLException e) {\r
\r
}\r
\r
+ private static Team getAuthorTeam(MapWrapper<Team> authorMap, Object teamIdObject, int nameId){\r
+ if (teamIdObject == null){\r
+ return null;\r
+ }else {\r
+ int teamId = (Integer)teamIdObject;\r
+ Team team = authorMap.get(teamId);\r
+ if (team == null){\r
+ //TODO\r
+ logger.warn("AuthorTeam (teamId = " + teamId + ") for TaxonName (nameId = " + nameId + ")"+\r
+ " was not found in authorTeam store. Relation was not set!!");\r
+ return null;\r
+ }else{\r
+ return team;\r
+ }\r
+ }\r
+ }\r
+ \r
+ \r
+ public static boolean invokeRelations(BerlinModelImportConfigurator bmiConfig, CdmApplicationController cdmApp,\r
+ MapWrapper<TaxonNameBase> nameMap, MapWrapper<ReferenceBase> referenceMap){\r
+\r
+ Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>();\r
+ Source source = bmiConfig.getSource();\r
+ String dbAttrName;\r
+ String cdmAttrName;\r
+ \r
+ logger.info("start makeNameRelationships ...");\r
+ \r
+ INameService nameService = cdmApp.getNameService();\r
+ boolean delete = bmiConfig.isDeleteAll();\r
+\r
+ try {\r
+ //get data from database\r
+ String strQuery = \r
+ " SELECT RelName.*, FromName.nameId as name1Id, ToName.nameId as name2Id " + \r
+ " FROM Name as FromName INNER JOIN " +\r
+ " RelName ON FromName.NameId = RelName.NameFk1 INNER JOIN " +\r
+ " Name AS ToName ON RelName.NameFk2 = ToName.NameId "+\r
+ " WHERE (1=1)";\r
+ ResultSet rs = source.getResultSet(strQuery) ;\r
+ \r
+ int i = 0;\r
+ //for each reference\r
+ while (rs.next()){\r
+ \r
+ if ((i++ % modCount) == 0){ logger.info("RelName handled: " + (i-1));}\r
+ \r
+ int relNameId = rs.getInt("RelNameId");\r
+ int name1Id = rs.getInt("name1Id");\r
+ int name2Id = rs.getInt("name2Id");\r
+ int relRefFk = rs.getInt("refFk");\r
+ int relQualifierFk = rs.getInt("relNameQualifierFk");\r
+ \r
+ TaxonNameBase nameFrom = nameMap.get(name1Id);\r
+ TaxonNameBase nameTo = nameMap.get(name2Id);\r
+ \r
+ //TODO\r
+ ReferenceBase citation = null;\r
+ String microcitation = null;\r
+\r
+ if (nameFrom != null && nameTo != null){\r
+ if (relQualifierFk == NAME_REL_IS_BASIONYM_FOR){\r
+ //TODO references, mikroref, etc\r
+ nameTo.setBasionym(nameFrom);\r
+ }else if (relQualifierFk == NAME_REL_IS_LATER_HOMONYM_OF){\r
+ String rule = null; //TODO\r
+ nameFrom.addRelationshipToName(nameTo, NameRelationshipType.LATER_HOMONYM(), rule) ;\r
+ //TODO reference\r
+ }else if (relQualifierFk == NAME_REL_IS_REPLACED_SYNONYM_FOR){\r
+ String rule = null; //TODO\r
+ nameFrom.addRelationshipToName(nameTo, NameRelationshipType.REPLACED_SYNONYM(), rule) ;\r
+ //TODO reference\r
+ }else if (relQualifierFk == NAME_REL_IS_TYPE_OF){\r
+ logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented");\r
+ //TODO reference\r
+ }else if (relQualifierFk == NAME_REL_IS_ORTHOGRAPHIC_VARIANT_OF){\r
+ String rule = null; //TODO\r
+ nameFrom.addRelationshipToName(nameTo, NameRelationshipType.ORTHOGRAPHIC_VARIANT(), rule) ;\r
+ //TODO reference\r
+ }else {\r
+ //TODO\r
+ logger.warn("NameRelationShipType " + relQualifierFk + " not yet implemented");\r
+ }\r
+ nameStore.add(nameFrom);\r
+ \r
+ //TODO\r
+ //Reference\r
+ //ID\r
+ //etc.\r
+ }else{\r
+ //TODO\r
+ if (nameFrom == null){\r
+ logger.warn("from TaxonName for RelName (" + relNameId + ") does not exist in store");\r
+ }\r
+ if (nameTo == null){\r
+ logger.warn("to TaxonNames for RelName (" + relNameId + ") does not exist in store");\r
+ }\r
+ }\r
+ }\r
+ logger.info("TaxonName to save: " + nameStore.size());\r
+ nameService.saveTaxonNameAll(nameStore);\r
+ \r
+ logger.info("end makeRelName ...");\r
+ return true;\r
+ } catch (SQLException e) {\r
+ logger.error("SQLException:" + e);\r
+ return false;\r
+ }\r
+\r
+ }\r
+ \r
}\r