//database validation status (create, update, validate ...)
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
- static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_cdmtest_mysql();
-// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_test1();
+// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_cdmtest_mysql();
+ static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_test1();
//feature tree uuid
- public static final UUID featureTreeUuid = UUID.fromString("dd2070ef-e75b-494b-bc6a-4a370271866b");
+ private static final UUID featureTreeUuid = UUID.fromString("dd2070ef-e75b-494b-bc6a-4a370271866b");
+ private static final UUID flatFeatureTreeUuid = UUID.fromString("33896d1f-c3df-4cdb-afb8-bffd35f9d6b0");
+ private static final String featureTreeName = "Catalogo feature tree";
+ private static final String flatFeatureTreeName = "Catalogo flat feature tree";
+
//classification
static final UUID classificationUuid = UUID.fromString("588dd2de-7c95-42ad-8eb1-994460561b5e");
config.setDbSchemaValidation(hbm2dll);
config.setSecReference(getSecReference());
config.setFeatureTreeUuid(featureTreeUuid);
+ config.setFlatFeatureTreeUuid(flatFeatureTreeUuid);
+ config.setFeatureTreeTitle(featureTreeName);
+ config.setFlatFeatureTreeTitle(flatFeatureTreeName);
+
config.setRecordsPerTransaction(5000);
config.setSource(source);
return null;
}else if (key.equals("Endémica")){
return PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA();
+ }else if (key.equals("Nativa")){
+ return PresenceAbsenceTerm.NATIVE();
}else{
return null;
}
false, true);
description.addElement(commonName);
- state.getCommonNameMap().put(idCombi, commonName);
+ state.getCommonNameMap().put(idCombi, commonName.getUuid());
partitioner.startDoSave();
taxaToSave.add(taxonBase);
} catch (Exception e) {
+ e.printStackTrace();
logger.warn("An exception (" +e.getMessage()+") occurred when trying to create common name for id " + idCombi + ".");
success = false;
}
}
getTaxonService().save(taxaToSave);
+ logger.warn("Partition finished");
return success;
}
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-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.description.CommonTaxonName;
@SuppressWarnings("unchecked")
//TODO
- Map<String, Reference> referenceMap = partitioner.getObjectMap(MexicoEfloraRefArticlesImport.NAMESPACE);
+ Map<String, Reference> referenceMap = partitioner.getObjectMap(MexicoEfloraReferenceImportBase.NAMESPACE);
ResultSet rs = partitioner.getResultSet();
try{
Reference ref = referenceMap.get(String.valueOf(idBibliografia));
String detail = state.getRefDetailMap().get(idBibliografia);
- DescriptionElementSource source = commonName.addPrimaryTaxonomicSource(ref, detail);
- //TODO
- TaxonName nameUsedInSource = getNameUsedInSource(state, observaciones);
- source.setNameUsedInSource(nameUsedInSource);
- //TODO other observaciones
+ if (commonName != null) {
+ DescriptionElementSource source = commonName.addPrimaryTaxonomicSource(ref, detail);
+ //TODO
+ if (source!= null) {
+ TaxonName nameUsedInSource = getNameUsedInSource(state, observaciones);
+ source.setNameUsedInSource(nameUsedInSource);
+ //TODO other observaciones
+ } else {
+ logger.warn("Source not found for " + idCombi + " and bibID: " + idBibliografia);
+ }
+ }else {
+ logger.warn("CommonName not found for " + idCombi);
+ }
partitioner.startDoSave();
} catch (Exception e) {
+ e.printStackTrace();
logger.warn("An exception (" +e.getMessage()+") occurred when trying to create common name for id " + idCombi + ".");
success = false;
}
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");
- }
-
- //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);
+ Set<String> commonNameIdSet = new HashSet<>();
+ Set<String> referenceIdSet = new HashSet<>();
+ while (rs.next()){
+ handleForeignKey(rs, referenceIdSet, "IdBibliografia");
+ handleForeignKey(rs, commonNameIdSet, "IdCombinado");
+ }
+
+ //common name map
+ nameSpace = MexicoEfloraCommonNameImport.NAMESPACE;
+ Map<UUID,String> uuidMap = new HashMap<>();
+ commonNameIdSet.stream().forEach(cnId->uuidMap.put(state.getCommonNameMap().get(cnId),cnId));
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ List<CommonTaxonName> commonNames = (List)getDescriptionElementService().find(uuidMap.keySet());
+ Map<String, CommonTaxonName> commonNameMap = new HashMap<>();
+ commonNames.stream().forEach(cn->commonNameMap.put(uuidMap.get(cn.getUuid()), cn));
+ result.put(nameSpace, commonNameMap);
+
+ //reference map
+ nameSpace = MexicoEfloraReferenceImportBase.NAMESPACE;
+ idSet = referenceIdSet;
+ Map<String, Reference> referenceMap = getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
+ result.put(nameSpace, referenceMap);
} catch (SQLException e) {
throw new RuntimeException(e);
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelReferenceImport;
import eu.etaxonomy.cdm.io.common.ResultSetPartitioner;
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
import eu.etaxonomy.cdm.model.common.CdmBase;
//create TaxonName element
String idCombi = rs.getString("IdDist");
- String idCAT = rs.getString("IdCAT");
- String nombreStr = rs.getString("Nombre");
- String paisStr = rs.getString("Pais");
- String estadoStr = rs.getString("Estado");
- String abreviaturaEstado = rs.getString("AbreviaturaEstado");
+ String taxonUuid = rs.getString("taxonUuid");
+// String nombreStr = rs.getString("Nombre");
+// String paisStr = rs.getString("Pais");
+// String estadoStr = rs.getString("Estado");
+// String abreviaturaEstado = rs.getString("AbreviaturaEstado");
String tipoDistribucion = rs.getString("TipoDistribucion");
int idRegion = rs.getInt("IdRegion");
- int idTipoDistribucion = rs.getInt("IdTipoDistribucion");
- int idTipoRegion = rs.getInt("IdTipoRegion");
+// int idTipoDistribucion = rs.getInt("IdTipoDistribucion");
+// int idTipoRegiond = rs.getInt("IdTipoRegion");
try {
- TaxonBase<?> taxonBase = taxonMap.get(idCAT);
+ TaxonBase<?> taxonBase = taxonMap.get(taxonUuid);
Taxon taxon;
- if (taxonBase.isInstanceOf(Taxon.class)) {
+ if (taxonBase == null) {
+ logger.warn("Taxon "+taxonUuid+" not found for distribution " + idCombi);
+ continue;
+ }else if (taxonBase.isInstanceOf(Taxon.class)) {
taxon = CdmBase.deproxy(taxonBase, Taxon.class);
}else {
- logger.warn(idCombi + ": Taxon is not accepted: " + idCAT);
+ logger.warn(idCombi + ": Taxon is not accepted: " + taxonUuid);
continue;
}
- NamedArea area = getArea(state, idTipoRegion);
+ NamedArea area = getArea(state, idRegion);
PresenceAbsenceTerm status = getStatus(state, tipoDistribucion);
Distribution distribution = Distribution.NewInstance(area, status);
//TODO
Reference ref = null;
- TaxonDescription description = this.getTaxonDescription(taxon, ref,
- false, true);
+ TaxonDescription description = this.getTaxonDescription(taxon, ref, false, true);
description.addElement(distribution);
- state.getDistributionMap().put(idCombi, distribution);
+ state.getDistributionMap().put(idCombi, distribution.getUuid());
partitioner.startDoSave();
taxaToSave.add(taxonBase);
public Map<Object, Map<String, ? extends CdmBase>> getRelatedObjectsForPartition(ResultSet rs, MexicoEfloraImportState state) {
String nameSpace;
- Set<String> idSet;
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
try{
Set<UUID> taxonIdSet = new HashSet<>();
- Set<String> referenceIdSet = new HashSet<>();
while (rs.next()){
handleForeignUuidKey(rs, taxonIdSet, "taxonUuid");
-// handleForeignKey(rs, referenceIdSet, "PTRefFk");
}
//taxon map
taxa.stream().forEach(t->taxonMap.put(t.getUuid().toString(), t));
result.put(nameSpace, taxonMap);
- //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);
}
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.UUID;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
-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.description.DescriptionElementSource;
try {
Distribution distribution = distributionMap.get(idCombi);
-
+ if (distribution == null) {
+ logger.warn("Distribution not found for " + idCombi);
+ continue;
+ }
Reference ref = referenceMap.get(String.valueOf(idBibliografia));
String detail = state.getRefDetailMap().get(idBibliografia);
DescriptionElementSource source = distribution.addPrimaryTaxonomicSource(ref, detail);
- //TODO
- TaxonName nameUsedInSource = getNameUsedInSource(state, observaciones);
- source.setNameUsedInSource(nameUsedInSource);
-
- //TODO other observaciones
+ //TODO
+ if (source!= null) {
+ TaxonName nameUsedInSource = getNameUsedInSource(state, observaciones);
+ source.setNameUsedInSource(nameUsedInSource);
+ //TODO other observaciones
+ } else {
+ logger.warn("Source not found for " + idCombi + " and bibID: " + idBibliografia);
+ }
partitioner.startDoSave();
// taxaToSave.add(taxonBase);
} catch (Exception e) {
+ e.printStackTrace();
logger.warn("An exception (" +e.getMessage()+") occurred when trying to create common name for id " + idCombi + ".");
success = false;
}
Map<Object, Map<String, ? extends CdmBase>> result = new HashMap<>();
try{
- Set<String> nameIdSet = new HashSet<>();
+ Set<String> distributionIdSet = new HashSet<>();
Set<String> referenceIdSet = new HashSet<>();
while (rs.next()){
-// handleForeignKey(rs, nameIdSet, "PTNameFk");
-// handleForeignKey(rs, referenceIdSet, "PTRefFk");
+ handleForeignKey(rs, referenceIdSet, "IdBibliografia");
+ handleForeignKey(rs,distributionIdSet, "IdDist");
}
- //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);
+ //distribution map
+ nameSpace = MexicoEfloraDistributionImport.NAMESPACE;
+ Map<UUID,String> uuidMap = new HashMap<>();
+ distributionIdSet.stream().forEach(dId->uuidMap.put(state.getDistributionMap().get(dId),dId));
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ List<Distribution> distributions = (List)getDescriptionElementService().find(uuidMap.keySet());
+ Map<String, Distribution> distributionMap = new HashMap<>();
+ distributions.stream().forEach(d->distributionMap.put(uuidMap.get(d.getUuid()), d));
+ result.put(nameSpace, distributionMap);
+
+ //reference map
+ nameSpace = MexicoEfloraReferenceImportBase.NAMESPACE;
+ idSet = referenceIdSet;
+ Map<String, Reference> referenceMap = getCommonService().getSourcedObjectsByIdInSourceC(Reference.class, idSet, nameSpace);
+ result.put(nameSpace, referenceMap);
} catch (SQLException e) {
throw new RuntimeException(e);
private void saveTree(MexicoEfloraImportState state) {
TransactionStatus tx = this.startTransaction();
+
@SuppressWarnings("unchecked")
TermVocabulary<Feature> featureVoc = TermVocabulary.NewInstance(TermType.Feature);
- featureVoc.setLabel("Catalogo", Language.SPANISH_CASTILIAN());
-// featureVoc.setTitleCache("Catalogo", true);
+// featureVoc.setLabel("Catalogo", Language.SPANISH_CASTILIAN());
+ featureVoc.setTitleCache("Catalogo", true);
+
TermTree<Feature> featureTree = TermTree.NewFeatureInstance(state.getConfig().getFeatureTreeUuid());
- featureTree.setTitleCache("Catalogo feature tree", true);
+ featureTree.setTitleCache(state.getConfig().getFeatureTreeTitle(), true);
+ featureTree.setUuid(state.getConfig().getFeatureTreeUuid());
+ featureTree.getRoot().addChild(Feature.DISTRIBUTION());
getTermTreeService().save(featureTree);
+ TermTree<Feature> flatFeatureTree = TermTree.NewFeatureInstance(state.getConfig().getFeatureTreeUuid());
+ flatFeatureTree.setTitleCache(state.getConfig().getFlatFeatureTreeTitle(), true);
+ flatFeatureTree.setUuid(state.getConfig().getFlatFeatureTreeUuid());
+ flatFeatureTree.getRoot().addChild(Feature.DISTRIBUTION());
+ getTermTreeService().save(flatFeatureTree);
+
+
getVocabularyService().save(featureVoc);
for (TreeNode child : root.children) {
- saveNodeRecursive(state, child, featureVoc, null, featureTree.getRoot());
+ saveNodeRecursive(state, child, featureVoc, null, featureTree.getRoot(), flatFeatureTree.getRoot());
}
+
+ featureTree.getRoot().addChild(Feature.COMMON_NAME());
+ flatFeatureTree.getRoot().addChild(Feature.COMMON_NAME());
+
this.commitTransaction(tx);
}
- private void saveNodeRecursive(MexicoEfloraImportState state, TreeNode node, TermVocabulary<Feature> featureVoc, Feature parentFeature, TermNode<Feature> parentFeatureTreeNode) {
+ private void saveNodeRecursive(MexicoEfloraImportState state, TreeNode node, TermVocabulary<Feature> featureVoc, Feature parentFeature,
+ TermNode<Feature> parentFeatureTreeNode, TermNode<Feature> flatFeatureTreereTreeNode) {
if (!node.children.isEmpty()) {
//is feature
String sep = UTF8.EN_DASH_SPATIUM.toString();
feature.setSupportsTextData(false);
featureVoc.addTerm(feature);
TermNode<Feature> featureTreeNode = parentFeatureTreeNode.addChild(feature);
+ flatFeatureTreereTreeNode.addChild(feature);
getTermService().save(feature);
//parent-child
if (parentFeature != null) {
parentFeature.addIncludes(feature);
}
for (TreeNode child : node.children) {
- saveNodeRecursive(state, child, featureVoc, feature, featureTreeNode);
+ saveNodeRecursive(state, child, featureVoc, feature, featureTreeNode, flatFeatureTreereTreeNode);
}
}else {
TermVocabulary<State> supportedStates = parentFeature.getSupportedCategoricalEnumerations().stream().findAny().orElse(null);
private boolean doRelTaxa = true;
private UUID featureTreeUuid;
+ private UUID flatFeatureTreeUuid;
+
private String featureTreeTitle;
+ private String flatFeatureTreeTitle;
private Reference secReference;
MexicoEfloraRefWebSitesImport.class,
MexicoEfloraRegionImport.class,
MexicoEfloraTaxonImport.class,
- MexicoEfloraTaxonRelationImport.class,
MexicoEfloraCommonNameImport.class,
-// MexicoEfloraCommonNameRefImport.class,
+ MexicoEfloraCommonNameRefImport.class,
MexicoEfloraDistributionImport.class,
-// MexicoEfloraDistributionRefImport.class,
+ MexicoEfloraDistributionRefImport.class,
MexicoEfloraFactCategoryImport.class,
MexicoEfloraFactImport.class,
+ MexicoEfloraTaxonRelationImport.class,
};
}
- @Override
+ @SuppressWarnings("unchecked")
+ @Override
public MexicoEfloraImportState getNewState() {
return new MexicoEfloraImportState(this);
}
this.featureTreeUuid = featureTreeUuid;
}
+ public UUID getFlatFeatureTreeUuid() {
+ return flatFeatureTreeUuid;
+ }
+ public void setFlatFeatureTreeUuid(UUID flatFeatureTreeUuid) {
+ this.flatFeatureTreeUuid = flatFeatureTreeUuid;
+ }
+
@Override
public String getFeatureTreeTitle() {
return featureTreeTitle;
this.featureTreeTitle = featureTreeTitle;
}
+ public String getFlatFeatureTreeTitle() {
+ return flatFeatureTreeTitle;
+ }
+ public void setFlatFeatureTreeTitle(String flatFeatureTreeTitle) {
+ this.flatFeatureTreeTitle = flatFeatureTreeTitle;
+ }
+
public boolean isDoNamedAreas() {
return doNamedAreas;
}
import org.apache.log4j.Logger;
import eu.etaxonomy.cdm.io.common.DbImportStateBase;
-import eu.etaxonomy.cdm.model.description.CommonTaxonName;
-import eu.etaxonomy.cdm.model.description.Distribution;
import eu.etaxonomy.cdm.model.description.Feature;
import eu.etaxonomy.cdm.model.description.State;
import eu.etaxonomy.cdm.model.location.NamedArea;
private Map<Integer,UUID> referenceUuidMap = new HashMap<>();
private Map<Integer,String> refDetailMap = new HashMap<>();
- private Map<String,CommonTaxonName> commonNameMap = new HashMap<>();
- private Map<String,Distribution> distributionMap = new HashMap<>();
+ private Map<String,UUID> commonNameMap = new HashMap<>();
+ private Map<String,UUID> distributionMap = new HashMap<>();
public MexicoEfloraImportState(MexicoEfloraImportConfigurator config) {
return refDetailMap;
}
- public Map<String,CommonTaxonName> getCommonNameMap() {
+ public Map<String,UUID> getCommonNameMap() {
return commonNameMap;
}
- public Map<String,Distribution> getDistributionMap() {
+ public Map<String,UUID> getDistributionMap() {
return distributionMap;
}
String nameStr = rs.getString("Nombre");
String autorStr = rs.getString("AutorSinAnio");
String fullNameStr = nameStr + " " + autorStr;
- String citaNomenclaturStr = rs.getString("CitaNomenclatural");
+ String citaNomenclaturalStr = rs.getString("CitaNomenclatural");
String annotationStr = rs.getString("AnotacionTaxon");
String type = rs.getString("NomPublicationType");
String year = rs.getString("Anio");
TaxonName taxonName = (TaxonName)parser.parseFullName(fullNameStr, NomenclaturalCode.ICNAFP, rank);
//FIXME TODO
Reference nomRef = ReferenceFactory.newGeneric();
- nomRef.setTitleCache(citaNomenclaturStr, true);
+ nomRef.setAbbrevTitleCache(citaNomenclaturalStr, true);
+
nomRef.setDatePublished(TimePeriodParser.parseStringVerbatim(year));
taxonName.setNomenclaturalReference(nomRef);
}
getTaxonService().save(taxaToSave);
+ logger.warn("Partition finished");
return success;
}