update for Caryophallales import
authorAndreas Müller <a.mueller@bgbm.org>
Fri, 16 Nov 2012 21:21:33 +0000 (21:21 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Fri, 16 Nov 2012 21:21:33 +0000 (21:21 +0000)
app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/CaryoActivator.java
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoTaxonImport.java

index a81f511578cdd483197e337b274447d2763a7b07..3deb281ca52d81c3ca96885da7b9b764d0709807 100644 (file)
@@ -9,36 +9,26 @@
 \r
 package eu.etaxonomy.cdm.app.caryophyllales;\r
 \r
-import java.net.URI;\r
-import java.net.URISyntaxException;\r
 import java.util.UUID;\r
 \r
 import org.apache.log4j.Logger;\r
 \r
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;\r
-import eu.etaxonomy.cdm.api.service.ITermService;\r
 import eu.etaxonomy.cdm.app.berlinModelImport.SourceBase;\r
 import eu.etaxonomy.cdm.app.common.CdmDestinations;\r
 import eu.etaxonomy.cdm.database.DbSchemaValidation;\r
 import eu.etaxonomy.cdm.database.ICdmDataSource;\r
 import eu.etaxonomy.cdm.io.caryo.CaryoImportConfigurator;\r
 import eu.etaxonomy.cdm.io.common.CdmDefaultImport;\r
-import eu.etaxonomy.cdm.io.common.Source;\r
 import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;\r
-import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;\r
-import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;\r
-import eu.etaxonomy.cdm.io.cyprus.CyprusImportConfigurator;\r
-import eu.etaxonomy.cdm.io.cyprus.CyprusTransformer;\r
+import eu.etaxonomy.cdm.io.common.Source;\r
 import eu.etaxonomy.cdm.model.agent.Person;\r
-import eu.etaxonomy.cdm.model.description.Feature;\r
-import eu.etaxonomy.cdm.model.description.FeatureNode;\r
-import eu.etaxonomy.cdm.model.description.FeatureTree;\r
 import eu.etaxonomy.cdm.model.reference.Reference;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
 \r
 /**\r
  * @author a.mueller\r
- * @created 16.12.2010\r
+ * @created 16.10.2012\r
  * @version 1.0\r
  */\r
 public class CaryoActivator extends SourceBase{\r
@@ -50,15 +40,12 @@ public class CaryoActivator extends SourceBase{
 \r
        \r
        static final ICdmDataSource cdmDestination = CdmDestinations.localH2();\r
-//     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();\r
 //     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();\r
-//     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev();\r
-//     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_production();\r
-\r
+//     static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();\r
        \r
        \r
        //classification\r
-       static final UUID classificationUuid = UUID.fromString("125d7812-065b-46a2-88ee-06d6115e105e");\r
+       static final UUID classificationUuid = UUID.fromString("9edc58b5-de3b-43aa-9f31-1ede7c009c2b");\r
        \r
        //check - import\r
        static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;\r
@@ -76,8 +63,9 @@ public class CaryoActivator extends SourceBase{
                config.setCheck(check);\r
                config.setDoTaxa(doTaxa);\r
                config.setDbSchemaValidation(hbm2dll);\r
+               config.setSourceReferenceTitle("NCU - Caryophyllales, v0.4");\r
                \r
-               CdmDefaultImport myImport = new CdmDefaultImport();\r
+               CdmDefaultImport<CaryoImportConfigurator> myImport = new CdmDefaultImport<CaryoImportConfigurator>();\r
 \r
                \r
                //...\r
@@ -103,32 +91,18 @@ public class CaryoActivator extends SourceBase{
                \r
        }\r
 \r
-       private Reference getSourceReference(String string) {\r
-               Reference result = ReferenceFactory.newGeneric();\r
+       private Reference<?> getSourceReference(String string) {\r
+               Reference<?> result = ReferenceFactory.newGeneric();\r
                result.setTitleCache(string);\r
                return result;\r
        }\r
 \r
 \r
-       \r
-\r
-       //Cyprus\r
-       public static URI caryo_local() {\r
-               URI sourceUrl;\r
-               try {\r
-                       sourceUrl = new URI("file:/C:/localCopy/Data/zypern/Zypern.xls");\r
-                       return sourceUrl;\r
-               } catch (URISyntaxException e) {\r
-                       e.printStackTrace();\r
-                       return null;\r
-               }\r
-       }\r
-       \r
        public static Source caryo_len61(){\r
                //      Cyryophyllales source\r
                String dbms = Source.SQL_SERVER_2008;\r
                String strServer = "Lenovo-T61";\r
-               String strDB = "CARYOPHYLLALES";\r
+               String strDB = "caryo";\r
                int port = 1433;\r
                String userName = "WebUser";\r
                return  makeSource(dbms, strServer, strDB, port, userName, null);\r
index 114067898b7f5a77c2286a29110b7bbdb0ccc46a..80afc9812412e57fe9941f15c10ae05eec16d342 100644 (file)
@@ -16,21 +16,40 @@ import java.util.HashSet;
 import java.util.Map;\r
 import java.util.Set;\r
 \r
+import org.apache.commons.lang.StringUtils;\r
 import org.apache.log4j.Logger;\r
 import org.springframework.stereotype.Component;\r
 \r
 import eu.etaxonomy.cdm.io.common.DbImportBase;\r
 import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;\r
 import eu.etaxonomy.cdm.io.common.Source;\r
+import eu.etaxonomy.cdm.model.agent.Person;\r
+import eu.etaxonomy.cdm.model.agent.Team;\r
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
 import eu.etaxonomy.cdm.model.common.Language;\r
+import eu.etaxonomy.cdm.model.common.TimePeriod;\r
 import eu.etaxonomy.cdm.model.name.BotanicalName;\r
+import eu.etaxonomy.cdm.model.name.NameTypeDesignation;\r
+import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;\r
+import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;\r
 import eu.etaxonomy.cdm.model.name.Rank;\r
+import eu.etaxonomy.cdm.model.reference.IArticle;\r
+import eu.etaxonomy.cdm.model.reference.IBook;\r
+import eu.etaxonomy.cdm.model.reference.IBookSection;\r
+import eu.etaxonomy.cdm.model.reference.IJournal;\r
+import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;\r
 import eu.etaxonomy.cdm.model.reference.Reference;\r
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;\r
 import eu.etaxonomy.cdm.model.taxon.Classification;\r
+import eu.etaxonomy.cdm.model.taxon.Synonym;\r
+import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
+import eu.etaxonomy.cdm.strategy.cache.name.BotanicNameDefaultCacheStrategy;\r
+import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;\r
+import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;\r
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;\r
 \r
 \r
 /**\r
@@ -45,25 +64,23 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
        private int modCount = 10000;\r
        private static final String pluralString = "taxa";\r
        private static final String dbTableName = "CARYOPHYLLALES";\r
-       private static final String FAMILY = "Family";\r
-       private static final String PERSON = "Person";\r
-       private static final String TEAM = "Team";\r
-       private static final String JOURNAL = "Journal";\r
-       private static final String BOOK = "Book";\r
+\r
 \r
        \r
        private Map<String, Taxon> familyMap = new HashMap<String, Taxon>();\r
-       private Map<String, TeamOrPersonBase> personMap = new HashMap<String, TeamOrPersonBase>();\r
-       private Map<String, TeamOrPersonBase> teamMap = new HashMap<String, TeamOrPersonBase>();\r
-       private Map<String, Reference> journalMap = new HashMap<String, Reference>();\r
-       private Map<String, Reference> bookMap = new HashMap<String, Reference>();\r
+       private Map<String, Person> personMap = new HashMap<String, Person>();\r
+       private Map<String, Team> teamMap = new HashMap<String, Team>();\r
+       private Map<String, TeamOrPersonBase> inAuthorMap = new HashMap<String, TeamOrPersonBase>();\r
+       private Map<String, IJournal> journalMap = new HashMap<String, IJournal>();\r
+       private Map<String, IBook> bookMap = new HashMap<String, IBook>();\r
        \r
        \r
        private Classification classification;\r
 \r
        \r
+       \r
        public CaryoTaxonImport(){\r
-               super(pluralString, dbTableName);\r
+               super(dbTableName, pluralString);\r
        }\r
 \r
        \r
@@ -76,7 +93,8 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
        protected String getIdQuery(CaryoImportState state) {\r
                String strRecordQuery = \r
                        " SELECT ID " + \r
-                       " FROM " + dbTableName; \r
+                       " FROM " + dbTableName +\r
+                       " ORDER BY id "; \r
                return strRecordQuery;  \r
        }\r
 \r
@@ -87,7 +105,7 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
        @Override\r
        protected String getRecordQuery(CaryoImportConfigurator config) {\r
                String strRecordQuery = \r
-                       " SELECT cs.* " + \r
+                       " SELECT t.* " + \r
                        " FROM " + getTableName() + " t " +\r
                        " WHERE ( t.ID IN (" + ID_LIST_TOKEN + ") )";\r
                return strRecordQuery;\r
@@ -112,49 +130,62 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
                try {\r
                        doFamilies(state);\r
                        doAuthors(state);\r
+                       doInAuthors(state);\r
                        doJournals(state);\r
                        doBooks(state);\r
                        \r
                        ResultSet rs = partitioner.getResultSet();\r
                        \r
                        int i = 0;\r
+               Reference<?> sec = state.getTransactionalSourceReference();\r
 \r
                        //for each reference\r
             while (rs.next()){\r
                 \r
                        if ((i++ % modCount) == 0 && i!= 1 ){ logger.info(pluralString + " handled: " + (i-1));}\r
                                \r
-                       Integer taxonId = rs.getInt("IDcurrentspec");\r
-                       \r
-                       \r
-                       //String dtSpcJahr -> ignore !\r
-                       //empty: fiSpcLiteratur\r
-                       \r
-                       //TODO\r
-                       //fiSpcspcgrptax\r
-                       \r
-               \r
+                       Integer id = rs.getInt("Id");\r
+                       Integer taxonId = rs.getInt("NCUGenID");\r
+                       String genus = rs.getString("Genus");\r
+                       String family = rs.getString("Family");\r
+                               String pages = rs.getString("Pages");\r
+                               String autoren = rs.getString("Autoren");\r
+                               String typeStr = rs.getString("Type");\r
+                               String nomStatusStr = rs.getString("NomenclaturalStatus");\r
+                               String basioStr = rs.getString("Basionym");\r
+                               \r
+//                   ,[EtInCitation]\r
+//                   ,[Gender]\r
+                               \r
+//                   ,[Basionym]\r
+//                   ,[OriginalCitation]\r
+                               \r
                        \r
-                               try {\r
-                                       \r
-                                       \r
-//                                     classification.addParentChild(nextHigherTaxon, species, sourceRef, null);\r
-//                                     \r
-//                                     \r
-//                                     this.doIdCreatedUpdatedNotes(state, species, rs, taxonId, TAXON_NAMESPACE);\r
-//                                     \r
-//                                     objectsToSave.add(species); \r
-                                       \r
+                               BotanicalName name = BotanicalName.NewInstance(Rank.GENUS());\r
+                               name.setGenusOrUninomial(genus);\r
+                               makeAuthors(name, autoren, id);\r
+                               INomenclaturalReference nomRef = makeNomRef(state, rs, id);\r
+                       name.setNomenclaturalReference(nomRef);\r
+                               name.setNomenclaturalMicroReference(pages);\r
+                               makeStatus(name, nomStatusStr, id);\r
+                               \r
+                               \r
+                               Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());\r
+                               handleTypes(state, rs, taxon, typeStr, id);\r
+                               handleBasionym(state, rs, taxon, basioStr, id);\r
+                               \r
+                               Taxon parent = familyMap.get(family);\r
+                               \r
+                               classification.addParentChild(parent, taxon, sec, null);\r
+                               \r
+                               taxon.addSource(String.valueOf(taxonId), "NCUGenID", sec, null);\r
+                               \r
+                               \r
+                               \r
+                               objectsToSave.add(taxon);\r
 \r
-                               } catch (Exception e) {\r
-                                       logger.warn("Exception in current_species: IDcurrentspec " + taxonId + ". " + e.getMessage());\r
-//                                     e.printStackTrace();\r
-                               } \r
-                \r
             }\r
            \r
-//            logger.warn("Specimen: " + countSpecimen + ", Descriptions: " + countDescriptions );\r
-\r
                        logger.warn(pluralString + " to save: " + objectsToSave.size());\r
                        getTaxonService().save(objectsToSave);  \r
                        \r
@@ -165,31 +196,545 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
                }\r
        }\r
 \r
+       \r
+       private INonViralNameParser parser = NonViralNameParserImpl.NewInstance();\r
+       private void handleBasionym(CaryoImportState state, ResultSet rs, Taxon taxon, String basioStr, Integer id) {\r
+               if (StringUtils.isNotBlank(basioStr)){\r
+                       BotanicalName name = (BotanicalName) taxon.getName();\r
+                       BotanicalName basionym = BotanicalName.PARSED_NAME(basioStr);\r
+                       name.addBasionym(basionym);\r
+                       Synonym syn = Synonym.NewInstance(basionym, state.getTransactionalSourceReference());\r
+                       taxon.addSynonym(syn, SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF());\r
+                       getTaxonService().save(syn);\r
+               }\r
+               \r
+       }\r
+\r
+\r
+\r
+\r
+       private void handleTypes(CaryoImportState state, ResultSet rs, Taxon taxon, String origType, Integer id) {\r
+               NameTypeDesignation desig = NameTypeDesignation.NewInstance();\r
+               String type = origType;\r
+               if (StringUtils.isBlank(type) ){\r
+                       return;\r
+               }else{\r
+                       BotanicalName name = (BotanicalName)taxon.getName();\r
+                       BotanicalName typeName = BotanicalName.NewInstance(Rank.SPECIES());\r
+                       if ("not designated".equalsIgnoreCase(type)){\r
+                               desig.setNotDesignated(true);\r
+                       }else{\r
+                               String genus = name.getGenusOrUninomial();\r
+                               typeName.setGenusOrUninomial(genus);\r
+                               if (! type.startsWith(genus.substring(0,1) + ". " )){\r
+                                       int i = type.indexOf(" ");\r
+                                       String genusOrig = type.substring(0, i);\r
+                                       logger.warn("First genus letter not recognized: " + genusOrig + "-" + genus + ":"+  id);\r
+                                       typeName.setGenusOrUninomial(genusOrig);\r
+                                       type = type.substring(i + 1).trim();\r
+                               }else{\r
+                                       type = type.substring(3);\r
+                               }\r
+                               int i = type.indexOf(" ");\r
+                               if (i <= 0){\r
+                                       logger.warn("No space: " + type +"; " + id);\r
+                               }else{\r
+                                       String species = type.substring(0, i);\r
+                                       typeName.setSpecificEpithet(species);\r
+                                       type = type.substring(i + 1).trim();\r
+                                       \r
+                                       int posBracket = type.indexOf("(", 2);\r
+                                       if (posBracket > 0){\r
+                                               String bracket = type.substring(posBracket);\r
+                                               //TODO\r
+//                                             logger.warn("Type has bracket("+id+"): " + bracket);\r
+                                               //TODO Annotation\r
+                                               type = type.substring(0, posBracket).trim();\r
+                                       }\r
+                                       type = makeTypeNomStatus(typeName, type);\r
+\r
+                                       \r
+                                       makeAuthors(typeName, type, id);\r
+                               }\r
+                                       \r
+                               desig.setTypeName(typeName);\r
+                       }\r
+                       name.addTypeDesignation(desig, true);\r
+               }\r
+               \r
+               \r
+       }\r
+\r
+\r
+\r
+\r
+       private String makeTypeNomStatus(BotanicalName typeName, String type) {\r
+               if (type.endsWith(", nom. illeg.")){\r
+                       type = type.replaceAll(", nom. illeg.", "");\r
+                       typeName.addStatus(NomenclaturalStatus.NewInstance(NomenclaturalStatusType.ILLEGITIMATE()));\r
+               }\r
+               return type;\r
+       }\r
+\r
+\r
+\r
+\r
+       private void makeStatus(BotanicalName name, String nomStatusStr, Integer id) throws SQLException {\r
+//           ,[NomenclaturalStatus]\r
+               \r
+               if (StringUtils.isNotBlank(nomStatusStr)){\r
+                       NomenclaturalStatusType nomStatusType;\r
+                       try {\r
+                               nomStatusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(nomStatusStr);\r
+                       } catch (UnknownCdmTypeException e) {\r
+                               if (nomStatusStr.startsWith("nom. rej. prop.")){\r
+                                       nomStatusType = NomenclaturalStatusType.REJECTED_PROP();\r
+                                       logger.warn("in favour not supported ("+id+"): " + nomStatusStr);\r
+                               }else if (nomStatusStr.startsWith("nom. rej. in favour")){\r
+                                       nomStatusType = NomenclaturalStatusType.REJECTED();\r
+                                       logger.warn("in favour not supported ("+id+"): " + nomStatusStr);\r
+                               }else if (nomStatusStr.startsWith("nom. cons. against")){\r
+                                       nomStatusType = NomenclaturalStatusType.CONSERVED();\r
+                                       logger.warn("against not supported ("+id+"): " + nomStatusStr);\r
+                               }else if (nomStatusStr.startsWith("nom. cons. prop. against")){\r
+                                       nomStatusType = NomenclaturalStatusType.CONSERVED_PROP();\r
+                                       logger.warn("against not supported ("+id+"): " + nomStatusStr);\r
+                               }else{\r
+                                       logger.warn("Unknown status type ("+id+"): " + nomStatusStr);\r
+                                       nomStatusType = NomenclaturalStatusType.DOUBTFUL();\r
+                               }\r
+                       }\r
+                       \r
+                       NomenclaturalStatus status = NomenclaturalStatus.NewInstance(nomStatusType);\r
+                       name.addStatus(status);\r
+               }\r
+               \r
+       }\r
+\r
+\r
+\r
+\r
+       private INomenclaturalReference makeNomRef(CaryoImportState state, ResultSet rs, Integer id) throws SQLException {\r
+               INomenclaturalReference result;\r
+               String periodicalTitle = rs.getString("PeriodicalTitle");\r
+               String volume = rs.getString("PeriodicalVolume");\r
+               String bookTitle = rs.getString("BookTitle");\r
+               String inAutorStr = rs.getString("InAutor");\r
+               String autorenStr = rs.getString("Autoren");\r
+               \r
+               TeamOrPersonBase<?> author = getNomRefAuthor(autorenStr, id);\r
+               if (StringUtils.isNotBlank(periodicalTitle)){\r
+                       IJournal journal = journalMap.get(periodicalTitle);\r
+                       if (journal == null){\r
+                               logger.warn("Journal not found: " + periodicalTitle + ";" + id);\r
+                       }\r
+                       IArticle article = ReferenceFactory.newArticle();\r
+                       article.setInJournal(journal);\r
+                       article.setVolume(volume);\r
+                       result = article;\r
+               }else if (StringUtils.isNotBlank(bookTitle)){\r
+                       IBook book = bookMap.get(bookTitle);\r
+                       if (inAutorStr != null){\r
+                               IBookSection section = ReferenceFactory.newBookSection();\r
+                               section.setInBook(book);\r
+                               TeamOrPersonBase<?> inAuthor = getInAuthor(inAutorStr);\r
+                               book.setAuthorTeam(inAuthor);\r
+                               result = section;\r
+                       }else{\r
+                               result = book;\r
+                       }\r
+               }else{\r
+                       logger.warn("No nomRef found: " +  id);\r
+                       result = null;\r
+               }\r
+               if (result != null){\r
+                       result.setAuthorTeam(author);\r
+                       makeDate(state, rs, result, id);\r
+               }\r
+               return result;\r
+       }\r
+\r
+       private void makeDate(CaryoImportState state, ResultSet rs, INomenclaturalReference ref, Integer id) throws SQLException {\r
+               TimePeriod tp = TimePeriod.NewInstance();\r
+               String pre1 = rs.getString("DatePre1");\r
+               String pre2 = rs.getString("DatePre2");\r
+               Float year1 = nullSafeFloat(rs, "DateYear1");\r
+               Float year2 = nullSafeFloat(rs, "DateYear2");\r
+               if (year2 == 0.0 ){\r
+                       year2 = null;\r
+               }\r
+               String modi1 = rs.getString("DateModi1");\r
+               String modi2 = rs.getString("DateModi2");\r
+               String date = rs.getString("Date");\r
+\r
+               tp.setStartYear(year1.intValue());\r
+               Integer[] preDate1 = getDay(pre1,id);\r
+               tp.setStartMonth(preDate1[1]);\r
+               tp.setStartDay(preDate1[0]);\r
+               if (year2 != null){\r
+                       tp.setEndYear(year2.intValue());\r
+               }\r
+               Integer[] preDate2 = getDay(pre2, id);\r
+               tp.setEndMonth(preDate2[1]);\r
+               tp.setEndDay(preDate2[0]);\r
+               \r
+               if (StringUtils.isNotBlank(modi1) || StringUtils.isNotBlank(modi2)){\r
+                       tp.setFreeText(date);\r
+               }\r
+               ref.setDatePublished(tp);\r
+       }\r
+\r
+\r
+\r
+\r
+       private Integer[] getDay(String pre, Integer id) {\r
+               Integer[] result = new Integer[2];\r
+               if (! StringUtils.isBlank(pre)){\r
+                       try {\r
+                               String[] split = pre.split("\\s");\r
+                               String monthStr;\r
+                               if (split.length > 2){\r
+                                       logger.warn("L > 2: " + pre);\r
+                                       monthStr = "";\r
+                               }else if(split.length == 2){\r
+                                       result[0] = Integer.valueOf(split[0]);\r
+                                       monthStr = split[1];\r
+                               }else{\r
+                                       monthStr = split[0];\r
+                               }\r
+                               Integer month;\r
+                               if ("Jan".equalsIgnoreCase(monthStr)){\r
+                                       month = 1;\r
+                               }else if ("Feb".equalsIgnoreCase(monthStr)){\r
+                                       month = 2;\r
+                               }else if ("Mar".equalsIgnoreCase(monthStr)){\r
+                                       month = 3;\r
+                               }else if ("Apr".equalsIgnoreCase(monthStr)){\r
+                                       month = 4;\r
+                               }else if ("Mai".equalsIgnoreCase(monthStr)){\r
+                                       month = 5;\r
+                               }else if ("Jun".equalsIgnoreCase(monthStr)){\r
+                                       month = 6;\r
+                               }else if ("Jul".equalsIgnoreCase(monthStr)){\r
+                                       month = 7;\r
+                               }else if ("Aug".equalsIgnoreCase(monthStr)){\r
+                                       month = 8;\r
+                               }else if ("Sep".equalsIgnoreCase(monthStr)){\r
+                                       month = 9;\r
+                               }else if ("Oct".equalsIgnoreCase(monthStr)){\r
+                                       month = 10;\r
+                               }else if ("Nov".equalsIgnoreCase(monthStr)){\r
+                                       month = 11;\r
+                               }else if ("Dec".equalsIgnoreCase(monthStr)){\r
+                                       month = 12;\r
+                               }else{\r
+                                       logger.warn("Unknown month ("+id+"): " + monthStr );\r
+                                       month = null;\r
+                               }\r
+                               result[1]= month;\r
+                       } catch (Exception e) {\r
+                               e.printStackTrace();\r
+                       }\r
+               }\r
+               return result;\r
+       }\r
+\r
+       \r
+       private TeamOrPersonBase<?> getInAuthor(String inAutorStr) {\r
+               if (StringUtils.isBlank(inAutorStr)){\r
+                       return null;\r
+               }\r
+               TeamOrPersonBase<?> inAuthor = inAuthorMap.get(inAutorStr);\r
+               if (inAuthor == null){\r
+                       logger.warn("Inauthor not found: " +  inAutorStr);\r
+               }\r
+               return inAuthor;\r
+       }\r
+\r
 \r
 \r
+       private void makeAuthors(BotanicalName name, String autoren, Integer id) {\r
+               String[] parsedAuthorTeams = getParsedAuthors(autoren);\r
+               name.setBasionymAuthorTeam(getTeam(parsedAuthorTeams[0], id));\r
+               name.setExBasionymAuthorTeam(getTeam(parsedAuthorTeams[1], id));\r
+               name.setCombinationAuthorTeam(getTeam(parsedAuthorTeams[2], id));\r
+               name.setExCombinationAuthorTeam(getTeam(parsedAuthorTeams[3], id));\r
+               \r
+       }\r
+       \r
+       private TeamOrPersonBase<?> getNomRefAuthor(String authorStr, Integer id) {\r
+               String[] parsedAuthorTeams = getParsedAuthors(authorStr);\r
+               TeamOrPersonBase<?> team = getTeam(parsedAuthorTeams[2], id);\r
+               return team;\r
+       }\r
 \r
 \r
+       private TeamOrPersonBase<?> getTeam(String author, Integer id) {\r
+               if (StringUtils.isBlank(author)){\r
+                       return null;\r
+               }\r
+               TeamOrPersonBase<?> result;\r
+               if (personMap.get(author) != null){\r
+                       result = personMap.get(author);\r
+               }else{\r
+                       result = teamMap.get(author);\r
+               }\r
+               if (result == null){\r
+                       logger.warn("Team not found ("+id+"): " + author);\r
+               }\r
+               return result;\r
+       }\r
+       \r
 \r
+       private void doInAuthors(CaryoImportState state) throws SQLException {\r
+               Source source = state.getConfig().getSource();\r
+               String sql = "SELECT DISTINCT inAutor FROM " + getTableName() + " WHERE inAutor IS NOT NULL AND inAutor <> '' ";\r
+               ResultSet rs = source.getResultSet(sql);\r
+               while (rs.next()){\r
+                       String inAutorStr = rs.getString("inAutor");\r
+                       if (inAuthorMap.get(inAutorStr) == null){\r
+                               Team team = Team.NewTitledInstance(inAutorStr, inAutorStr);\r
 \r
-       private void doAuthors(CaryoImportState state) {\r
-               // TODO Auto-generated method stub\r
+                               inAuthorMap.put(inAutorStr, team);\r
+                               getAgentService().save(team);\r
+                       }\r
+               }\r
                \r
        }\r
 \r
 \r
+       private void doAuthors(CaryoImportState state) throws SQLException {\r
+               Source source = state.getConfig().getSource();\r
+               String sql = "SELECT DISTINCT Autoren FROM " + getTableName() + " WHERE Autoren IS NOT NULL AND Autoren <> '' ";\r
+               ResultSet rs = source.getResultSet(sql);\r
+               doTypeAuthors(state);\r
+               while (rs.next()){\r
+                       String autorenStr = rs.getString("Autoren");\r
+                       String[] parsedAuthorTeams = getParsedAuthors(autorenStr);\r
+                       for (String teamStr : parsedAuthorTeams){\r
+                               doTeam(teamStr);\r
+                       }\r
+               }\r
+       }\r
+\r
 \r
 \r
-       private void doBooks(CaryoImportState state) {\r
-               // TODO Auto-generated method stub\r
+\r
+       private void doTypeAuthors(CaryoImportState state) {\r
+               doTeam("Dinter & Derenb.");\r
+               doTeam("Marloth");\r
+               doTeam("Engl.");\r
+               doTeam("Kensit");\r
+               doTeam("Sond.");\r
+               doTeam("L. f.");\r
+               doTeam("Dinter & A. Berger");\r
+               doTeam("Schltr.");\r
+               doTeam("Dinter & Berger");\r
+               doTeam("Poir.");\r
+               doTeam("J. C. Wendl.");\r
+               doTeam("Baker & Clarke");\r
+               doTeam("Vahl");\r
+               doTeam("Nicolai");\r
+               doTeam("Gürke");\r
+               doTeam("Cels");\r
+               doTeam("Dams");\r
+               doTeam("Coult.");\r
+               doTeam("A. Weber");\r
+               doTeam("Vaupel");\r
+               doTeam("Gay");\r
+               doTeam("Pall.");\r
+               doTeam("Moq. & Coss.");\r
+               doTeam("Durieu & Moq.");\r
+               doTeam("Lag. & Rodrigues");\r
+               doTeam("M. Martens & Galeotti");\r
+               doTeam("Steud.");\r
+               doTeam("Aitch. & Hemsl.");\r
+               doTeam("Ikonn.-Gal.");\r
+               doTeam("Freitag");\r
+               doTeam("Regel");\r
+               doTeam("Ledeb.");\r
+               doTeam("Schur");\r
+               doTeam("Asch.");\r
+               doTeam("G. Forst.");\r
+               doTeam("Gray");\r
+               doTeam("Curran");\r
+               doTeam("Donn. Sm.");\r
+               doTeam("Diels");\r
+               doTeam("Colla");\r
+               doTeam("Miers");\r
+               doTeam("Gillis");\r
+               doTeam("Royle");\r
+               doTeam("Monv.");\r
+               doTeam("Werderm. & Backeb.");\r
+               doTeam("Wright");\r
+               doTeam("Meyen");\r
+               doTeam("Runge");\r
+               doTeam("Böd.");\r
+               doTeam("Rol.-Goss.");\r
+               doTeam("Poselg.");\r
+               doTeam("Andreae & Backeberg");\r
+               doTeam("Miq.");\r
+               doTeam("Rol.");\r
+               doTeam("Backeb. & Voll");\r
+               doTeam("Engelm. & Bigelow");\r
+               doTeam("Pfeiffer & Otto");\r
+               doTeam("Humb. & Bonpl.");\r
+               doTeam("Schmalh.");\r
+               doTeam("Preobr.");\r
+               doTeam("Labill.");\r
+               doTeam("Barkoudah");\r
+               doTeam("Regel & Schmalh.");\r
+               doTeam("Cambess.");\r
+               doTeam("Pax & K. Hoff.");\r
+               doTeam("Bergeret");\r
+               doTeam("Walp.");\r
+               doTeam("Huds.");\r
+               doTeam("Kit.");\r
+               doTeam("Schott, Nymann & Kotschy");\r
+               doTeam("Boiss. & Buhse");\r
+               doTeam("Medik.");\r
+               doTeam("Coss. & Germ.");\r
+               doTeam("Moss");\r
+               doTeam("Pax & Hoffm.");\r
+               doTeam("Schischk.");\r
+               doTeam("Lipsch.");\r
+               doTeam("Maerkl.");\r
+               doTeam("Vierh.");\r
+               doTeam("Exell");\r
                \r
        }\r
 \r
 \r
 \r
 \r
-       private void doJournals(CaryoImportState state) {\r
-               // TODO Auto-generated method stub\r
+       /**\r
+        * @param teamStr\r
+        * @return\r
+        */\r
+       protected void doTeam(String teamStr) {\r
+               if (StringUtils.isBlank(teamStr)){\r
+                       return;\r
+               }\r
+               String[] parsedTeam = parseTeam(teamStr);\r
+               if (parsedTeam.length == 1){\r
+                       savePerson(parsedTeam[0]);\r
+               }else{\r
+                       Team team = teamMap.get(teamStr);\r
+                       if (team == null){\r
+                               team = Team.NewInstance();\r
+                               for (String member : parsedTeam){\r
+                                       Person person = savePerson(member);\r
+                                       team.addTeamMember(person);\r
+                               }\r
+                               teamMap.put(teamStr, team);\r
+                               getAgentService().saveOrUpdate(team);\r
+                       }\r
+               }\r
+               return;\r
+       }\r
+\r
+       private String[] parseTeam(String teamStr) {\r
+               String[] split = teamStr.split("[&,]");\r
+               for (int i = 0; i < split.length; i++){\r
+                       split[i] = split[i].trim();\r
+               }\r
+               return split;\r
+       }\r
+\r
+       private Person savePerson(String personStr) {\r
+               Person result = personMap.get(personStr);\r
+               if (result == null ){\r
+                       Person person = Person.NewTitledInstance(personStr);\r
+                       personMap.put(personStr, person);\r
+                       getAgentService().save(person);\r
+                       result = person;\r
+               }\r
+               return result;\r
+       }\r
+\r
+\r
+\r
+\r
+       private String[] getParsedAuthors(String autorenStr) {\r
+               String[] result = new String[4]; \r
+               String basioFull = null;\r
+               String origFull;\r
+\r
+                       String[]  split = autorenStr.split("\\)");\r
+               if (split.length > 1){\r
+                       basioFull = split[0].replace("(", "").trim();\r
+                       origFull = split[1].trim();\r
+               }else{\r
+                       origFull = split[0].trim();\r
+               }\r
+               String[] splitBasio = splitExAuthors(basioFull);\r
+               String[] splitOrig = splitExAuthors(origFull);\r
+               result[0] = splitBasio[0];\r
+               result[1] = splitBasio[1];\r
+               result[2] = splitOrig[0];\r
+               result[3] = splitOrig[1];\r
                \r
+               return result;\r
+       }\r
+\r
+\r
+\r
+\r
+       private String[] splitExAuthors(String author) {\r
+               String[] result = new String[2]; \r
+               if (author != null){\r
+                       String[]  split = author.split("\\sex\\s");\r
+                       if (split.length > 1){\r
+                               //TODO richtige Reihenfolge ?\r
+                               result[0] = split[1].trim();\r
+                               result[1] = split[0].trim();\r
+                       }else{\r
+                               result[0] = split[0].trim();\r
+                       }\r
+               }\r
+               return result;\r
+       }\r
+\r
+\r
+\r
+\r
+       private void doBooks(CaryoImportState state) throws SQLException {\r
+               Source source = state.getConfig().getSource();\r
+               String sql = "SELECT DISTINCT BookTitle FROM " + getTableName() + " WHERE BookTitle IS NOT NULL AND BookTitle <> '' ";\r
+               ResultSet rs = source.getResultSet(sql);\r
+               while (rs.next()){\r
+                       String bookStr = rs.getString("BookTitle");\r
+                       if (bookMap.get(bookStr) == null ){\r
+                               \r
+                               IBook book = ReferenceFactory.newBook(); \r
+\r
+                               book.setTitle(bookStr);\r
+                               \r
+                               bookMap.put(bookStr, book);\r
+                               getReferenceService().save((Reference<?>)book);\r
+                       }\r
+               }\r
+       }\r
+\r
+\r
+\r
+\r
+       private void doJournals(CaryoImportState state) throws SQLException {\r
+               Source source = state.getConfig().getSource();\r
+               String sqlPeriodical = "SELECT DISTINCT PeriodicalTitle FROM " + getTableName() + " WHERE PeriodicalTitle IS NOT NULL AND PeriodicalTitle <> '' ";\r
+               ResultSet rs = source.getResultSet(sqlPeriodical);\r
+               while (rs.next()){\r
+                       String periodical = rs.getString("PeriodicalTitle");\r
+                       if (journalMap.get(periodical) == null ){\r
+                               \r
+                               Reference<?> journal = ReferenceFactory.newJournal(); \r
+\r
+                               journal.setTitle(periodical);\r
+                               \r
+                               journalMap.put(periodical, journal);\r
+                               getReferenceService().save(journal);\r
+                       }\r
+               }\r
        }\r
 \r
 \r
@@ -197,18 +742,21 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
 \r
        private void doFamilies(CaryoImportState state) throws SQLException {\r
                Source source = state.getConfig().getSource();\r
-               String sqlFamily = "SELECT DISTINCT family FROM table WHERE family IS NOT NULL";\r
+               String sqlFamily = "SELECT DISTINCT Family FROM " + getTableName() + " WHERE Family IS NOT NULL";\r
                ResultSet rs = source.getResultSet(sqlFamily);\r
                while (rs.next()){\r
                        String family = rs.getString("family");\r
-                       BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());\r
-                       name.setGenusOrUninomial(family);\r
-                       Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());\r
-                       classification.addChildTaxon(taxon, null, null, null);\r
-//                     taxon.addSource(id, idNamespace, citation, null);\r
-                       \r
-                       \r
-                       familyMap.put(family, taxon);\r
+                       if (familyMap.get(family) == null ){\r
+                               \r
+                               BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());\r
+                               name.setGenusOrUninomial(family);\r
+                               Taxon taxon = Taxon.NewInstance(name, state.getTransactionalSourceReference());\r
+                               classification.addChildTaxon(taxon, null, null, null);\r
+       //                      taxon.addSource(id, idNamespace, citation, null);\r
+                               \r
+                               familyMap.put(family, taxon);\r
+                               getTaxonService().save(taxon);\r
+                       }\r
                }\r
                \r
        }\r
@@ -224,7 +772,6 @@ public class CaryoTaxonImport  extends DbImportBase<CaryoImportState, CaryoImpor
                        getClassificationService().save(classification);\r
                }\r
                return this.classification;\r
-               \r
        }\r
 \r
 \r