--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2022 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.app.mexico;
+
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.app.common.CdmDestinations;
+import eu.etaxonomy.cdm.common.URI;
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
+import eu.etaxonomy.cdm.io.mexico.MexicoConabioTransformer;
+import eu.etaxonomy.cdm.io.mexico.MexicoEfloraImportConfigurator;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
+
+/**
+ * See #9932.
+ *
+ * @author a.mueller
+ * @date 29.01.2022
+ */
+public class MexicoEfloraActivator {
+
+ private static final Logger logger = Logger.getLogger(MexicoBorhidiActivator.class);
+
+ //database validation status (create, update, validate ...)
+ static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
+
+ //static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
+ static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
+
+ //feature tree uuid
+ public static final UUID featureTreeUuid = UUID.fromString("7cfa2122-043d-4e96-922c-356fc04d68a3");
+
+ //classification
+ static final UUID classificationUuid = UUID.fromString("28abf7da-e0ad-48ca-b26c-9f276dd90267");
+ private static final String classificationName = "Mexico Eflora";
+
+ //check - import
+ static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
+
+ boolean doVocabularies = (hbm2dll == DbSchemaValidation.CREATE);
+// static final boolean doTaxa = false;
+// static final boolean doDeduplicate = true;
+
+ protected void doImport(ICdmDataSource cdmDestination){
+
+ URI source = borhidi();
+
+ //make Source
+ MexicoEfloraImportConfigurator config= MexicoEfloraImportConfigurator.NewInstance(source, cdmDestination);
+ config.setClassificationUuid(classificationUuid);
+ config.setClassificationName(classificationName);
+ config.setCheck(check);
+ config.setDbSchemaValidation(hbm2dll);
+ config.setSecReference(getSecReference());
+
+ config.setSource(source);
+ String fileName = source.toString();
+ fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
+
+ String message = "Start import from ("+ fileName + ") ...";
+ System.out.println(message);
+ logger.warn(message);
+
+ config.setSourceReference(getSourceReference());
+
+ CdmDefaultImport<MexicoEfloraImportConfigurator> myImport = new CdmDefaultImport<>();
+
+ myImport.invoke(config);
+
+ System.out.println("End import from ("+ source.toString() + ")...");
+
+ }
+
+
+ //Mexico eflora
+ public static URI borhidi() {
+ return URI.create("file:////BGBM-PESIHPC/Mexico/Borhidi_2012.xlsx");
+ }
+
+
+ private Reference getSourceReference() {
+ Reference result = ReferenceFactory.newDatabase();
+ result.setTitle("CONABIO Eflora");
+// Person borhidi = Person.NewTitledInstance("Borhidi");
+// borhidi.setGivenName("Attila");
+// result.setAuthorship(borhidi);
+ return result;
+ }
+
+ private Reference getSecReference() {
+ Reference result = ReferenceFactory.newBook();
+ result.setTitle("Mexico Eflora");
+ //TODO
+ result.setUuid(MexicoConabioTransformer.uuidReferenceEflora);
+ return result;
+ }
+
+ public static void main(String[] args) {
+ MexicoBorhidiActivator me = new MexicoBorhidiActivator();
+ me.doImport(cdmDestination);
+ System.exit(0);
+ }
+}
--- /dev/null
+// $Id$
+/**
+* Copyright (C) 2022 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.cdm.app.mexico;
+
+/**
+ * @author a.mueller
+ * @date 29.01.2022
+ *
+ */
+public class MexicoEfloraReferencesActivator {
+
+}
private static final Logger logger = Logger.getLogger(MexicoConabioTransformer.class);
+ public static UUID uuidReferenceEflora = UUID.fromString("0a04f189-b014-41b3-8a59-40f2f56a3087");
+
+
public static UUID uuidReferenceBorhidi = UUID.fromString("f76a535b-a1fd-437c-a09d-f94eddae2b5e");
-// public static UUID uuidReferenceConabio = UUID.fromString("7183652f-d7ca-45a7-9383-265996d3d10f");
+ // public static UUID uuidReferenceConabio = UUID.fromString("7183652f-d7ca-45a7-9383-265996d3d10f");
public static UUID uuidReferenceConabio2 = UUID.fromString("292d0470-74b1-4419-84c5-0315a3bfe643");
public static final UUID uuidConabioIdIdentifierType = UUID.fromString("025fb8fe-e8e8-4136-bf37-93367a268889");
--- /dev/null
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.mexico;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+import org.joda.time.DateTime;
+
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
+import eu.etaxonomy.cdm.io.common.DbImportBase;
+import eu.etaxonomy.cdm.io.common.ICdmIO;
+import eu.etaxonomy.cdm.io.common.IPartitionedIO;
+import eu.etaxonomy.cdm.model.common.IdentifiableSource;
+import eu.etaxonomy.cdm.model.reference.ISourceable;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+
+/**
+ * @author a.mueller
+ * @since 20.03.2008
+ */
+public abstract class MexicoEfloraImportBase
+ extends DbImportBase<MexicoEfloraImportState, MexicoEfloraImportConfigurator>
+ implements ICdmIO<MexicoEfloraImportState>, IPartitionedIO<MexicoEfloraImportState> {
+
+ private static final long serialVersionUID = -5229728676004248450L;
+ private static final Logger logger = Logger.getLogger(MexicoEfloraImportBase.class);
+
+ public MexicoEfloraImportBase(String tableName, String pluralString ) {
+ super(tableName, pluralString);
+ }
+
+ @Override
+ protected String getIdQuery(BerlinModelImportState state){
+ String result = " SELECT " + getTableName() + "id FROM " + getTableName();
+ return result;
+ }
+
+ //can be overriden
+ protected String getIdInSource(BerlinModelImportState state, ResultSet rs) throws SQLException {
+ return null;
+ }
+
+ private DateTime getDateTime(Object timeString){
+ if (timeString == null){
+ return null;
+ }
+ DateTime dateTime = null;
+ if (timeString instanceof Timestamp){
+ Timestamp timestamp = (Timestamp)timeString;
+ dateTime = new DateTime(timestamp);
+ }else{
+ logger.warn("time ("+timeString+") is not a timestamp. Datetime set to current date. ");
+ dateTime = new DateTime();
+ }
+ return dateTime;
+ }
+
+
+ protected Taxon getTaxon(BerlinModelImportState state, int taxonId, Map<String, TaxonBase> taxonMap, int factId) {
+ TaxonBase<?> taxonBase = taxonMap.get(String.valueOf(taxonId));
+
+ //TODO for testing
+// if (taxonBase == null && ! state.getConfig().isDoTaxa()){
+// taxonBase = Taxon.NewInstance(TaxonNameFactory.NewBotanicalInstance(Rank.SPECIES()), null);
+// }
+
+ Taxon taxon;
+ if ( taxonBase instanceof Taxon ) {
+ taxon = (Taxon) taxonBase;
+ } else if (taxonBase != null) {
+ logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " was not of type Taxon but: " + taxonBase.getClass().getSimpleName());
+ return null;
+ } else {
+ logger.warn("TaxonBase (" + taxonId + ") for Fact(Specimen) with factId " + factId + " is null.");
+ return null;
+ }
+ return taxon;
+ }
+
+
+ /**
+ * Searches first in the detail maps then in the ref maps for a reference.
+ * Returns the reference as soon as it finds it in one of the map, according
+ * to the order of the map.
+ * If nomRefDetailFk is <code>null</code> no search on detail maps is performed.
+ * If one of the maps is <code>null</code> no search on the according map is
+ * performed. <BR>
+ * You may define the order of search by the order you pass the maps but
+ * make sure to always pass the detail maps first.
+ * @param firstDetailMap
+ * @param secondDetailMap
+ * @param firstRefMap
+ * @param secondRefMap
+ * @param nomRefDetailFk
+ * @param nomRefFk
+ * @return
+ */
+ protected Reference getReferenceFromMaps(
+ Map<String, Reference> detailMap,
+ Map<String, Reference> refMap,
+ String nomRefDetailFk,
+ String nomRefFk) {
+ Reference ref = null;
+ if (detailMap != null){
+ ref = detailMap.get(nomRefDetailFk);
+ }
+ if (ref == null){
+ ref = refMap.get(nomRefFk);
+ }
+ return ref;
+ }
+
+ protected Reference getSourceReference(Reference sourceReference) {
+ Reference persistentSourceReference = getReferenceService().find(sourceReference.getUuid()); //just to be sure
+ if (persistentSourceReference != null){
+ sourceReference = persistentSourceReference;
+ }
+ return sourceReference;
+ }
+
+ protected static <T extends IdentifiableSource> boolean importSourceExists(ISourceable<T> sourceable, String idInSource,
+ String namespace, Reference ref) {
+ for (T source : sourceable.getSources()){
+ if (CdmUtils.nullSafeEqual(namespace, source.getIdNamespace()) &&
+ CdmUtils.nullSafeEqual(idInSource, source.getIdInSource()) &&
+ CdmUtils.nullSafeEqual(ref, source.getCitation())){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+}
--- /dev/null
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.mexico;
+
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelAuthorImport;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelUserImport;
+import eu.etaxonomy.cdm.io.berlinModel.in.validation.BerlinModelGeneralImportValidator;
+import eu.etaxonomy.cdm.io.common.DbImportConfiguratorBase;
+import eu.etaxonomy.cdm.io.common.Source;
+import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+
+/**
+ * Configurator for Mexico Eflora import.
+ *
+ * @author a.mueller
+ * @date 29.01.2022
+ */
+public class MexicoEfloraImportConfigurator
+ extends DbImportConfiguratorBase<MexicoEfloraImportState>{
+
+ private static final long serialVersionUID = 70300913255425256L;
+
+ @SuppressWarnings("unused")
+ private static Logger logger = Logger.getLogger(MexicoEfloraImportConfigurator.class);
+
+ public static MexicoEfloraImportConfigurator NewInstance(Source berlinModelSource, ICdmDataSource destination){
+ return new MexicoEfloraImportConfigurator(berlinModelSource, destination);
+ }
+
+ //TODO
+ private static IInputTransformer defaultTransformer = null;
+
+ private boolean doNameStatus = true;
+ private boolean doCommonNames = true;
+ private boolean doOccurrence = true;
+ private boolean doOccurrenceSources = true;
+ private boolean doMarker = true;
+ private boolean doUser = true;
+ private boolean doFacts = true;
+ private boolean doNameFacts = true;
+ private boolean doAuthors = true;
+ private DO_REFERENCES doReferences = DO_REFERENCES.ALL;
+ private boolean doTaxonNames = true;
+ private boolean doTypes = true;
+ private boolean doNamedAreas = true;
+
+ //taxa
+ private boolean doTaxa = true;
+ private boolean doRelTaxa = true;
+
+
+ private UUID featureTreeUuid;
+ private String featureTreeTitle;
+
+ @Override
+ protected void makeIoClassList(){
+ ioClassList = new Class[]{
+ BerlinModelGeneralImportValidator.class
+ , BerlinModelUserImport.class
+ , BerlinModelAuthorImport.class
+ };
+ }
+
+ @Override
+ public MexicoEfloraImportState getNewState() {
+ return new MexicoEfloraImportState(this);
+ }
+
+ protected MexicoEfloraImportConfigurator(Source berlinModelSource, ICdmDataSource destination) {
+ super(berlinModelSource, destination, NomenclaturalCode.ICNAFP, defaultTransformer); //default for Berlin Model
+ }
+
+
+ public boolean isDoNameStatus() {
+ return doNameStatus;
+ }
+ public void setDoNameStatus(boolean doNameStatus) {
+ this.doNameStatus = doNameStatus;
+ }
+
+
+ public boolean isDoCommonNames() {
+ return doCommonNames;
+ }
+
+
+ /**
+ * @param doCommonNames
+ */
+ public void setDoCommonNames(boolean doCommonNames) {
+ this.doCommonNames = doCommonNames;
+
+ }
+
+ public boolean isDoFacts() {
+ return doFacts;
+ }
+ public void setDoFacts(boolean doFacts) {
+ this.doFacts = doFacts;
+ }
+
+
+ public boolean isDoOccurrence() {
+ return doOccurrence;
+ }
+ public void setDoOccurrence(boolean doOccurrence) {
+ this.doOccurrence = doOccurrence;
+ }
+
+ public boolean isDoOccurrenceSources() {
+ return doOccurrenceSources;
+ }
+ public void setDoOccurrenceSources(boolean doOccurrenceSources) {
+ this.doOccurrenceSources = doOccurrenceSources;
+ }
+
+
+ public boolean isDoMarker() {
+ return doMarker;
+ }
+
+ public void setDoMarker(boolean doMarker) {
+ this.doMarker = doMarker;
+ }
+
+ public boolean isDoUser() {
+ return doUser;
+ }
+ public void setDoUser(boolean doUser) {
+ this.doUser = doUser;
+ }
+
+ public boolean isDoNameFacts() {
+ return doNameFacts;
+ }
+ public void setDoNameFacts(boolean doNameFacts) {
+ this.doNameFacts = doNameFacts;
+ }
+
+ public boolean isDoAuthors() {
+ return doAuthors;
+ }
+ public void setDoAuthors(boolean doAuthors) {
+ this.doAuthors = doAuthors;
+ }
+
+ public DO_REFERENCES getDoReferences() {
+ return doReferences;
+ }
+ public void setDoReferences(DO_REFERENCES doReferences) {
+ this.doReferences = doReferences;
+ }
+
+ public boolean isDoTaxonNames() {
+ return doTaxonNames;
+ }
+ public void setDoTaxonNames(boolean doTaxonNames) {
+ this.doTaxonNames = doTaxonNames;
+ }
+
+ public boolean isDoTypes() {
+ return doTypes;
+ }
+ public void setDoTypes(boolean doTypes) {
+ this.doTypes = doTypes;
+ }
+
+ public boolean isDoTaxa() {
+ return doTaxa;
+ }
+ public void setDoTaxa(boolean doTaxa) {
+ this.doTaxa = doTaxa;
+ }
+
+ public boolean isDoRelTaxa() {
+ return doRelTaxa;
+ }
+ public void setDoRelTaxa(boolean doRelTaxa) {
+ this.doRelTaxa = doRelTaxa;
+ }
+
+ public UUID getFeatureTreeUuid() {
+ return featureTreeUuid;
+ }
+ public void setFeatureTreeUuid(UUID featureTreeUuid) {
+ this.featureTreeUuid = featureTreeUuid;
+ }
+
+ @Override
+ public String getFeatureTreeTitle() {
+ return featureTreeTitle;
+ }
+ @Override
+ public void setFeatureTreeTitle(String featureTreeTitle) {
+ this.featureTreeTitle = featureTreeTitle;
+ }
+
+ public boolean isDoNamedAreas() {
+ return doNamedAreas;
+ }
+ public void setDoNamedAreas(boolean doNamedAreas) {
+ this.doNamedAreas = doNamedAreas;
+ }
+
+}
--- /dev/null
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.mexico;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.io.common.DbImportStateBase;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+
+/**
+ * State for Mexico Eflora import.
+ *
+ * @author a.mueller
+ * @date 29.01.2022
+ *
+ */
+public class MexicoEfloraImportState
+ extends DbImportStateBase<MexicoEfloraImportConfigurator, MexicoEfloraImportState>{
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = Logger.getLogger(MexicoEfloraImportState.class);
+
+ private Map<String, DefinedTermBase> dbCdmDefTermMap = new HashMap<>();
+
+ private boolean isReferenceSecondPath = false;
+
+ public MexicoEfloraImportState(MexicoEfloraImportConfigurator config) {
+ super(config);
+ }
+
+ public Map<String, DefinedTermBase> getDbCdmDefinedTermMap(){
+ return this.dbCdmDefTermMap;
+ }
+
+ public void putDefinedTermToMap(String tableName, String id, DefinedTermBase term){
+ this.dbCdmDefTermMap.put(tableName + "_" + id, term);
+ }
+
+ public void putDefinedTermToMap(String tableName, int id, DefinedTermBase term){
+ putDefinedTermToMap(tableName, String.valueOf(id), term);
+ }
+
+ public boolean isReferenceSecondPath() {
+ return isReferenceSecondPath;
+ }
+
+ public void setReferenceSecondPath(boolean isReferenceSecondPath) {
+ this.isReferenceSecondPath = isReferenceSecondPath;
+ }
+}
--- /dev/null
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.io.mexico;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+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.database.update.DatabaseTypeNotSupportedException;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportState;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelReferenceImport;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelTaxonNameImport;
+import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.TaxonDescription;
+import eu.etaxonomy.cdm.model.description.TextData;
+import eu.etaxonomy.cdm.model.name.Rank;
+import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.taxon.Synonym;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.model.term.DefinedTerm;
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
+
+
+/**
+ * @author a.mueller
+ * @since 20.03.2008
+ */
+@Component
+public class MexicoEfloraTaxonImport extends MexicoEfloraImportBase {
+
+ private static final long serialVersionUID = -1186364983750790695L;
+
+ private static final Logger logger = Logger.getLogger(MexicoEfloraTaxonImport.class);
+
+ public static final String NAMESPACE = "Taxon";
+
+ private static final String pluralString = "Taxa";
+ private static final String dbTableName = "Efloa_Taxonomia4CDM ";
+
+ private static final String LAST_SCRUTINY_FK = "lastScrutinyFk";
+
+ /**
+ * How should the publish flag in table PTaxon be interpreted
+ * NO_MARKER: No marker is set
+ * ONLY_FALSE:
+ */
+ public enum PublishMarkerChooser{
+ NO_MARKER,
+ ONLY_FALSE,
+ ONLY_TRUE,
+ ALL;
+
+ boolean doMark(boolean value){
+ if (value == true){
+ return this == ALL || this == ONLY_TRUE;
+ }else{
+ return this == ALL || this == ONLY_FALSE;
+ }
+ }
+ }
+
+ public MexicoEfloraTaxonImport(){
+ super(dbTableName, pluralString);
+ }
+
+ @Override
+ protected String getIdQuery(BerlinModelImportState state) {
+ String sql = " SELECT IdCAT "
+ + " FROM " + dbTableName
+ + " ORDER BY IdCAT ";
+ return sql;
+ }
+
+ @Override
+ protected String getRecordQuery(MexicoEfloraImportConfigurator config) {
+ String sqlSelect = " SELECT * ";
+ String sqlFrom = " FROM " + dbTableName;
+ String sqlWhere = " WHERE ( IdCAT IN (" + ID_LIST_TOKEN + ") )";
+
+ String strRecordQuery =sqlSelect + " " + sqlFrom + " " + sqlWhere ;
+ return strRecordQuery;
+ }
+
+ @Override
+ protected boolean doCheck(MexicoEfloraImportState state){
+ //IOValidator<BerlinModelImportState> validator = new BerlinModelTaxonImportValidator();
+ //return validator.validate(state);
+ return true;
+ }
+
+ @Override
+ public boolean doPartition(@SuppressWarnings("rawtypes") ResultSetPartitioner partitioner, MexicoEfloraImportState state) {
+
+ boolean success = true ;
+ MexicoEfloraImportConfigurator config = state.getConfig();
+ @SuppressWarnings("rawtypes")
+ Set<TaxonBase> taxaToSave = new HashSet<>();
+// @SuppressWarnings("unchecked")
+// Map<String, TaxonName> taxonNameMap = partitioner.getObjectMap(BerlinModelTaxonNameImport.NAMESPACE);
+ @SuppressWarnings("unchecked")
+ Map<String, Reference> refMap = partitioner.getObjectMap(BerlinModelReferenceImport.REFERENCE_NAMESPACE);
+
+ ResultSet rs = partitioner.getResultSet();
+ try{
+ while (rs.next()){
+
+ // if ((i++ % modCount) == 0 && i!= 1 ){ logger.info("PTaxa handled: " + (i-1));}
+
+ //create TaxonName element
+ String taxonId = rs.getString("IdCAT");
+ String status = rs.getString("EstatusNombre");
+ String rankStr = rs.getString("CategoriaTaxonomica");
+ String nameStr = rs.getString("Nombre");
+ String autorStr = rs.getString("AutorSinAnio");
+ String fullNameStr = nameStr + " " + autorStr;
+ String annotationStr = rs.getString("AnotacionTaxon");
+// String type = rs.getString("NomPublicationType");
+ String year = rs.getString("Anio");
+ int secFk = rs.getInt("IdBibliografiaSec");
+ int nameId = rs.getInt("idNombre");
+
+
+ //IdCATRel => Accepted Taxon => TaxonRel
+ //IdCAT_AscendenteHerarquico4CDM => Parent => TaxonRel
+ //IdCAT_BasNomOrig => Basionyme der akzeptierten Taxa => TaxonRel
+
+ Rank rank = Rank.GENUS(); //FIXME
+ NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
+ TaxonName taxonName = (TaxonName)parser.parseFullName(fullNameStr);
+
+ String refFkStr = String.valueOf(secFk);
+ Reference sec = refMap.get(refFkStr);
+
+ TaxonBase<?> taxonBase;
+ Synonym synonym;
+ Taxon taxon;
+ try {
+ if ("aceptado".equals(status)){
+ taxon = Taxon.NewInstance(taxonName, sec);
+ taxonBase = taxon;
+ }else if ("sinónimo".equals(status)){
+ synonym = Synonym.NewInstance(taxonName, sec);
+ taxonBase = synonym;
+ }else {
+ logger.error("Status not yet implemented: " + status);
+ }
+
+
+ DefinedTerm taxonIdType = DefinedTerm.IDENTIFIER_NAME_IPNI();
+ taxonBase.addIdentifier(taxonId, taxonIdType);
+
+ //namePhrase
+ String namePhrase = rs.getString("NamePhrase");
+ if (StringUtils.isNotBlank(namePhrase)){
+ taxonBase.setAppendedPhrase(namePhrase);
+ }
+
+ //Notes
+ boolean excludeNotes = state.getConfig().isTaxonNoteAsFeature() && taxonBase.isInstanceOf(Taxon.class);
+ String notes = rs.getString("Notes");
+
+ doIdCreatedUpdatedNotes(state, taxonBase, rs, taxonId, NAMESPACE, false, excludeNotes || notes == null);
+ if (excludeNotes && notes != null){
+ makeTaxonomicNote(state, CdmBase.deproxy(taxonBase, Taxon.class), rs.getString("Notes"));
+ }
+
+ partitioner.startDoSave();
+ taxaToSave.add(taxonBase);
+ } catch (Exception e) {
+ logger.warn("An exception (" +e.getMessage()+") occurred when creating taxon with id " + taxonId + ". Taxon could not be saved.");
+ success = false;
+ }
+ }
+ } catch (DatabaseTypeNotSupportedException e) {
+ logger.error("MethodNotSupportedException:" + e);
+ return false;
+ } catch (Exception e) {
+ logger.error("SQLException:" + e);
+ return false;
+ }
+
+ getTaxonService().save(taxaToSave);
+ return success;
+ }
+
+ private boolean isMclIdentifier(BerlinModelImportState state, ResultSet rs, String idInSource) throws SQLException {
+ if (idInSource.contains("-")){
+ return true;
+ }else if (idInSource.matches("(293|303)")){
+ String created = rs.getString("Created_Who");
+ if (created.endsWith(".xml")){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ protected String getIdInSource(BerlinModelImportState state, ResultSet rs) throws SQLException {
+ String id = rs.getString("idInSource");
+ return id;
+ }
+
+ private void makeTaxonomicNote(BerlinModelImportState state, Taxon taxon, String notes) {
+ if (isNotBlank(notes)){
+ TaxonDescription desc = getTaxonDescription(taxon, false, true);
+ desc.setDefault(true); //hard coded for Salvador, not used elsewhere as far as I can see
+ TextData textData = TextData.NewInstance(Feature.NOTES() , notes, Language.SPANISH_CASTILIAN(), null);
+ desc.addElement(textData);
+ }
+ }
+
+ @Override
+ public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, BerlinModelImportState state) {
+
+ String nameSpace;
+ Set<String> idSet;
+ Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
+
+ try{
+ Set<String> nameIdSet = new HashSet<>();
+ Set<String> referenceIdSet = new HashSet<>();
+ while (rs.next()){
+ handleForeignKey(rs, nameIdSet, "PTNameFk");
+ handleForeignKey(rs, referenceIdSet, "PTRefFk");
+ if (state.getConfig().isUseLastScrutinyAsSec() && resultSetHasColumn(rs, LAST_SCRUTINY_FK)){
+ handleForeignKey(rs, referenceIdSet, LAST_SCRUTINY_FK);
+ }
+ }
+
+ //name map
+ nameSpace = BerlinModelTaxonNameImport.NAMESPACE;
+ idSet = nameIdSet;
+ Map<String, TaxonName> nameMap = getCommonService().getSourcedObjectsByIdInSourceC(TaxonName.class, idSet, nameSpace);
+ result.put(nameSpace, nameMap);
+
+ //reference map
+ nameSpace = BerlinModelReferenceImport.REFERENCE_NAMESPACE;
+ idSet = referenceIdSet;
+ Map<String, Reference> referenceMap = getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
+ result.put(nameSpace, referenceMap);
+
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ }
+ return result;
+ }
+
+ @Override
+ protected String getTableName() {
+ return dbTableName;
+ }
+
+ @Override
+ public String getPluralString() {
+ return pluralString;
+ }
+
+ @Override
+ protected boolean isIgnore(MexicoEfloraImportState state){
+ return ! state.getConfig().isDoTaxa();
+ }
+}
\ No newline at end of file