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