import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
-import java.util.BitSet;
+import java.util.EnumSet;
import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Matcher;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
-import org.joda.time.DateTime;
-import org.joda.time.format.DateTimeFormat;
-import org.joda.time.format.DateTimeFormatter;
import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionStatus;
import eu.etaxonomy.cdm.api.service.TaxonServiceImpl;
import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
import eu.etaxonomy.cdm.io.common.Source;
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
import eu.etaxonomy.cdm.io.common.mapping.out.DbConstantMapper;
-import eu.etaxonomy.cdm.io.common.mapping.out.DbExtensionMapper;
import eu.etaxonomy.cdm.io.common.mapping.out.DbLastActionMapper;
import eu.etaxonomy.cdm.io.common.mapping.out.DbObjectMapper;
import eu.etaxonomy.cdm.io.common.mapping.out.DbStringMapper;
import eu.etaxonomy.cdm.io.common.mapping.out.MethodMapper;
import eu.etaxonomy.cdm.io.common.mapping.out.ObjectChangeMapper;
import eu.etaxonomy.cdm.io.pesi.erms.ErmsTransformer;
-import eu.etaxonomy.cdm.model.common.Annotation;
import eu.etaxonomy.cdm.model.common.AnnotationType;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.Extension;
import eu.etaxonomy.cdm.model.common.ExtensionType;
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
-import eu.etaxonomy.cdm.model.common.Language;
import eu.etaxonomy.cdm.model.common.Marker;
import eu.etaxonomy.cdm.model.common.MarkerType;
import eu.etaxonomy.cdm.model.common.RelationshipBase;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
-import eu.etaxonomy.cdm.profiler.ProfilerController;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
import eu.etaxonomy.cdm.strategy.cache.HTMLTagRules;
import eu.etaxonomy.cdm.strategy.cache.TagEnum;
import eu.etaxonomy.cdm.strategy.cache.name.INonViralNameCacheStrategy;
-import eu.etaxonomy.cdm.strategy.cache.name.NonViralNameDefaultCacheStrategy;
+import eu.etaxonomy.cdm.strategy.cache.name.TaxonNameDefaultCacheStrategy;
import eu.etaxonomy.cdm.strategy.cache.name.ZooNameNoMarkerCacheStrategy;
/**
* The export class for {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames}.<p>
* Inserts into DataWarehouse database table <code>Taxon</code>.
* It is divided into four phases:<p><ul>
- * <li>Phase 1: Export of all {@link eu.etaxonomy.cdm.model.name.TaxonNameBase TaxonNames} except some data exported in the following phases.
- * <li>Phase 2: Export of additional data: ParenTaxonFk and TreeIndex.
+ * <li>Phase 1: Export of all {@link eu.etaxonomy.cdm.model.name.TaxonName TaxonNames} except some data exported in the following phases.
+ * <li>Phase 2: Export of additional data: ParentTaxonFk and TreeIndex.
* <li>Phase 3: Export of additional data: Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk.
* <li>Phase 4: Export of Inferred Synonyms.</ul>
- * @author e.-m.lee
- * @date 23.02.2010
*
+ * @author e.-m.lee
+ * @since 23.02.2010
*/
@Component
public class PesiTaxonExport extends PesiExportBase {
- private static final Logger logger = Logger.getLogger(PesiTaxonExport.class);
+
+ private static final long serialVersionUID = -3412722058790200078L;
+ private static final Logger logger = Logger.getLogger(PesiTaxonExport.class);
+
private static final Class<? extends CdmBase> standardMethodParameter = TaxonBase.class;
private static int modCount = 1000;
private static final String dbTableName = "Taxon";
private static final String dbTableNameSynRel = "RelTaxon";
private static final String dbTableAdditionalSourceRel = "AdditionalTaxonSource";
+
private static final String pluralString = "Taxa";
private static final String parentPluralString = "Taxa";
- private PreparedStatement parentTaxonFk_TreeIndex_KingdomFkStmt;
+ private static final String pluralStringNames = "Names";
+
+// private PreparedStatement parentTaxonFk_TreeIndex_KingdomFkStmts;
private PreparedStatement parentTaxonFkStmt;
private PreparedStatement rankTypeExpertsUpdateStmt;
private PreparedStatement rankUpdateStmt;
- private NomenclaturalCode nomenclaturalCode;
private Integer kingdomFk;
- private final HashMap<Rank, Rank> rank2endRankMap = new HashMap<Rank, Rank>();
- private final List<Rank> rankList = new ArrayList<Rank>();
- private static final UUID uuidTreeIndex = UUID.fromString("28f4e205-1d02-4d3a-8288-775ea8413009");
- private AnnotationType treeIndexAnnotationType;
+
private static ExtensionType lastActionExtensionType;
private static ExtensionType lastActionDateExtensionType;
private static ExtensionType expertNameExtensionType;
private static ExtensionType speciesExpertNameExtensionType;
private static ExtensionType cacheCitationExtensionType;
- public static NonViralNameDefaultCacheStrategy zooNameStrategy = ZooNameNoMarkerCacheStrategy.NewInstance();
- public static NonViralNameDefaultCacheStrategy nonViralNameStrategy = NonViralNameDefaultCacheStrategy.NewInstance();
- private static int currentTaxonId;
-
- /**
- * @return the treeIndexAnnotationType
- */
- protected AnnotationType getTreeIndexAnnotationType() {
- return treeIndexAnnotationType;
- }
-
- /**
- * @param treeIndexAnnotationType the treeIndexAnnotationType to set
- */
- protected void setTreeIndexAnnotationType(AnnotationType treeIndexAnnotationType) {
- this.treeIndexAnnotationType = treeIndexAnnotationType;
- }
+ public static TaxonNameDefaultCacheStrategy zooNameStrategy = ZooNameNoMarkerCacheStrategy.NewInstance();
+ public static TaxonNameDefaultCacheStrategy nonViralNameStrategy = TaxonNameDefaultCacheStrategy.NewInstance();
+ private static int currentTaxonId;
enum NamePosition {
beginning,
return standardMethodParameter;
}
- @Override
- protected boolean doCheck(PesiExportState state) {
- boolean result = true;
- return result;
- }
-
-
@Override
protected void doInvoke(PesiExportState state) {
try {
boolean success = true;
// PESI: Clear the database table Taxon.
-// doDelete(state);
+ doDelete(state);
// Get specific mappings: (CDM) Taxon -> (PESI) Taxon
PesiExportMapping mapping = getMapping();
additionalSourceMapping.initialize(state);
// Find extensionTypes
- lastActionExtensionType = (ExtensionType)getTermService().find(PesiTransformer.lastActionUuid);
- lastActionDateExtensionType = (ExtensionType)getTermService().find(PesiTransformer.lastActionDateUuid);
- expertNameExtensionType = (ExtensionType)getTermService().find(PesiTransformer.expertNameUuid);
- speciesExpertNameExtensionType = (ExtensionType)getTermService().find(PesiTransformer.speciesExpertNameUuid);
- cacheCitationExtensionType = (ExtensionType)getTermService().find(PesiTransformer.cacheCitationUuid);
+ lastActionExtensionType = (ExtensionType)getTermService().find(PesiTransformer.uuidExtLastAction);
+ lastActionDateExtensionType = (ExtensionType)getTermService().find(PesiTransformer.uuidExtLastActionDate);
+ expertNameExtensionType = (ExtensionType)getTermService().find(PesiTransformer.uuidExtExpertName);
+ speciesExpertNameExtensionType = (ExtensionType)getTermService().find(PesiTransformer.uuidExtSpeciesExpertName);
+ cacheCitationExtensionType = (ExtensionType)getTermService().find(PesiTransformer.uuidExtCacheCitation);
//Export Taxa..
success &= doPhase01(state, mapping, additionalSourceMapping);
//"PHASE 1b: Handle names without taxa ...
- success &= doNames(state, additionalSourceMapping);
-
+ success &= doPhase01b_Names(state, additionalSourceMapping);
// 2nd Round: Add ParentTaxonFk to each taxon
success &= doPhase02(state);
// 4nd Round: Add TreeIndex to each taxon
success &= doPhase04(state);
-
- //"PHASE 4: Creating Inferred Synonyms...
+ //"PHASE 5: Creating Inferred Synonyms...
success &= doPhase05(state, mapping, synonymRelMapping);
logger.info("*** Finished Making " + pluralString + " ..." + getSuccessString(success));
if (!success){
- state.getResult().addError("An error occurred in PesiTaxonExport.doInvoke");
+ state.getResult().addError("An error occurred in PesiTaxonExport.doInvoke. Success = false");
}
return;
} catch (Exception e) {
private void initPreparedStatements(PesiExportState state) throws SQLException {
- initTreeIndexStatement(state);
+// initTreeIndexStatement(state);
initRankExpertsUpdateStmt(state);
initRankUpdateStatement(state);
initParentFkStatement(state);
}
- // Prepare TreeIndex-And-KingdomFk-Statement
- private void initTreeIndexStatement(PesiExportState state) throws SQLException {
- Connection connection = state.getConfig().getDestination().getConnection();
- String parentTaxonFk_TreeIndex_KingdomFkSql = "UPDATE Taxon SET ParentTaxonFk = ?, TreeIndex = ? WHERE TaxonId = ?";
- parentTaxonFk_TreeIndex_KingdomFkStmt = connection.prepareStatement(parentTaxonFk_TreeIndex_KingdomFkSql);
- }
+// // Prepare TreeIndex-And-KingdomFk-Statement
+// private void initTreeIndexStatement(PesiExportState state) throws SQLException {
+// Connection connection = state.getConfig().getDestination().getConnection();
+// String parentTaxonFk_TreeIndex_KingdomFkSql = "UPDATE Taxon SET ParentTaxonFk = ?, TreeIndex = ? WHERE TaxonId = ?";
+// parentTaxonFk_TreeIndex_KingdomFkStmt = connection.prepareStatement(parentTaxonFk_TreeIndex_KingdomFkSql);
+// }
// Prepare TreeIndex-And-KingdomFk-Statement
private void initParentFkStatement(PesiExportState state) throws SQLException {
rankTypeExpertsUpdateStmt = connection.prepareStatement(sql);
}
- private boolean doPhase01(PesiExportState state, PesiExportMapping mapping, PesiExportMapping additionalSourceMapping) throws SQLException {
- int count = 0;
+ private boolean doPhase01(PesiExportState state, PesiExportMapping mapping, PesiExportMapping additionalSourceMapping){
+
+ int count = 0;
int pastCount = 0;
- List<TaxonBase> list;
boolean success = true;
// Get the limit for objects to save within a single transaction.
int limit = state.getConfig().getLimitSave();
-
logger.info("PHASE 1: Export Taxa...limit is " + limit);
// Start transaction
TransactionStatus txStatus = startTransaction(true);
- logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
-
-
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ logger.info("Taking snapshot at the beginning of phase 1 of taxonExport");
+ //ProfilerController.memorySnapshot();
+ }
int partitionCount = 0;
-
- logger.info("Taking snapshot at the beginning of phase 1 of taxonExport");
- //ProfilerController.memorySnapshot();
+ List<TaxonBase<?>> list;
while ((list = getNextTaxonPartition(null, limit, partitionCount++, null)) != null ) {
logger.debug("Fetched " + list.size() + " " + pluralString + ". Exporting...");
TaxonName taxonName = taxon.getName();
TaxonName nvn = CdmBase.deproxy(taxonName);
- System.err.println(nvn.getTitleCache());
if (! nvn.isProtectedTitleCache()){
nvn.setTitleCache(null, false);
}
nvn.setAuthorshipCache(null, false);
}
try{
- if (nvn.getRank().equals(Rank.KINGDOM())){
- String treeIndex = ((Taxon)taxon).getTaxonNodes().iterator().next().treeIndex();
- Integer kingdomId = PesiTransformer.pesiKingdomMap.get(nvn.getGenusOrUninomial());
- state.getTreeIndexKingdomMap().put(treeIndex, kingdomId);
- }}catch(NullPointerException e){
- logger.error(nvn.getTitleCache() + "has no Rank!");
- System.err.println(nvn.getTitleCache() + "has no Rank!");
+ if (nvn.getRank().equals(Rank.KINGDOM())){
+ if(taxon.isInstanceOf(Taxon.class)){
+ String treeIndex = ((Taxon)taxon).getTaxonNodes().iterator().next().treeIndex();
+ Integer kingdomId = PesiTransformer.pesiKingdomId(nvn.getGenusOrUninomial());
+ state.getTreeIndexKingdomMap().put(treeIndex, kingdomId);
+ }else{
+ logger.warn("Kingdom taxon is not of class Taxon but " + taxon.getClass().getSimpleName() + ": " + nvn.getGenusOrUninomial());
+ }
+ }
+ }catch(NullPointerException e){
+ logger.error(nvn.getTitleCache() + " has no Rank!");
+ System.err.println(nvn.getTitleCache() + " has no Rank!");
}
//core mapping
success &= mapping.invoke(taxon);
additionalSourceMapping.invoke(taxon);
}
+ //TODO switch on again, leads to some warnings in ERMS for taxa of not correctly handled kingdoms
validatePhaseOne(taxon, nvn);
- taxon = null;
- nvn = null;
- taxonName = null;
-
-
-
}
-
// Commit transaction
commitTransaction(txStatus);
- logger.debug("Committed transaction.");
- logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
+ logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count + " (Phase 01)");
pastCount = count;
- /*logger.warn("Taking snapshot at the end of the loop of phase 1 of taxonExport");
- //ProfilerController.memorySnapshot();
- */
- // Start transaction
+
+ // Start new transaction
txStatus = startTransaction(true);
- logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ }
}
- if (list == null ) {
- logger.info("No " + pluralString + " left to fetch.");
- }
-
-
+ logger.debug("No " + pluralString + " left to fetch.");
// Commit transaction
commitTransaction(txStatus);
txStatus = null;
- logger.debug("Committed transaction.");
- list = null;
- if (logger.isDebugEnabled()){
- logger.debug("Taking snapshot at the end of phase 1 of taxonExport");
- ProfilerController.memorySnapshot();
- }
+
return success;
}
-
private void validatePhaseOne(TaxonBase<?> taxon, TaxonName taxonName) {
- // Check whether some rules are violated
- nomenclaturalCode = taxonName.getNomenclaturalCode();
+
+ // Check whether some rules are violated
String genusOrUninomial = taxonName.getGenusOrUninomial();
String specificEpithet = taxonName.getSpecificEpithet();
String infraSpecificEpithet = taxonName.getInfraSpecificEpithet();
String infraGenericEpithet = taxonName.getInfraGenericEpithet();
- Integer rank = getRankFk(taxonName, nomenclaturalCode);
+ Rank rank = taxonName.getRank();
- if (rank == null) {
- logger.error("Rank was not determined: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
- } else {
+ //as kingdomFk can not be defined in Phase 01 the below code was switched to use the CDM rank.
+ //This may be changed if we move validation to Phase03 or later
+// Integer rankFk = getRankFk(taxonName, taxonName.getNameType());
+// if (rankFk == null) {
+// logger.error("Rank was not determined: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
+// } else {
// Check whether infraGenericEpithet is set correctly
// 1. Childs of an accepted taxon of rank subgenus that are accepted taxa of rank species have to have an infraGenericEpithet
// 2. Grandchilds of an accepted taxon of rank subgenus that are accepted taxa of rank subspecies have to have an infraGenericEpithet
int ancestorLevel = 0;
- if (taxonName.getRank().equals(Rank.SUBSPECIES())) {
+ if (rank == null){
+ logger.warn("PhaseOne validation: Taxon name has no rank: " + taxonName.getTitleCache());
+ }else if (rank.equals(Rank.SUBSPECIES())) {
// The accepted taxon two rank levels above should be of rank subgenus
ancestorLevel = 2;
- }
- if (taxonName.getRank().equals(Rank.SPECIES())) {
+ }else if (rank.equals(Rank.SPECIES())) {
// The accepted taxon one rank level above should be of rank subgenus
ancestorLevel = 1;
}
}
}
- if (infraGenericEpithet == null && rank.intValue() == 190) {
- logger.warn("InfraGenericEpithet was not determined although it should exist for rank 190: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
- }
- if (specificEpithet != null && rank.intValue() < 216) {
- logger.warn("SpecificEpithet was determined for rank " + rank + " although it should only exist for ranks higher or equal to 220: TaxonName " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
- if (infraSpecificEpithet != null && rank.intValue() < 225) {
- String message = "InfraSpecificEpithet '" +infraSpecificEpithet + "' was determined for rank " + rank + " although it should only exist for ranks higher or equal to 230: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")";
- if (StringUtils.isNotBlank(infraSpecificEpithet)){
- logger.warn(message);
- }else{
- logger.warn(message);
- }
+ if (rank != null){
+ if (infraGenericEpithet == null && rank.isInfraGenericButNotSpeciesGroup()) {
+ logger.warn("InfraGenericEpithet was not determined although it should exist for infra generic names: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
+ }
+ if (specificEpithet != null && (rank.isInfraGenericButNotSpeciesGroup()||rank.isGenus()||rank.isSupraGeneric())) {
+ logger.warn("SpecificEpithet was determined for rank " + rank.getTitleCache() + " although it should only exist for species aggregates, species or infraspecific taxa: TaxonName " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ }
+ if (infraSpecificEpithet != null && !rank.isInfraSpecific()) {
+ String message = "InfraSpecificEpithet '" +infraSpecificEpithet + "' was determined for rank " + rank.getTitleCache() + " although it should only exist for rank species and higher: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")";
+ if (StringUtils.isNotBlank(infraSpecificEpithet)){
+ logger.warn(message);
+ }else{
+ logger.warn(message);
+ }
+ }
}
- }
+// }
if (infraSpecificEpithet != null && specificEpithet == null) {
logger.warn("An infraSpecificEpithet was determined, but a specificEpithet was not determined: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
}
}
}
-
-
/**
* 2nd Round: Add ParentTaxonFk to each taxon and add Biota if not exists
- * @param state
- * @return
*/
private boolean doPhase02(PesiExportState state) {
int count = 0;
return success;
}
- List<Taxon> list;
-
// Get the limit for objects to save within a single transaction.
int limit = state.getConfig().getLimitSave();
int partitionCount = 0;
// ProfilerController.memorySnapshot();
+ List<Taxon> list;
while ((list = getNextTaxonPartition(Taxon.class, limit, partitionCount++, null)) != null ) {
- logger.info("Fetched " + list.size() + " " + pluralString + ". Exporting...");
+ if(logger.isDebugEnabled()) {
+ logger.info("Fetched " + list.size() + " " + pluralString + ". Exporting...");
+ }
for (Taxon taxon : list) {
for (TaxonNode node : taxon.getTaxonNodes()){
doCount(count++, modCount, pluralString);
TaxonNode parentNode = node.getParent();
- if (parentNode != null && parentNode.getTaxon() != null){ //new root node handling requires has root taxon with taxon == null
+ if (parentNode != null && isPesiTaxon(parentNode.getTaxon())){ //exclude root taxa and unpublished parents (relevant for "Valueless" parent for E+M Rubus taxa). Usually a parent should not be unpublished
int childId = state.getDbId( taxon);
int parentId = state.getDbId(parentNode.getTaxon());
success &= invokeParentTaxonFk(parentId, childId);
}
}
-
}
// Commit transaction
commitTransaction(txStatus);
- logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
+ logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count + " (Phase 2)");
pastCount = count;
// Start transaction
txStatus = startTransaction(true);
- logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
-
- }
- if (list == null ) {
- logger.info("No " + pluralString + " left to fetch.");
+ if (logger.isDebugEnabled()){
+ logger.info("Started new transaction. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ }
}
- list = null;
+ logger.debug("No " + pluralString + " left to fetch.");
+
// Commit transaction
commitTransaction(txStatus);
return success;
-
}
/**
* Inserts the Biota Taxon if not yet exists.
- * @param state
- * @throws SQLException
*/
private void insertBiota(PesiExportState state) {
try {
} catch (SQLException e) {
logger.warn ("Biota could not be requested or inserted");
}
-
- }
-
- // 4th round: Add TreeIndex to each taxon
- private boolean doPhase04(PesiExportState state) {
- boolean success = true;
-
- logger.info("PHASE 4: Make TreeIndex ... ");
-
- //TODO test if possible to move to phase 02
- String sql = " UPDATE Taxon SET ParentTaxonFk = (Select TaxonId from Taxon where RankFk = 0) " +
- " WHERE (RankFk = 10) and TaxonStatusFk = 1 ";
- state.getConfig().getDestination().update(sql);
-
- state.getConfig().getDestination().update("EXEC dbo.recalculateallstoredpaths");
-
- return success;
-
- }
-
-
- // 2nd Round: Add ParentTaxonFk, TreeIndex to each Taxon
- private boolean doPhase02_OLD(PesiExportState state) {
- boolean success = true;
- if (! state.getConfig().isDoTreeIndex()){
- logger.info ("Ignore PHASE 2: ParentTaxonFk and TreeIndex");
- return success;
- }
-
- List<Classification> classificationList = null;
- logger.info("PHASE 2: Add ParenTaxonFk and TreeIndex...");
-
- // Specify starting ranks for tree traversing
- rankList.add(Rank.KINGDOM());
- rankList.add(Rank.GENUS());
-
- // Specify where to stop traversing (value) when starting at a specific Rank (key)
- rank2endRankMap.put(Rank.GENUS(), null); // Since NULL does not match an existing Rank, traverse all the way down to the leaves
- rank2endRankMap.put(Rank.KINGDOM(), Rank.GENUS()); // excludes rank genus
-
- StringBuffer treeIndex = new StringBuffer();
-
- // Retrieve list of classifications
- TransactionStatus txStatus = startTransaction(true);
- logger.info("Started transaction for parentFk and treeIndex. Fetching all classifications...");
- classificationList = getClassificationService().listClassifications(null, 0, null, null);
- commitTransaction(txStatus);
- logger.debug("Committed transaction.");
-
- logger.info("Fetched " + classificationList.size() + " classification(s).");
-
- setTreeIndexAnnotationType(getAnnotationType(uuidTreeIndex, "TreeIndex", "TreeIndex", "TI"));
- List<TaxonNode> rankSpecificRootNodes;
- for (Classification classification : classificationList) {
- for (Rank rank : rankList) {
-
- txStatus = startTransaction(true);
- logger.info("Started transaction to fetch all rootNodes specific to Rank " + rank.getLabel() + " ...");
-
- rankSpecificRootNodes = getClassificationService().listRankSpecificRootNodes(classification, rank, null, null, null);
- logger.info("Fetched " + rankSpecificRootNodes.size() + " RootNodes for Rank " + rank.getLabel());
-
- commitTransaction(txStatus);
- logger.debug("Committed transaction.");
-
- for (TaxonNode rootNode : rankSpecificRootNodes) {
- txStatus = startTransaction(false);
- Rank endRank = rank2endRankMap.get(rank);
- if (endRank != null) {
- logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till Rank " + endRank.getLabel() + " ...");
- } else {
- logger.debug("Started transaction to traverse childNodes of rootNode (" + rootNode.getUuid() + ") till leaves are reached ...");
- }
-
- TaxonNode newNode = getTaxonNodeService().load(rootNode.getUuid());
-
- if (isPesiTaxon(newNode.getTaxon())){
- TaxonNode parentNode = newNode.getParent();
- if (rank.equals(Rank.KINGDOM())) {
- treeIndex = new StringBuffer();
- treeIndex.append("#");
- } else {
- // Get treeIndex from parentNode
- if (parentNode != null) {
- boolean annotationFound = false;
- Set<Annotation> annotations = parentNode.getAnnotations();
- for (Annotation annotation : annotations) {
- AnnotationType annotationType = annotation.getAnnotationType();
- if (annotationType != null && annotationType.equals(getTreeIndexAnnotationType())) {
- treeIndex = new StringBuffer(CdmUtils.Nz(annotation.getText()));
- annotationFound = true;
- // logger.error("treeIndex: " + treeIndex);
- break;
- }
- }
- if (!annotationFound) {
- // This should not happen because it means that the treeIndex was not set correctly as an annotation to parentNode
- logger.error("TreeIndex could not be read from annotation of TaxonNode: " + parentNode.getUuid() + ", Taxon: " + parentNode.getTaxon().getUuid());
- treeIndex = new StringBuffer();
- treeIndex.append("#");
- }
- } else {
- // TreeIndex could not be determined, but it's unclear how to proceed to generate a correct treeIndex if the parentNode is NULL
- logger.error("ParentNode for RootNode is NULL. TreeIndex could not be determined: " + newNode.getUuid());
- treeIndex = new StringBuffer(); // This just prevents growing of the treeIndex in a wrong manner
- treeIndex.append("#");
- }
- }
- nomenclaturalCode = newNode.getTaxon().getName().getNomenclaturalCode();
- kingdomFk = PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode);
- traverseTree(newNode, parentNode, treeIndex, endRank, state);
- parentNode =null;
- }else{
- logger.debug("Taxon is not a PESI taxon: " + newNode.getTaxon().getUuid());
- }
-
- newNode = null;
-
- try {
- commitTransaction(txStatus);
- logger.debug("Committed transaction.");
- } catch (Exception e) {
- logger.error(e.getMessage());
- e.printStackTrace();
- }
-
- }
- rankSpecificRootNodes = null;
- }
-
- }
-
- logger.warn("Taking snapshot at the end of phase 2 of taxonExport");
- //ProfilerController.memorySnapshot();
- return success;
}
//PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk...
logger.info ("Ignore PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk...");
return success;
}
+
+ addValuelessTaxonToKingdomMap(state);
+
// Get the limit for objects to save within a single transaction.
int limit = state.getConfig().getLimitSave();
- List<TaxonBase> list;
logger.info("PHASE 3: Add Rank data, KingdomFk, TypeNameFk, expertFk and speciesExpertFk...");
// Be sure to add rank information, KingdomFk, TypeNameFk, expertFk and speciesExpertFk to every taxonName
// Start transaction
TransactionStatus txStatus = startTransaction(true);
- logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ }
int partitionCount = 0;
+ @SuppressWarnings("rawtypes")
+ List<TaxonBase> list;
while ((list = getNextTaxonPartition(TaxonBase.class, limit, partitionCount++, null)) != null) {
- logger.debug("Fetched " + list.size() + " " + pluralString + ". Exporting...");
+ if (logger.isDebugEnabled()) {
+ logger.debug("Fetched " + list.size() + " " + pluralString + ". Exporting...");
+ }
for (TaxonBase<?> taxon : list) {
- TaxonName taxonName = taxon.getName();
+ TaxonName taxonName = CdmBase.deproxy(taxon.getName());
// Determine expertFk
// Integer expertFk = makeExpertFk(state, taxonName);
//
doCount(count++, modCount, pluralString);
Integer typeNameFk = getTypeNameFk(taxonName, state);
- kingdomFk = findKingdomIdFromTreeIndex(taxon, state);
- // PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode);
+ Integer kingdomFk = findKingdomIdFromTreeIndex(taxon, state);
+ Integer rankFk = getRankFk(taxonName, kingdomFk);
- //TODO why are expertFks needed? (Andreas M.)
-// if (expertFk != null || speciesExpertFk != null) {
- invokeRankDataAndTypeNameFkAndKingdomFk(taxonName, nomenclaturalCode, state.getDbId(taxon),
- typeNameFk, kingdomFk, state);
-// }
-
- taxon = null;
- taxonName = null;
+ invokeRankDataAndTypeNameFkAndKingdomFk(taxonName, state.getDbId(taxon),
+ typeNameFk, kingdomFk, rankFk, state);
}
// Commit transaction
commitTransaction(txStatus);
- logger.debug("Committed transaction.");
- logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
+ if (logger.isDebugEnabled()){logger.debug("Committed transaction.");}
+ logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count + " (Phase 3)");
pastCount = count;
// Start transaction
txStatus = startTransaction(true);
- logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ...");
- }
- if (list == null) {
- logger.info("No " + pluralString + " left to fetch.");
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction for rank, kingdom, typeName, expertFk and speciesExpertFK. Fetching some " + pluralString + " (max: " + limit + ") ...");
+ }
}
-
- list = null;
+ logger.debug("No " + pluralString + " left to fetch.");
// Commit transaction
commitTransaction(txStatus);
- logger.debug("Committed transaction.");
- logger.debug("Try to take snapshot at the end of phase 3 of taxonExport, number of partitions: " + partitionCount);
- //ProfilerController.memorySnapshot();
+ if (logger.isDebugEnabled()){
+ logger.debug("Committed transaction.");
+ logger.debug("Try to take snapshot at the end of phase 3 of taxonExport, number of partitions: " + partitionCount);
+ //ProfilerController.memorySnapshot();
+ }
return success;
}
- /**
- * @param taxon
- * @return
- */
- private Integer findKingdomIdFromTreeIndex(TaxonBase<?> taxon,PesiExportState state) {
- if (taxon instanceof Taxon){
- Set<TaxonNode> nodes = ((Taxon)taxon).getTaxonNodes();
- if (!nodes.isEmpty()){
+ private void addValuelessTaxonToKingdomMap(PesiExportState state) {
+ TransactionStatus txStatus = startTransaction();
+ Taxon valuelessTaxon = (Taxon)getTaxonService().find(PesiTransformer.uuidTaxonValuelessEuroMed);
+ if (valuelessTaxon != null){
+ String treeIndex = valuelessTaxon.getTaxonNodes().iterator().next().treeIndex();
+ Integer kingdomId = PesiTransformer.pesiKingdomId("Plantae");
+ state.getTreeIndexKingdomMap().put(treeIndex, kingdomId);
+ }
+ commitTransaction(txStatus);
+ }
+
+ // 4th round: Add TreeIndex to each taxon
+ private boolean doPhase04(PesiExportState state) {
+ boolean success = true;
+
+ logger.info("PHASE 4: Make TreeIndex ... ");
+
+ //TODO test if possible to move to phase 02
+ String sql = " UPDATE Taxon SET ParentTaxonFk = (SELECT TaxonId FROM Taxon WHERE RankFk = 0) " +
+ " WHERE (RankFk = 10) and TaxonStatusFk = 1 ";
+ state.getConfig().getDestination().update(sql);
+
+ state.getConfig().getDestination().update("EXEC dbo.recalculateallstoredpaths");
+
+ logger.info("PHASE 4: Make TreeIndex DONE");
+
+ return success;
+ }
+
+ private static Integer findKingdomIdFromTreeIndex(TaxonBase<?> taxonBase, PesiExportState state) {
+ Taxon taxon;
+ if (taxonBase instanceof Synonym){
+ taxon = ((Synonym) taxonBase).getAcceptedTaxon();
+ }else{
+ taxon = checkPseudoOrRelatedTaxon((Taxon)taxonBase);
+ }
+ if (taxon == null){
+ NomenclaturalCode nomenclaturalCode = taxonBase.getName().getNameType();
+ logger.warn("Taxon is synonym with no accepted taxon attached: " + taxonBase.getTitleCache() + ". The kingdom is taken from the nomenclatural code: " + PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode) );
+ return PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode);
+ } else{
+ Set<TaxonNode> nodes = taxon.getTaxonNodes();
+ if (nodes.isEmpty()){
+ NomenclaturalCode nomenclaturalCode = taxon.getName().getNameType();
+ logger.warn("The taxon has no nodes: " + taxon.getTitleCache() + ". The kingdom is taken from the nomenclatural code: " + PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode));
+ return PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode);
+ } else {
+ if (nodes.size()>1){
+ logger.warn("The taxon has more then 1 taxon node: " + taxon.getTitleCache() + ". Take arbitrary one.");
+ }
String treeIndex = nodes.iterator().next().treeIndex();
- Pattern pattern = Pattern.compile("#t[0-9]+#[0-9]+#[0-9]+#");
+ Pattern pattern = Pattern.compile("#t[0-9]+#([0-9]+#){3}");
Matcher matcher = pattern.matcher(treeIndex);
Integer kingdomID = null;
if(matcher.find()) {
String treeIndexKingdom = matcher.group(0);
kingdomID = state.getTreeIndexKingdomMap().get(treeIndexKingdom);
}
+ if (kingdomID == null){
+ pattern = Pattern.compile("#t[0-9]+#([0-9]+#){2}");
+ matcher = pattern.matcher(treeIndex);
+ if(matcher.find()) {
+ String treeIndexKingdom = matcher.group(0);
+ Map<String, Integer> map = state.getTreeIndexKingdomMap();
+ kingdomID = map.get(treeIndexKingdom);
+ }
+ }
+ if(Rank.DOMAIN().equals(taxon.getName().getRank())){
+ return 0;
+ }
+ if(kingdomID == null){
+ logger.warn("Kingdom could not be defined for treeindex " + treeIndex);
+ }
return kingdomID;
- } else {
- logger.debug("The taxon has no nodes: " + taxon.getTitleCache() + " the kingdom is taken from the nomenclatural code: " + PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode));
- return PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode);
- }} else{
- return PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode);
+ }
}
}
+ private static Taxon checkPseudoOrRelatedTaxon(Taxon taxon) {
+ if (!taxon.getTaxonNodes().isEmpty()){
+ return taxon;
+ }else if(hasPseudoTaxonRelationship(taxon)){
+ return acceptedPseudoTaxon(taxon);
+ }else if(isMisappliedNameOrProParteSynonym(taxon)){
+ return acceptedTaxonConcept(taxon);
+ }else{
+ return taxon;
+ }
+ }
+
+ private static Taxon acceptedPseudoTaxon(Taxon taxon) {
+ for (TaxonRelationship rel : taxon.getRelationsFromThisTaxon()){
+ if (TaxonRelationshipType.pseudoTaxonUuids().contains(rel.getType().getUuid())){
+ return rel.getToTaxon();
+ }
+ }
+ return taxon;
+ }
+
+ private static Taxon acceptedTaxonConcept(Taxon taxon) {
+ for (TaxonRelationship rel : taxon.getRelationsFromThisTaxon()){
+ if (TaxonRelationshipType.misappliedNameUuids().contains(rel.getType().getUuid())||
+ TaxonRelationshipType.proParteOrPartialSynonymUuids().contains(rel.getType().getUuid())){
+ return rel.getToTaxon();
+ }
+ }
+ return taxon;
+ }
+
+ private static boolean hasPseudoTaxonRelationship(Taxon taxon) {
+ for (TaxonRelationship rel : taxon.getRelationsFromThisTaxon()){
+ if (TaxonRelationshipType.pseudoTaxonUuids().contains(rel.getType().getUuid())){
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static boolean isMisappliedNameOrProParteSynonym(Taxon taxon) {
+ for (TaxonRelationship rel : taxon.getRelationsFromThisTaxon()){
+ if (TaxonRelationshipType.misappliedNameUuids().contains(rel.getType().getUuid())||
+ TaxonRelationshipType.proParteOrPartialSynonymUuids().contains(rel.getType().getUuid())){
+ return true;
+ }
+ }
+ return false;
+ }
+
// "PHASE 5: Creating Inferred Synonyms..."
- private boolean doPhase05(PesiExportState state, PesiExportMapping mapping, PesiExportMapping synRelMapping) throws SQLException {
+ private boolean doPhase05(PesiExportState state, PesiExportMapping mapping, PesiExportMapping synRelMapping) {
int count;
int pastCount;
boolean success = true;
int limit = state.getConfig().getLimitSave();
// Create inferred synonyms for accepted taxa
- logger.info("PHASE 4: Creating Inferred Synonyms...");
+ logger.info("PHASE 5: Creating Inferred Synonyms...");
- // Determine the count of elements in datawarehouse database table Taxon
+ // Determine the count of elements in data warehouse database table Taxon
currentTaxonId = determineTaxonCount(state);
currentTaxonId++;
// Start transaction
TransactionStatus txStatus = startTransaction(true);
- logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
- List<TaxonBase> taxonList = null;
-
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
+ }
+ List<TaxonBase> taxonList = null;
+ while ((taxonList = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SPECIES(), pageSize, pageNumber, null)).size() > 0) {
- while ((taxonList = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SPECIES(), pageSize, pageNumber)).size() > 0) {
- HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<Integer, TaxonName>();
+ Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
- logger.info("Fetched " + taxonList.size() + " " + parentPluralString + ". Exporting...");
+ if (logger.isDebugEnabled()) {
+ logger.info("Fetched " + taxonList.size() + " " + parentPluralString + ". Exporting...");
+ }
inferredSynonymsDataToBeSaved.putAll(createInferredSynonymsForTaxonList(state, mapping,
synRelMapping, taxonList));
doCount(count += taxonList.size(), modCount, inferredSynonymPluralString);
// Commit transaction
commitTransaction(txStatus);
- logger.debug("Committed transaction.");
+ if (logger.isDebugEnabled()){logger.debug("Committed transaction.");}
logger.info("Exported " + (taxonList.size()) + " " + inferredSynonymPluralString + ". Total: " + count);
//pastCount = count;
// Save Rank Data and KingdomFk for inferred synonyms
for (Integer taxonFk : inferredSynonymsDataToBeSaved.keySet()) {
- invokeRankDataAndKingdomFk(inferredSynonymsDataToBeSaved.get(taxonFk), nomenclaturalCode, taxonFk, kingdomFk, state);
+ TaxonName taxonName = inferredSynonymsDataToBeSaved.get(taxonFk);
+ invokeRankDataAndKingdomFk(inferredSynonymsDataToBeSaved.get(taxonFk), taxonFk, kingdomFk, state);
}
// Start transaction
txStatus = startTransaction(true);
- logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
+ if (logger.isDebugEnabled()) {
+ logger.info("Started new transaction. Fetching some " + parentPluralString + " first (max: " + limit + ") ...");
+ }
// Increment pageNumber
pageNumber++;
}
taxonList = null;
- while ((taxonList = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SUBSPECIES(), pageSize, pageNumber)).size() > 0) {
- HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
+ while ((taxonList = getTaxonService().listTaxaByName(Taxon.class, "*", "*", "*", "*", "*", Rank.SUBSPECIES(), pageSize, pageNumber, null)).size() > 0) {
+ Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
logger.info("Fetched " + taxonList.size() + " " + parentPluralString + ". Exporting...");
inferredSynonymsDataToBeSaved.putAll(createInferredSynonymsForTaxonList(state, mapping,
synRelMapping, taxonList));
- ;
+
doCount(count += taxonList.size(), modCount, inferredSynonymPluralString);
// Commit transaction
commitTransaction(txStatus);
// Save Rank Data and KingdomFk for inferred synonyms
for (Integer taxonFk : inferredSynonymsDataToBeSaved.keySet()) {
- invokeRankDataAndKingdomFk(inferredSynonymsDataToBeSaved.get(taxonFk), nomenclaturalCode, taxonFk, kingdomFk, state);
+ TaxonName taxonName = inferredSynonymsDataToBeSaved.get(taxonFk);
+ invokeRankDataAndKingdomFk(taxonName, taxonFk, kingdomFk, state);
}
// Start transaction
}
taxonList = null;
-// logger.warn("Taking snapshot at the end of phase 4 of taxonExport");
+// logger.warn("Taking snapshot at the end of phase 5 of taxonExport");
// ProfilerController.memorySnapshot();
// Commit transaction
commitTransaction(txStatus);
System.gc();
- logger.debug("Taking snapshot at the end of phase 4 after gc() of taxonExport");
+ logger.debug("Taking snapshot at the end of phase 5 after gc() of taxonExport");
//ProfilerController.memorySnapshot();
logger.debug("Committed transaction.");
return success;
}
- /**
- * @param state
- * @param mapping
- * @param synRelMapping
- * @param currentTaxonId
- * @param taxonList
- * @param inferredSynonymsDataToBeSaved
- * @return
- */
- private HashMap<Integer, TaxonName> createInferredSynonymsForTaxonList(PesiExportState state,
+ private Map<Integer, TaxonName> createInferredSynonymsForTaxonList(PesiExportState state,
PesiExportMapping mapping, PesiExportMapping synRelMapping, List<TaxonBase> taxonList) {
Taxon acceptedTaxon;
List<Synonym> inferredSynonyms = null;
boolean localSuccess = true;
- HashMap<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<Integer, TaxonName>();
+ Map<Integer, TaxonName> inferredSynonymsDataToBeSaved = new HashMap<>();
for (TaxonBase<?> taxonBase : taxonList) {
TaxonName taxonName = acceptedTaxon.getName();
if (taxonName.isZoological()) {
- nomenclaturalCode = taxonName.getNameType();
- kingdomFk = PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode);
+ kingdomFk = findKingdomIdFromTreeIndex(taxonBase, state);
Set<TaxonNode> taxonNodes = acceptedTaxon.getTaxonNodes();
TaxonNode singleNode = null;
// The stored classification from another TaxonNode is used. It's a simple, but not a failsafe fallback solution.
if (taxonNodes.size() == 0) {
//logger.error("Classification could not be determined directly from this Taxon: " + acceptedTaxon.getUuid() + " is misapplication? "+acceptedTaxon.isMisapplication()+ "). The classification of the last taxon is used");
-
}
}
logger.error("This TaxonBase is not a Taxon even though it should be: " + taxonBase.getUuid() + " (" + taxonBase.getTitleCache() + ")");
}
}
- taxonList = null;
return inferredSynonymsDataToBeSaved;
}
-
/**
- * Handles names that do not appear in taxa
- * @param state
- * @param mapping
- * @return
+ * Handles names that do not appear in taxa.
*/
- private boolean doNames(PesiExportState state, PesiExportMapping additionalSourceMapping) throws SQLException {
+ private boolean doPhase01b_Names(PesiExportState state, PesiExportMapping additionalSourceMapping) {
boolean success = true;
if (! state.getConfig().isDoPureNames()){
mapping.initialize(state);
int count = 0;
int pastCount = 0;
- List<TaxonName> list;
success = true;
// Get the limit for objects to save within a single transaction.
int limit = state.getConfig().getLimitSave();
-
logger.info("PHASE 1b: Export Pure Names ...");
// Start transaction
TransactionStatus txStatus = startTransaction(true);
logger.info("Started new transaction for Pure Names. Fetching some " + pluralString + " (max: " + limit + ") ...");
int partitionCount = 0;
+ List<TaxonName> list;
while ((list = getNextPureNamePartition(null, limit, partitionCount++)) != null ) {
- logger.info("Fetched " + list.size() + " names without taxa. Exporting...");
+ logger.debug("Fetched " + list.size() + pluralStringNames + " without taxa. Exporting...");
for (TaxonName taxonName : list) {
doCount(count++, modCount, pluralString);
success &= mapping.invoke(taxonName);
// Commit transaction
commitTransaction(txStatus);
logger.debug("Committed transaction.");
- logger.info("Exported " + (count - pastCount) + " " + pluralString + ". Total: " + count);
+ logger.info("Exported " + (count - pastCount) + " " + pluralStringNames + ". Total: " + count + ". Partition: " + partitionCount);
pastCount = count;
// Start transaction
txStatus = startTransaction(true);
- logger.info("Started new transaction for PureNames. Fetching some " + pluralString + " (max: " + limit + ") ...");
- }
- if (list == null) {
- logger.info("No " + pluralString + " left to fetch.");
+ logger.debug("Started new transaction for PureNames. Fetching some " + pluralString + " (max: " + limit + ") ...");
}
- list = null;
+ logger.debug("No " + pluralString + " left to fetch.");
+
// Commit transaction
commitTransaction(txStatus);
logger.debug("Committed transaction.");
return annotationType;
}
- /**
- * Traverses the classification recursively and stores determined values for every Taxon.
- * @param childNode The {@link TaxonNode TaxonNode} to process.
- * @param parentNode The parent {@link TaxonNode TaxonNode} of the childNode.
- * @param treeIndex The TreeIndex at the current level.
- * @param fetchLevel Rank to stop fetching at.
- * @param state The {@link PesiExportState PesiExportState}.
- */
- private void traverseTree(TaxonNode childNode, TaxonNode parentNode, StringBuffer treeIndex, Rank fetchLevel, PesiExportState state) {
- // Traverse all branches from this childNode until specified fetchLevel is reached.
- StringBuffer localTreeIndex = new StringBuffer(treeIndex);
- Taxon childTaxon = childNode.getTaxon();
- if (childTaxon != null) {
- if (isPesiTaxon(childTaxon)){
- Integer taxonId = state.getDbId(childTaxon);
- TaxonName childName = childTaxon.getName();
- if (taxonId != null) {
- Rank childRank = childName.getRank();
- if (childRank != null) {
- if (! childRank.equals(fetchLevel)) {
-
- localTreeIndex.append(taxonId + "#");
-
- saveData(childNode, parentNode, localTreeIndex, state, taxonId);
-
- // Store treeIndex as annotation for further use
- Annotation annotation = Annotation.NewInstance(localTreeIndex.toString(), getTreeIndexAnnotationType(), Language.DEFAULT());
- childNode.addAnnotation(annotation);
-
- for (TaxonNode newNode : childNode.getChildNodes()) {
- if (newNode.getTaxon() != null && isPesiTaxon(newNode.getTaxon())){
- traverseTree(newNode, childNode, localTreeIndex, fetchLevel, state);
- }
- }
-
- } else {
- // logger.debug("Target Rank " + fetchLevel.getLabel() + " reached");
- return;
- }
- } else {
- logger.error("Rank is NULL. FetchLevel can not be checked: " + childName.getUuid() + " (" + childName.getTitleCache() + ")");
- }
- } else {
- logger.error("Taxon can not be found in state: " + childTaxon.getUuid() + " (" + childTaxon.getTitleCache() + ")");
- }
- }else{
- if (logger.isDebugEnabled()){
- logger.debug("Taxon is not a PESI taxon: " + childTaxon.getUuid());
- }
- }
-
- } else {
- logger.error("Taxon is NULL for TaxonNode: " + childNode.getUuid());
- }
- }
-
- /**
- * Stores values in database for every recursive round.
- * @param childNode The {@link TaxonNode TaxonNode} to process.
- * @param parentNode The parent {@link TaxonNode TaxonNode} of the childNode.
- * @param treeIndex The TreeIndex at the current level.
- * @param state The {@link PesiExportState PesiExportState}.
- * @param currentTaxonFk The TaxonFk to store the values for.
- */
- private void saveData(TaxonNode childNode, TaxonNode parentNode, StringBuffer treeIndex, PesiExportState state, Integer currentTaxonFk) {
- // We are differentiating kingdoms by the nomenclatural code for now.
- // This needs to be handled in a better way as soon as we know how to differentiate between more kingdoms.
- Taxon childTaxon = childNode.getTaxon();
- if (isPesiTaxon(childTaxon)) {
- TaxonBase<?> parentTaxon = null;
- if (parentNode != null) {
- parentTaxon = parentNode.getTaxon();
-
- }
-
- invokeParentTaxonFkAndTreeIndex(state.getDbId(parentTaxon), currentTaxonFk, treeIndex);
- }
-
- }
-
- /**
- * Inserts values into the Taxon database table.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @param state The {@link PesiExportState PesiExportState}.
- * @param stmt The prepared statement.
- * @return Whether save was successful or not.
- */
- protected boolean invokeParentTaxonFkAndTreeIndex(Integer parentTaxonFk, Integer currentTaxonFk, StringBuffer treeIndex) {
- try {
- if (parentTaxonFk != null) {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setInt(1, parentTaxonFk);
- } else {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(1, null);
- }
-
- if (treeIndex != null) {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setString(2, treeIndex.toString());
- } else {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(2, null);
- }
-
- if (currentTaxonFk != null) {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setInt(3, currentTaxonFk);
- } else {
- parentTaxonFk_TreeIndex_KingdomFkStmt.setObject(3, null);
- }
-
- parentTaxonFk_TreeIndex_KingdomFkStmt.executeUpdate();
- return true;
- } catch (SQLException e) {
- logger.error("ParentTaxonFk (" + parentTaxonFk ==null? "-":parentTaxonFk + ") and TreeIndex could not be inserted into database for taxon "+ (currentTaxonFk == null? "-" :currentTaxonFk) + ": " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- }
-
- protected boolean invokeParentTaxonFk(Integer parentId, Integer childId) {
+ private boolean invokeParentTaxonFk(Integer parentId, Integer childId) {
try {
parentTaxonFkStmt.setInt(1, parentId);
parentTaxonFkStmt.setInt(2, childId);
parentTaxonFkStmt.executeUpdate();
return true;
} catch (SQLException e) {
- logger.warn("ParentTaxonFk (" + parentId ==null? "-":parentId + ") could not be inserted into database for taxon "+ (childId == null? "-" :childId) + ": " + e.getMessage());
+ logger.warn("ParentTaxonFk (" + (parentId ==null? "-":parentId) + ") could not be inserted into database "
+ + "for taxon "+ (childId == null? "-" :childId) + ": " + e.getMessage());
e.printStackTrace();
return false;
}
* @param kindomFk The KingdomFk.
* @return Whether save was successful or not.
*/
- private boolean invokeRankDataAndKingdomFk(TaxonName taxonName, NomenclaturalCode nomenclaturalCode, Integer taxonFk, Integer kingdomFk, PesiExportState state) {
- try {
- Integer rankFk = getRankFk(taxonName, nomenclaturalCode);
+ private boolean invokeRankDataAndKingdomFk(TaxonName taxonName,
+ Integer taxonFk, Integer kingdomFk, PesiExportState state) {
+
+ try {
+ Integer rankFk = getRankFk(taxonName, kingdomFk);
if (rankFk != null) {
rankUpdateStmt.setInt(1, rankFk);
} else {
rankUpdateStmt.setObject(1, null);
}
- String rankCache = getRankCache(taxonName, nomenclaturalCode, state);
+ String rankCache = getRankCache(taxonName, kingdomFk, state);
if (rankCache != null) {
rankUpdateStmt.setString(2, rankCache);
} else {
* @param nomenclaturalCode The {@link NomenclaturalCode NomenclaturalCode}.
* @param taxonFk The TaxonFk to store the values for.
* @param typeNameFk The TypeNameFk.
+ * @param rankFk
* @param state
* @param kindomFk The KingdomFk.
* @param expertFk The ExpertFk.
* @param speciesExpertFk The SpeciesExpertFk.
* @return Whether save was successful or not.
*/
- private boolean invokeRankDataAndTypeNameFkAndKingdomFk(TaxonName taxonName, NomenclaturalCode nomenclaturalCode,
- Integer taxonFk, Integer typeNameFk, Integer kingdomFkk, PesiExportState state) {
- try {
+ private boolean invokeRankDataAndTypeNameFkAndKingdomFk(TaxonName taxonName,
+ Integer taxonFk, Integer typeNameFk, Integer kingdomFk, Integer rankFk, PesiExportState state) {
+
+ try {
int index = 1;
- Integer rankFk = getRankFk(taxonName, nomenclaturalCode);
if (rankFk != null) {
rankTypeExpertsUpdateStmt.setInt(index++, rankFk);
} else {
rankTypeExpertsUpdateStmt.setObject(index++, null);
}
- String rankCache = getRankCache(taxonName, nomenclaturalCode, state);
+ String rankCache = getRankCache(taxonName, kingdomFk, state);
if (rankCache != null) {
rankTypeExpertsUpdateStmt.setString(index++, rankCache);
} else {
rankTypeExpertsUpdateStmt.setObject(index++, null);
}
- if (kingdomFkk != null) {
- rankTypeExpertsUpdateStmt.setInt(index++, kingdomFkk);
+ if (kingdomFk != null) {
+ rankTypeExpertsUpdateStmt.setInt(index++, kingdomFk);
} else {
rankTypeExpertsUpdateStmt.setObject(index++, null);
}
rankTypeExpertsUpdateStmt.executeUpdate();
return true;
} catch (SQLException e) {
- logger.error("Data could not be inserted into database: " + e.getMessage());
+ String name = taxonName == null? null:taxonName.getTitleCache();
+ logger.error("Data could not be inserted into database: " + e.getMessage() + "; rankFk = " + rankFk + "; kingdomFk = " + kingdomFk + "; taxonFk = "+ taxonFk + "; typeNameFk = " + typeNameFk + "; name = " + name);
e.printStackTrace();
return false;
} catch (Exception e) {
- logger.error("Some exception occurred: " + e.getMessage());
+ String name = taxonName == null? null:taxonName.getTitleCache();
+ logger.error("Some exception occurred: " + e.getMessage() + "; rankFk = " + rankFk + "; kingdomFk = " + kingdomFk + "; taxonFk = "+ taxonFk + "; typeNameFk = " + typeNameFk + "; name = " + name);
e.printStackTrace();
return false;
}
* @return Whether the delete operation was successful or not.
*/
protected boolean doDelete(PesiExportState state) {
- PesiExportConfigurator pesiConfig = state.getConfig();
- String sql;
- Source destination = pesiConfig.getDestination();
+ Source destination = state.getConfig().getDestination();
- // Clear Taxon
- sql = "DELETE FROM " + dbTableName;
- destination.setQuery(sql);
- destination.update(sql);
- return true;
- }
-
- @Override
- protected boolean isIgnore(PesiExportState state) {
- return ! state.getConfig().isDoTaxa();
- }
+ String[] tables = new String[]{"AdditionalTaxonSource","CommonNameSource","CommonName",
+ "Image","NoteSource","Note","OccurrenceSource","Occurrence","RelTaxon","Taxon"};
-
- /**
- * Creates the kingdom fk.
- * @param taxonName
- * @return
- */
- @SuppressWarnings("unused") //used by mapper
- private static Integer getKingdomFk(TaxonName taxonName){
- return PesiTransformer.nomenClaturalCode2Kingdom(taxonName.getNomenclaturalCode());
- }
-
- /**
- * Creates the parent fk.
- * @param taxonName
- * @return
- */
- @SuppressWarnings("unused") //used by mapper
- private static Integer getParentTaxonFk(TaxonBase<?> taxonBase, PesiExportState state){
- if (taxonBase.isInstanceOf(Taxon.class)){
- Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
- if (! isMisappliedName(taxon)){
- Set<TaxonNode> nodes = taxon.getTaxonNodes();
- if (nodes.size() == 0){
- if (taxon.getName().getRank().isLower(Rank.KINGDOM())){
- logger.warn("Accepted taxon has no parent. " + taxon.getTitleCache() + ", " + taxon.getUuid());
- }
- }else if (nodes.size() > 1){
- logger.warn("Taxon has more than 1 node attached. This is not supported by PESI export." + taxon.getTitleCache() + ", " + taxon.getUuid());
- }else{
- Taxon parent =nodes.iterator().next().getParent().getTaxon();
- return state.getDbId(parent);
- }
- }
+ for(String table : tables){
+ String sql = "DELETE FROM " + table;
+ destination.update(sql);
}
- return null;
- }
- /**
- * Returns the rankFk for the taxon name based on the names nomenclatural code.
- * You may not use this method for kingdoms other then Animalia, Plantae and Bacteria.
- * @param taxonName
- * @return
- */
- @SuppressWarnings("unused") //used by mapper
- private static Integer getRankFk(TaxonName taxonName) {
- return getRankFk(taxonName, taxonName.getNomenclaturalCode());
+ return true;
}
+ private static Integer getRankFk(TaxonName taxonName, NomenclaturalCode nomenclaturalCode) {
+ Integer kingdomId = PesiTransformer.nomenclaturalCode2Kingdom(nomenclaturalCode);
+ return getRankFk(taxonName, kingdomId);
+ }
/**
* Returns the <code>RankFk</code> attribute.
* @return The <code>RankFk</code> attribute.
* @see MethodMapper
*/
- private static Integer getRankFk(TaxonName taxonName, NomenclaturalCode nomenclaturalCode) {
+ private static Integer getRankFk(TaxonName taxonName, Integer kingdomId) {
Integer result = null;
try {
- if (nomenclaturalCode != null) {
- if (taxonName != null) {
- if (taxonName.getRank() == null) {
- logger.warn("Rank is null: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- } else {
- result = PesiTransformer.rank2RankId(taxonName.getRank(), PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode));
- }
- if (result == null) {
- logger.warn("Rank could not be determined for PESI-Kingdom-Id " + PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode) + " and TaxonName " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
+ if (taxonName != null) {
+ if (taxonName.getRank() == null) {
+ logger.warn("Rank is null: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ } else {
+ result = PesiTransformer.rank2RankId(taxonName.getRank(), kingdomId);
+ }
+ if (result == null) {
+ logger.warn("Rank could not be determined for PESI-Kingdom-Id " + kingdomId + " and TaxonName " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
}
}
} catch (Exception e) {
return result;
}
- /**
- * Returns the rank cache for the taxon name based on the names nomenclatural code.
- * You may not use this method for kingdoms other then Animalia, Plantae and Bacteria.
- * @param taxonName
- * @return
- */
@SuppressWarnings("unused") //used by mapper
- private static String getRankCache(TaxonName taxonName, PesiExportState state) {
- return getRankCache(taxonName, taxonName.getNomenclaturalCode(), state);
- }
-
-
- /**
- * Returns the <code>RankCache</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @param nomenclaturalCode The {@link NomenclaturalCode NomenclaturalCode}.
- * @param state
- * @return The <code>RankCache</code> attribute.
- * @see MethodMapper
- */
- private static String getRankCache(TaxonName taxonName, NomenclaturalCode nomenclaturalCode, PesiExportState state) {
- if (nomenclaturalCode != null) {
- return state.getTransformer().getCacheByRankAndKingdom(taxonName.getRank(), PesiTransformer.nomenClaturalCode2Kingdom(nomenclaturalCode));
- }else{
- logger.warn("No nomenclatural code defined for name " + taxonName.getUuid());
+ private static String getRankCache(TaxonName taxonName, PesiExportState state) {
+ List<TaxonNode> nodes = getTaxonNodes(taxonName);
+ Integer kingdomId;
+ if (nodes == null||nodes.isEmpty()){
+ kingdomId = getKingdomFk(taxonName);
+ }else{
+ //should not happen, method exists only pure names
+ kingdomId = findKingdomIdFromTreeIndex(nodes.iterator().next().getTaxon(), state);
+ }
+ return getRankCache(taxonName, kingdomId, state);
+ }
+
+ private static String getRankCache(TaxonName taxonName, Integer kingdomFk, PesiExportState state) {
+ if (Rank.DOMAIN().equals(taxonName.getRank())){
+ return state.getTransformer().getCacheByRankAndKingdom(Rank.DOMAIN(), null);
+ }else if (kingdomFk != null) {
+ return state.getTransformer().getCacheByRankAndKingdom(taxonName.getRank(), kingdomFk);
+ }else if (taxonName.getNameType() != null){
+ return state.getTransformer().getCacheByRankAndKingdom(taxonName.getRank(), PesiTransformer.nomenclaturalCode2Kingdom(taxonName.getNameType()));
+ }else{
+ logger.warn("No kingdom ID could be defined for name " + taxonName.getUuid());
return null;
}
-
}
+ private static List<TaxonNode> getTaxonNodes(TaxonName taxonName) {
+ List<TaxonNode> result = new ArrayList<>();
+ for (TaxonBase<?> tb:taxonName.getTaxonBases()){
+ Taxon taxon;
+ //TODO handle ERMS taxon relationships
+ if (tb.isInstanceOf(Taxon.class)){
+ taxon = CdmBase.deproxy(tb, Taxon.class);
+ }else{
+ taxon = CdmBase.deproxy(tb, Synonym.class).getAcceptedTaxon();
+ }
+ if (isPesiTaxon(taxon)){
+ for (TaxonNode node : taxon.getTaxonNodes()){
+ result.add(node);
+ }
+ }
+ }
+ return result;
+ }
- /**
- * Returns the <code>DisplayName</code> attribute.
- * @param taxon The {@link TaxonBase Taxon}.
- * @return The <code>DisplayName</code> attribute.
- * @see MethodMapper
- */
- @SuppressWarnings("unused") //used by Mapper
- private static String getDisplayName(TaxonBase<?> taxon) {
- TaxonName taxonName = taxon.getName();
- String result = getDisplayName(taxonName);
- if (isMisappliedName(taxon)){
- result = result + " " + getAuthorString(taxon);
- }
- return result;
- }
+// @SuppressWarnings("unused") //used by pure name mapper and by getRankFk
+ private static Integer getKingdomFk(TaxonName taxonName){
+ EnumSet<PesiSource> origin = getSources(taxonName);
+ if (origin.size() == 1 && origin.contains(PesiSource.EM)){
+ //maybe simply replace by
+ //return PesiTransformer.KINGDOM_PLANTAE;
+ return PesiTransformer.nomenclaturalCode2Kingdom(taxonName.getNameType());
+ }else{
+ logger.warn("getKingdomFk not yet implemented for non-EuroMed pure names");
+ return null;
+ }
+ }
+
+ /**
+ * Returns the rankFk for the taxon name based on the names nomenclatural code.
+ * You may not use this method for kingdoms other then Animalia, Plantae and Bacteria.
+ */
+ @SuppressWarnings("unused") //used by pure name mapper
+ private static Integer getRankFk(TaxonName taxonName) {
+ EnumSet<PesiSource> origin = getSources(taxonName);
+ if (origin.size() == 1 && origin.contains(PesiSource.EM)){
+ return getRankFk(taxonName, getKingdomFk(taxonName));
+ }else{
+ logger.warn("getRankFk not yet implemented for non-EuroMed pure names");
+ return null;
+ }
+ }
/**
* Returns the <code>AuthorString</code> attribute.
* @return The <code>AuthorString</code> attribute.
* @see MethodMapper
*/
- @SuppressWarnings("unused") //used by mapper
+ //used by mapper
protected static String getAuthorString(TaxonBase<?> taxon) {
try {
- String result = null;
- boolean isNonViralName = false;
- String authorshipCache = null;
- TaxonName taxonName = taxon.getName();
- if (taxonName != null && taxonName.isNonViral()){
- authorshipCache = taxonName.getAuthorshipCache();
- isNonViralName = true;
- }
- result = authorshipCache;
-
- // For a misapplied names there are special rules
- if (isMisappliedName(taxon)){
- if (taxon.getSec() != null){
- String secTitle = taxon.getSec().getTitleCache();
- if (! secTitle.startsWith("auct")){
- secTitle = "sensu " + secTitle;
- }else if (secTitle.equals("auct")){ //may be removed once the title cache is generated correctly for references with title auct. #
- secTitle = "auct.";
- }
- return secTitle;
- }else if (StringUtils.isBlank(authorshipCache)) {
- // Set authorshipCache to "auct."
- result = PesiTransformer.AUCT_STRING;
- }else{
- result = PesiTransformer.AUCT_STRING;
-// result = authorshipCache;
- }
- }
+ // For misapplied names there are special rules
+ if (isMisappliedName(taxon)){
+ return getMisappliedNameAuthorship(taxon);
+ }else{
+ boolean isNonViralName = false;
+ String authorshipCache = null;
+ TaxonName taxonName = taxon.getName();
+ if (taxonName != null && taxonName.isNonViral()){
+ authorshipCache = taxonName.getAuthorshipCache();
+ isNonViralName = true;
+ }
+ String result = authorshipCache;
- if (taxonName == null){
- logger.warn("TaxonName does not exist for taxon: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
- }else if (! isNonViralName){
- logger.warn("TaxonName is not of instance NonViralName: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
+ if (taxonName == null){
+ logger.warn("TaxonName does not exist for taxon: " + taxon.getUuid() + " (" + taxon.getTitleCache() + ")");
+ }else if (! isNonViralName){
+ logger.warn("TaxonName is not of instance NonViralName: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ }
- if (StringUtils.isBlank(result)) {
- return null;
- } else {
- return result;
- }
+ if (StringUtils.isBlank(result)) {
+ return null;
+ } else {
+ return result;
+ }
+ }
} catch (Exception e) {
e.printStackTrace();
return null;
}
+ }
+ private static String getMisappliedNameAuthorship(TaxonBase<?> taxon){
+ String result;
+ String relAppendedPhrase = taxon.getAppendedPhrase();
+ Reference sec = taxon.getSec();
+ String secTitle = sec != null ? sec.getTitleCache(): null;
+ if(relAppendedPhrase == null && sec == null) {
+ result = "auct.";
+ }else if (relAppendedPhrase != null && sec == null){
+ result = relAppendedPhrase;
+ }else if (relAppendedPhrase == null && sec != null){
+ result = "sensu " + secTitle;
+ }else{ //append!=null && sec!=null
+ result = relAppendedPhrase + " " + secTitle;
+ }
+ String authorship = taxon.getName().getAuthorshipCache();
+ if (isNotBlank(authorship)){
+ result += ", non " + authorship;
+ }
+ return result;
}
+ /**
+ * Returns the <code>DisplayName</code> attribute.
+ * @param taxon The {@link TaxonBase Taxon}.
+ * @return The <code>DisplayName</code> attribute.
+ * @see MethodMapper
+ */
+ //used by Mapper
+ private static String getDisplayName(TaxonBase<?> taxon) {
+ boolean isMisapplied = isMisappliedName(taxon);
+ TaxonName taxonName = taxon.getName();
+ String result = getDisplayName(taxonName, isMisapplied);
+ if (isMisapplied){
+ result = result + " " + getMisappliedNameAuthorship(taxon);
+ }
+ return result;
+ }
+
+ /**
+ * Returns the <code>DisplayName</code> attribute.
+ * @param taxonName The {@link TaxonNameBase TaxonName}.
+ * @return The <code>DisplayName</code> attribute.
+ * @see MethodMapper
+ */
+ @SuppressWarnings("unused") //used by Mapper
+ private static String getDisplayName(TaxonName taxonName) {
+ return getDisplayName(taxonName, false);
+ }
- /**
- * Returns the <code>DisplayName</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @return The <code>DisplayName</code> attribute.
- * @see MethodMapper
- */
- @SuppressWarnings("unused") //used by Mapper
- private static String getDisplayName(TaxonName taxonName) {
- // TODO: extension?
+ private static String getDisplayName(TaxonName taxonName, boolean useNameCache) {
if (taxonName == null) {
return null;
}else{
+ taxonName = CdmBase.deproxy(taxonName);
INonViralNameCacheStrategy cacheStrategy = getCacheStrategy(taxonName);
HTMLTagRules tagRules = new HTMLTagRules().
addRule(TagEnum.name, "i").
addRule(TagEnum.nomStatus, "@status@");
- TaxonName nvn = CdmBase.deproxy(taxonName);
- String result = cacheStrategy.getFullTitleCache(nvn, tagRules);
- cacheStrategy = null;
- nvn = null;
- return result.replaceAll(",?\\<@status@\\>.*\\</@status@\\>", "");
+ String result;
+ if (useNameCache){
+ result = cacheStrategy.getNameCache(taxonName, tagRules);
+ }else{
+ EnumSet<PesiSource> sources = getSources(taxonName);
+ if (sources.contains(PesiSource.ERMS)){
+ result = cacheStrategy.getTitleCache(taxonName, tagRules); //according to SQL script (also in ERMS sources are not abbreviated)
+ }else if (sources.contains(PesiSource.FE) || sources.contains(PesiSource.IF)){
+ //TODO define for FE + IF and for multiple sources
+ result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
+ }else if (sources.contains(PesiSource.EM)){
+ result = cacheStrategy.getFullTitleCache(taxonName, tagRules);
+ }else{
+ logger.warn("Source not yet handled");
+ result = cacheStrategy.getTitleCache(taxonName, tagRules);
+ }
+ result = replaceTagForInfraSpecificMarkerForProtectedTitleCache(taxonName, result);
+ result = result.replaceAll("(, ?)?\\<@status@\\>.*\\</@status@\\>", "").trim();
+ }
+ return result;
}
}
- @SuppressWarnings("unused")
- private static String getGUID(TaxonName taxonName) {
- UUID uuid = taxonName.getUuid();
- String result = "NameUUID:" + uuid.toString();
- return result;
- }
-
-
/**
* Returns the <code>WebShowName</code> attribute for a taxon.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
+ * See {@link #getWebShowName(TaxonName)} for further explanations.
+ * @param taxon The {@link TaxonBase taxon}.
* @return The <code>WebShowName</code> attribute.
+ * @see #getWebShowName(TaxonName)
+ * @see #getDisplayName(TaxonBase)
+ * @see #getFullName(TaxonBase)
* @see MethodMapper
*/
@SuppressWarnings("unused")
private static String getWebShowName(TaxonBase<?> taxon) {
- TaxonName taxonName = taxon.getName();
- String result = getWebShowName(taxonName);
- if (isMisappliedName(taxon)){
- result = result + " " + getAuthorString(taxon);
- }
- return result;
+ if (isMisappliedName(taxon)){
+ //for misapplications the webshowname is the same as the displayname as they do not show the nom.ref. in displayname
+ return getDisplayName(taxon);
+ }else{
+ TaxonName taxonName = taxon.getName();
+ return getWebShowName(taxonName);
+ }
}
/**
- * Returns the <code>WebShowName</code> attribute.
+ * Returns the <code>WebShowName</code> attribute for a name. The
+ * <code>WebShowName</code> is like fullName but with
+ * tagged (<i>) name part. It is also similar to
+ * <code>DisplayName</code> but for titleCache not fullTitleCache.
+ * For misapplications it slightly differs (see {@link #getWebShowName(TaxonBase)} )
+ *
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @return The <code>WebShowName</code> attribute.
+ * @see #getDisplayName(TaxonName)
+ * @see #getFullName(TaxonName)
+ * @see #getWebShowName(TaxonBase)
* @see MethodMapper
*/
private static String getWebShowName(TaxonName taxonName) {
- //TODO extensions?
if (taxonName == null) {
return null;
}else{
- INonViralNameCacheStrategy cacheStrategy = getCacheStrategy(taxonName);
+ taxonName = CdmBase.deproxy(taxonName);
+ INonViralNameCacheStrategy cacheStrategy = getCacheStrategy(taxonName);
HTMLTagRules tagRules = new HTMLTagRules().addRule(TagEnum.name, "i");
String result = cacheStrategy.getTitleCache(taxonName, tagRules);
+ result = replaceTagForInfraSpecificMarkerForProtectedTitleCache(taxonName, result);
return result;
}
}
+ private static String replaceTagForInfraSpecificMarkerForProtectedTitleCache(TaxonName taxonName, String result) {
+ if (taxonName.isProtectedTitleCache()||taxonName.isProtectedNameCache()){
+ if (!taxonName.isAutonym()){
+ result = result
+ .replace(" subsp. ", "</i> subsp. <i>")
+ .replace(" var. ", "</i> var. <i>")
+ .replace(" subvar. ", "</i> subvar. <i>")
+ .replace(" f. ", "</i> f. <i>")
+ .replace(" subf. ", "</i> subf. <i>") //does this exist?
+ ;
+ }
+ }
+ return result;
+ }
- /**
+ /**
* Returns the <code>WebSearchName</code> attribute.
* @param taxonName The {@link NonViralName NonViralName}.
* @return The <code>WebSearchName</code> attribute.
@SuppressWarnings("unused")
private static String getWebSearchName(TaxonName taxonName) {
//TODO extensions?
- NonViralNameDefaultCacheStrategy strategy = getCacheStrategy(taxonName);
+ TaxonNameDefaultCacheStrategy strategy = getCacheStrategy(taxonName);
String result = strategy.getNameCache(taxonName);
return result;
}
+ @SuppressWarnings("unused") //used by mapper
+ private static String getFullName(TaxonBase<?> taxon) {
+ if (isMisappliedName(taxon)){
+ String result = getCacheStrategy(taxon.getName()).getNameCache(taxon.getName());
+ result = result + " " + getMisappliedNameAuthorship(taxon);
+ return result;
+ }else{
+ return getFullName(taxon.getName());
+ }
+ }
/**
* Returns the <code>FullName</code> attribute.
* @return The <code>FullName</code> attribute.
* @see MethodMapper
*/
- @SuppressWarnings("unused")
+ //used by mapper
private static String getFullName(TaxonName taxonName) {
//TODO extensions?
String result = getCacheStrategy(taxonName).getTitleCache(taxonName);
- Iterator<Taxon> taxa = taxonName.getTaxa().iterator();
- if (taxonName.getTaxa().size() >0){
- if (taxonName.getTaxa().size() == 1){
- Taxon taxon = taxa.next();
- if (isMisappliedName(taxon)){
- result = result + " " + getAuthorString(taxon);
- }
- taxon = null;
- }
- }
+ //misapplied names are now handled differently in getFullName(TaxonBase)
+// Iterator<Taxon> taxa = taxonName.getTaxa().iterator();
+// if (taxonName.getTaxa().size() >0){
+// if (taxonName.getTaxa().size() == 1){
+// Taxon taxon = taxa.next();
+// if (isMisappliedName(taxon)){
+// result = result + " " + getAuthorString(taxon);
+// }
+// }
+// }
return result;
}
+ @SuppressWarnings("unused")
+ private static String getGUID(TaxonName taxonName) {
+ UUID uuid = taxonName.getUuid();
+ String result = "NameUUID:" + uuid.toString();
+ return result;
+ }
+
+ static boolean isFirstAbbrevTitle = true;
/**
* Returns the SourceNameCache for the AdditionalSource table
- * @param taxonName
- * @return
*/
@SuppressWarnings("unused")
private static String getSourceNameCache(TaxonName taxonName) {
if (taxonName != null){
- Reference nomRef = (Reference)taxonName.getNomenclaturalReference();
- if (nomRef != null){
- logger.warn("Semantics of getAbbrevTitleCache has changed. Please check if output is still correct. See #5388");
- return nomRef.getAbbrevTitleCache();
+ Reference nomRef = taxonName.getNomenclaturalReference();
+ if (nomRef != null ){
+ if (isFirstAbbrevTitle){
+ //#5388 is definetely not the correct ticket number
+ logger.warn("Semantics of getAbbrevTitleCache has changed. Please check if output is still correct. See #5388");
+ isFirstAbbrevTitle = false;
+ }
+ return nomRef.getAbbrevTitleCache();
}
}
return null;
}
-
-
- /**
- * Returns the <code>FullName</code> attribute.
- * @param taxon The {@link TaxonBase taxon}.
- * @return The <code>FullName</code> attribute.
- * @see MethodMapper
- */
- /*@SuppressWarnings("unused")
- private static String getFullName(TaxonBase taxon) {
- //TODO extensions?
- TaxonNameBase name = taxon.getName();
- String result = getFullName(name);
- if (isMisappliedName(taxon)){
- result = result + " " + getAuthorString(taxon);
- }
-
- return result;
- }
-*/
-
/**
* Returns the nomenclatural reference which is the reference
* including the detail (microreference).
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @return The <code>AuthorString</code> attribute.
+ * @param taxonName The {@link TaxonName taxon name}.
* @see MethodMapper
*/
@SuppressWarnings("unused")
if (ref == null){
return null;
}
- if (! ref.isProtectedAbbrevTitleCache()){
- ref.setAbbrevTitleCache(null, false); //to remove a false cache
+ String result = null;
+ EnumSet<PesiSource> sources = getSources(taxonName);
+ if(sources.contains(PesiSource.EM)){
+ if (! ref.isProtectedAbbrevTitleCache()){
+ ref.setAbbrevTitleCache(null, false); //to remove a false cache
+ }
+ result = ref.getNomenclaturalCitation(taxonName.getNomenclaturalMicroReference());
+ }else if(sources.contains(PesiSource.FE)||sources.contains(PesiSource.IF) ){
+ //TODO still need to check if correct for FE + IF
+ if (! ref.isProtectedAbbrevTitleCache()){
+ ref.setAbbrevTitleCache(null, false); //to remove a false cache
+ }
+ result = ref.getNomenclaturalCitation(taxonName.getNomenclaturalMicroReference());
+ return result; // according to SQL script
+ }else if(sources.contains(PesiSource.ERMS)) {
+ //result = null; //according to SQL script
+ }else{
+ logger.warn("Source not yet supported");
}
- return ref.getNomenclaturalCitation(taxonName.getNomenclaturalMicroReference());
+ return result;
}
-
/**
* Returns the <code>NameStatusFk</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
private static Integer getNameStatusFk(TaxonName taxonName) {
Integer result = null;
- NomenclaturalStatus state = getNameStatus(taxonName);
- if (state != null) {
- result = PesiTransformer.nomStatus2nomStatusFk(state.getType());
+ NomenclaturalStatus status = getNameStatus(taxonName);
+ if (status != null) {
+ result = PesiTransformer.nomStatus2nomStatusFk(status.getType());
}
return result;
}
return result;
}
-
private static NomenclaturalStatus getNameStatus(TaxonName taxonName) {
try {
if (taxonName != null) {
Set<NomenclaturalStatus> states = taxonName.getStatus();
- if (states.size() == 1) {
- NomenclaturalStatus status = states.iterator().next();
+ if (states.size() >= 1) {
+ if (states.size() > 1) {
+ String statusStr = null;
+ for (NomenclaturalStatus status: states){
+ statusStr = CdmUtils.concat(",", statusStr, status.getType()== null? null:status.getType().getTitleCache());
+ }
+ //a known case is ad43508a-8a10-480a-8519-2a76de2c0a0f (Labiatae Juss.) from E+M
+ logger.warn("This TaxonName has more than one nomenclatural status. This may happen in very rare cases but is not handled by the PESI data warehouse. Taxon name: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")Status:" + statusStr);
+ }
+ NomenclaturalStatus status = states.iterator().next();
return status;
- } else if (states.size() > 1) {
- logger.error("This TaxonName has more than one Nomenclatural Status: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
}
}
-
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
+
/**
* Returns the <code>TaxonStatusFk</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @see MethodMapper
*/
private static Integer getTaxonStatusFk(TaxonBase<?> taxon, PesiExportState state) {
- Integer result = null;
-
try {
- if (isMisappliedName(taxon)) {
- Synonym synonym = Synonym.NewInstance(null, null);
-
- // This works as long as only the instance is important to differentiate between TaxonStatus.
- result = PesiTransformer.taxonBase2statusFk(synonym); // Auct References are treated as Synonyms in Datawarehouse now.
- } else {
- result = PesiTransformer.taxonBase2statusFk(taxon);
- }
-
+ return PesiTransformer.taxonBase2statusFk(taxon);
} catch (Exception e) {
e.printStackTrace();
+ return null;
}
- return result;
}
/**
return state.getTransformer().getTaxonStatusCacheByKey(getTaxonStatusFk(taxon, state));
}
+ /**
+ * Returns the <code>TaxonFk1</code> attribute. It corresponds to a CDM <code>TaxonRelationship</code>.
+ * @param relationship The {@link RelationshipBase Relationship}.
+ * @param state The {@link PesiExportState PesiExportState}.
+ * @return The <code>TaxonFk1</code> attribute.
+ * @see MethodMapper
+ */
+ @SuppressWarnings("unused")
+ private static Integer getSynonym(Synonym synonym, PesiExportState state) {
+ return state.getDbId(synonym);
+ }
+
/**
* Returns the <code>TypeNameFk</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @return The <code>TypeNameFk</code> attribute.
* @see MethodMapper
*/
- private static Integer getTypeNameFk(TaxonName taxonNameBase, PesiExportState state) {
+ private static Integer getTypeNameFk(TaxonName taxonName, PesiExportState state) {
Integer result = null;
- if (taxonNameBase != null) {
- Set<NameTypeDesignation> nameTypeDesignations = taxonNameBase.getNameTypeDesignations();
+ if (taxonName != null) {
+ Set<NameTypeDesignation> nameTypeDesignations = taxonName.getNameTypeDesignations();
if (nameTypeDesignations.size() == 1) {
NameTypeDesignation nameTypeDesignation = nameTypeDesignations.iterator().next();
if (nameTypeDesignation != null) {
TaxonName typeName = nameTypeDesignation.getTypeName();
if (typeName != null) {
- result = state.getDbId(typeName);
+ if (typeName.getTaxonBases().isEmpty()){
+ logger.warn("Type name does not belong to a taxon and therefore is not expected to be a European taxon. Type name not added. Type name: " + typeName.getTitleCache() + ", typified name: " + taxonName.getTitleCache());
+ }else{
+ result = state.getDbId(typeName);
+ }
}
}
} else if (nameTypeDesignations.size() > 1) {
- logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonNameBase.getUuid() + " (" + taxonNameBase.getTitleCache() + ")");
+ logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
}
}
return result;
String result = null;
try {
- if (taxonName != null) {
- Set<NameTypeDesignation> nameTypeDesignations = taxonName.getNameTypeDesignations();
- if (nameTypeDesignations.size() == 1) {
- NameTypeDesignation nameTypeDesignation = nameTypeDesignations.iterator().next();
- if (nameTypeDesignation != null) {
- TaxonName typeName = nameTypeDesignation.getTypeName();
- if (typeName != null) {
- result = typeName.getTitleCache();
- }
- }
- } else if (nameTypeDesignations.size() > 1) {
- logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
- }
-
+ if (taxonName != null) {
+ Set<NameTypeDesignation> nameTypeDesignations = taxonName.getNameTypeDesignations();
+ if (nameTypeDesignations.size() == 1) {
+ NameTypeDesignation nameTypeDesignation = nameTypeDesignations.iterator().next();
+ if (nameTypeDesignation != null) {
+ TaxonName typeName = nameTypeDesignation.getTypeName();
+ if (typeName != null) {
+ result = typeName.getTitleCache();
+ }
+ }
+ } else if (nameTypeDesignations.size() > 1) {
+ logger.warn("This TaxonName has " + nameTypeDesignations.size() + " NameTypeDesignations: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ }
+ }
} catch (Exception e) {
e.printStackTrace();
}
* @see MethodMapper
*/
private static Integer getQualityStatusFk(TaxonName taxonName) {
- BitSet sources = getSources(taxonName);
+ EnumSet<PesiSource> sources = getSources(taxonName);
return PesiTransformer.getQualityStatusKeyBySource(sources, taxonName);
}
-
/**
* Returns the <code>QualityStatusCache</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @return The <code>TypeDesignationStatusFk</code> attribute.
* @see MethodMapper
*/
- @SuppressWarnings("unused")
+ //TODO seems not to be used
private static Integer getTypeDesignationStatusFk(TaxonName taxonName) {
Integer result = null;
try {
- if (taxonName != null) {
- Set<NameTypeDesignation> typeDesignations = taxonName.getNameTypeDesignations();
- if (typeDesignations.size() == 1) {
- Object obj = typeDesignations.iterator().next().getTypeStatus();
- NameTypeDesignationStatus designationStatus = CdmBase.deproxy(obj, NameTypeDesignationStatus.class);
- result = PesiTransformer.nameTypeDesignationStatus2TypeDesignationStatusId(designationStatus);
- } else if (typeDesignations.size() > 1) {
- logger.error("Found a TaxonName with more than one NameTypeDesignation: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
- }
-
+ if (taxonName != null) {
+ Set<NameTypeDesignation> typeDesignations = taxonName.getNameTypeDesignations();
+ if (typeDesignations.size() == 1) {
+ Object obj = typeDesignations.iterator().next().getTypeStatus();
+ NameTypeDesignationStatus designationStatus = CdmBase.deproxy(obj, NameTypeDesignationStatus.class);
+ result = PesiTransformer.nameTypeDesignationStatus2TypeDesignationStatusId(designationStatus);
+ } else if (typeDesignations.size() > 1) {
+ logger.error("Found a TaxonName with more than one NameTypeDesignation: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ }
+ }
} catch (Exception e) {
e.printStackTrace();
}
* @return The <code>TypeDesignationStatusCache</code> attribute.
* @see MethodMapper
*/
- @SuppressWarnings("unused")
+ //TODO seems not to be used
private static String getTypeDesignationStatusCache(TaxonName taxonName) {
String result = null;
try {
- if (taxonName != null) {
- Set<NameTypeDesignation> typeDesignations = taxonName.getNameTypeDesignations();
- if (typeDesignations.size() == 1) {
- Object obj = typeDesignations.iterator().next().getTypeStatus();
- NameTypeDesignationStatus designationStatus = CdmBase.deproxy(obj, NameTypeDesignationStatus.class);
- result = PesiTransformer.nameTypeDesignationStatus2TypeDesignationStatusCache(designationStatus);
- } else if (typeDesignations.size() > 1) {
- logger.error("Found a TaxonName with more than one NameTypeDesignation: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- }
- }
-
+ if (taxonName != null) {
+ Set<NameTypeDesignation> typeDesignations = taxonName.getNameTypeDesignations();
+ if (typeDesignations.size() == 1) {
+ Object obj = typeDesignations.iterator().next().getTypeStatus();
+ NameTypeDesignationStatus designationStatus = CdmBase.deproxy(obj, NameTypeDesignationStatus.class);
+ result = PesiTransformer.nameTypeDesignationStatus2TypeDesignationStatusCache(designationStatus);
+ } else if (typeDesignations.size() > 1) {
+ logger.error("Found a TaxonName with more than one NameTypeDesignation: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
+ }
+ }
} catch (Exception e) {
e.printStackTrace();
}
private static Integer getFossilStatusFk(IdentifiableEntity<?> identEntity, PesiExportState state) {
Integer result = null;
- Set<String> fossilStatuus = identEntity.getExtensions(ErmsTransformer.uuidFossilStatus);
+ Set<String> fossilStatuus = identEntity.getExtensions(ErmsTransformer.uuidExtFossilStatus);
if (fossilStatuus.size() == 0){
return null;
}else if (fossilStatuus.size() > 1){
}
String fossilStatus = fossilStatuus.iterator().next();
- int statusFk = state.getTransformer().FossilStatusCache2FossilStatusFk(fossilStatus);
+ int statusFk = state.getTransformer().fossilStatusCache2FossilStatusFk(fossilStatus);
return statusFk;
}
@SuppressWarnings("unused")
private static String getFossilStatusCache(IdentifiableEntity<?> identEntity, PesiExportState state) {
String result = null;
- Set<String> fossilStatuus = identEntity.getExtensions(ErmsTransformer.uuidFossilStatus);
+ Set<String> fossilStatuus = identEntity.getExtensions(ErmsTransformer.uuidExtFossilStatus);
if (fossilStatuus.size() == 0){
return null;
}
* @see MethodMapper
*/
@SuppressWarnings("unused")
- private static String getIdInSource(IdentifiableEntity taxonName) {
+ private static String getIdInSource(IdentifiableEntity<?> taxonName) {
String result = null;
try {
Reference ref = source.getCitation();
UUID refUuid = ref.getUuid();
String idInSource = source.getIdInSource();
- if (refUuid.equals(BerlinModelTransformer.uuidSourceRefEuroMed)){
+ if (refUuid.equals(PesiTransformer.uuidSourceRefEuroMed)){
result = idInSource != null ? ("NameId: " + source.getIdInSource()) : null;
}else if (refUuid.equals(PesiTransformer.uuidSourceRefFaunaEuropaea)){
result = idInSource != null ? ("TAX_ID: " + source.getIdInSource()) : null;
}else if (refUuid.equals(PesiTransformer.uuidSourceRefIndexFungorum)){ //Index Fungorum
result = idInSource != null ? ("if_id: " + source.getIdInSource()) : null;
}else{
- if (logger.isDebugEnabled()){logger.debug("Not a PESI source");};
+ if (logger.isDebugEnabled()){logger.debug("Not a PESI source");}
}
String sourceIdNameSpace = source.getIdNamespace();
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @return The idInSource.
*/
- private static String getIdInSourceOnly(IdentifiableEntity identEntity) {
+ private static String getIdInSourceOnly(IdentifiableEntity<?> identEntity) {
String result = null;
// Get the sources first
return result;
}
- /**
- * Returns the Sources for a given TaxonName only.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @return The Sources.
- */
- private static Set<IdentifiableSource> getPesiSources(IdentifiableEntity identEntity) {
- Set<IdentifiableSource> sources = new java.util.HashSet<IdentifiableSource>();
-
- //Taxon Names
- if (identEntity.isInstanceOf(TaxonName.class)){
- // Sources from TaxonName
- TaxonName taxonName = CdmBase.deproxy(identEntity, TaxonName.class);
- Set<IdentifiableSource> testSources = identEntity.getSources();
- sources = filterPesiSources(identEntity.getSources());
-
- if (sources.size() == 0 && testSources.size()>0){
- IdentifiableSource source = testSources.iterator().next();
- logger.warn("There are sources, but they are no pesi sources!!!" + source.getIdInSource() + " - " + source.getIdNamespace() + " - " + source.getCitation().getTitleCache());
- }
- if (sources.size() > 1) {
- logger.warn("This TaxonName has more than one Source: " + identEntity.getUuid() + " (" + identEntity.getTitleCache() + ")");
- }
-
- // name has no PESI source, take sources from TaxonBase
- if (sources == null || sources.isEmpty()) {
- Set<TaxonBase> taxa = taxonName.getTaxonBases();
- for (TaxonBase taxonBase: taxa){
- sources.addAll(filterPesiSources(taxonBase.getSources()));
- }
- }
-
- //for TaxonBases
- }else if (identEntity.isInstanceOf(TaxonBase.class)){
- sources = filterPesiSources(identEntity.getSources());
- }
-
- /*TODO: deleted only for testing the inferred synonyms
- if (sources == null || sources.isEmpty()) {
- logger.warn("This TaxonName has no PESI Sources: " + identEntity.getUuid() + " (" + identEntity.getTitleCache() +")");
- }else if (sources.size() > 1){
- logger.warn("This Taxon(Name) has more than 1 PESI source: " + identEntity.getUuid() + " (" + identEntity.getTitleCache() +")");
- }
- */
- return sources;
- }
-
- // return all sources with a PESI reference
- private static Set<IdentifiableSource> filterPesiSources(Set<? extends IdentifiableSource> sources) {
- Set<IdentifiableSource> result = new HashSet<IdentifiableSource>();
- for (IdentifiableSource source : sources){
- Reference ref = source.getCitation();
- UUID refUuid = ref.getUuid();
- if (refUuid.equals(BerlinModelTransformer.uuidSourceRefEuroMed) ||
- refUuid.equals(PesiTransformer.uuidSourceRefFaunaEuropaea)||
- refUuid.equals(PesiTransformer.uuidSourceRefErms)||
- refUuid.equals(PesiTransformer.uuidSourceRefIndexFungorum) ||
- refUuid.equals(PesiTransformer.uuidSourceRefAuct)){
- result.add(source);
- }
- }
- return result;
- }
-
/**
* Returns the <code>GUID</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
}
}
-
-
-
/**
* Returns the <code>DerivedFromGuid</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @see MethodMapper
*/
@SuppressWarnings("unused")
- private static String getCacheCitation(TaxonBase taxon) {
+ private static String getCacheCitation(TaxonBase<?> taxon) {
// !!! See also doPhaseUpdates
TaxonName taxonName = taxon.getName();
String result = "";
//TODO implement anew for taxa
try {
- BitSet sources = getSources(taxonName);
+ EnumSet<PesiSource> sources = getSources(taxon);
+ //TODO what if 2 sources? In PESI 2014 they were pipe separated
+ //TODO why does ERMS use accessed through eu-nomen, while E+M uses accessed through E+M
if (sources.isEmpty()) {
// logger.error("OriginalDB is NULL for this TaxonName: " + taxonName.getUuid() + " (" + taxonName.getTitleCache() + ")");
- } else if (sources.get(PesiTransformer.SOURCE_ERMS)) {
- // TODO: 19.08.2010: An import of CacheCitation does not exist in the ERMS import yet or it will be imported in a different way...
- // So the following code is some kind of harmless assumption.
- Set<Extension> extensions = taxonName.getExtensions();
+ } else if (sources.contains(PesiSource.ERMS)) {
+ //TODO check if correct, compare with PESI 2014
+ Set<Extension> extensions = taxon.getExtensions();
for (Extension extension : extensions) {
if (extension.getType().equals(cacheCitationExtensionType)) {
result = extension.getValue();
}
}
+ } else if (sources.contains(PesiSource.EM)) {
+ //TODO
+ boolean isMisapplied = isMisappliedName(taxon);
+ boolean isProParteSyn = isProParteOrPartialSynonym(taxon);
+ Reference sec = null;
+ if(!isMisapplied && !isProParteSyn){
+ sec = taxon.getSec();
+ }else if (isMisapplied){
+ sec = getAcceptedTaxonForMisappliedName(taxon).getSec();
+ }else if (isProParteSyn){
+ sec = getAcceptedTaxonForProParteSynonym(taxon).getSec();
+ }
+ if (sec == null){
+ logger.warn("Sec could not be defined for taxon " + taxon.getTitleCache()+ "; " + taxon.getUuid());
+ }
+ String author = sec == null? "" : sec.getTitleCache();
+ String webShowName = isMisapplied? getDisplayName(taxon):getWebShowName(taxonName); //for misapplied we need also the sensu and non author part, for ordinary names name + author is enough
+ String accessed = ". Accessed through: Euro+Med PlantBase at https://www.europlusmed.org/cdm_dataportal/taxon/";
+ result = CdmUtils.removeTrailingDot(author)
+ + ". " + CdmUtils.removeTrailingDot(webShowName)
+ + accessed + taxon.getUuid();
} else {
- String expertName = getExpertName(taxon);
+ //TODO check for IF + FE
+
+ String expertName = getExpertName(taxon);
String webShowName = getWebShowName(taxonName);
// idInSource only
/**
* Returns the <code>OriginalDB</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
+ * @param identifiableEntity
* @return The <code>OriginalDB</code> attribute.
* @see MethodMapper
*/
- private static String getOriginalDB(IdentifiableEntity identEntity) {
- // Sources from TaxonName
- BitSet sources = getSources(identEntity);
+// @SuppressWarnings("unused")
+ private static String getOriginalDB(IdentifiableEntity<?> identifiableEntity) {
+ EnumSet<PesiSource> sources = getSources(identifiableEntity);
return PesiTransformer.getOriginalDbBySources(sources);
}
- /**
- * Returns the <code>LastAction</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @return The <code>LastAction</code> attribute.
- * @see MethodMapper
- */
- @SuppressWarnings("unused")
- private static String getLastAction(IdentifiableEntity<?> identEntity) {
- String result = null;
- try {
- Set<Extension> extensions = identEntity.getExtensions();
- for (Extension extension : extensions) {
- if (extension.getType().equals(lastActionExtensionType)) {
- result = extension.getValue();
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
- /**
- * Returns the <code>LastActionDate</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @return The <code>LastActionDate</code> attribute.
- * @see MethodMapper
- */
- @SuppressWarnings({ "unused" })
- private static DateTime getLastActionDate(IdentifiableEntity identEntity) {
- DateTime result = null;
- try {
- Set<Extension> extensions = identEntity.getExtensions();
- for (Extension extension : extensions) {
- if (extension.getType().equals(lastActionDateExtensionType)) {
- String dateTime = extension.getValue();
- if (dateTime != null) {
- DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss.S");
- result = formatter.parseDateTime(dateTime);
- }
- }
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- return result;
- }
-
/**
* Returns the <code>ExpertName</code> attribute.
* @param taxonName The {@link TaxonNameBase TaxonName}.
* @return The <code>ExpertName</code> attribute.
* @see MethodMapper
*/
- @SuppressWarnings("unused")
- private static String getExpertName(TaxonBase<?> taxonName) {
- String result = null;
+ @SuppressWarnings("unused") //for some reason it is also called by getCacheCitation
+ private static String getExpertName(TaxonBase<?> taxon) {
try {
- Set<Extension> extensions = taxonName.getExtensions();
- for (Extension extension : extensions) {
- if (extension.getType().equals(expertNameExtensionType)) {
- result = extension.getValue();
- }
- }
+ String result = null;
+ if(expertNameExtensionType!=null){ //some databases do not have this extension type
+ Set<Extension> extensions = taxon.getExtensions();
+ for (Extension extension : extensions) {
+ if (extension.getType().equals(expertNameExtensionType)) {
+ result = extension.getValue();
+ }
+ }
+ }
+ if (getPesiSources(taxon).contains(PesiSource.EM)){
+ return taxon.getSec().getTitleCache();
+ }
+ return null;
} catch (Exception e) {
e.printStackTrace();
+ return null;
}
- return result;
}
- /**
- * Returns the <code>ExpertFk</code> attribute.
- * @param taxonName The {@link TaxonNameBase TaxonName}.
- * @param state The {@link PesiExportState PesiExportState}.
- * @return The <code>ExpertFk</code> attribute.
- * @see MethodMapper
- */
+ //TODO change to ExpertGUID
private static Integer getExpertFk(Reference reference, PesiExportState state) {
Integer result = state.getDbId(reference);
return result;
* @see MethodMapper
*/
@SuppressWarnings("unused")
- private static String getSpeciesExpertName(TaxonBase<?> taxonName) {
- String result = null;
+ private static String getSpeciesExpertName(TaxonBase<?> taxon) {
try {
- Set<Extension> extensions = taxonName.getExtensions();
- for (Extension extension : extensions) {
- if (extension.getType().equals(speciesExpertNameExtensionType)) {
- result = extension.getValue();
- }
- }
+ Set<Extension> extensions = taxon.getExtensions();
+ if(speciesExpertNameExtensionType != null){ //some databases do not have this extension type
+ for (Extension extension : extensions) {
+ if (extension.getType().equals(speciesExpertNameExtensionType)) {
+ return extension.getValue();
+ }
+ }
+ }
+ if (getPesiSources(taxon).contains(PesiSource.EM)){
+ return taxon.getSec().getTitleCache();
+ }
+ return null;
} catch (Exception e) {
e.printStackTrace();
+ return null;
}
- return result;
}
/**
* @return The <code>SpeciesExpertFk</code> attribute.
* @see MethodMapper
*/
+ //TODO should be changed to SpeciesExpertGUID
private static Integer getSpeciesExpertFk(Reference reference, PesiExportState state) {
Integer result = state.getDbId(reference);
return result;
}
-
- /**
- * Returns the source (E+M, Fauna Europaea, Index Fungorum, ERMS) of a given
- * Identifiable Entity as a BitSet
- * @param identEntity
- * @return
- */
- private static BitSet getSources(IdentifiableEntity<?> identEntity){
- BitSet bitSet = new BitSet();
- Set<IdentifiableSource> sources = getPesiSources(identEntity);
- for (IdentifiableSource source : sources) {
- Reference ref = source.getCitation();
- UUID refUuid = ref.getUuid();
- if (refUuid.equals(BerlinModelTransformer.uuidSourceRefEuroMed)){
- bitSet.set(PesiTransformer.SOURCE_EM);
- }else if (refUuid.equals(PesiTransformer.uuidSourceRefFaunaEuropaea)){
- bitSet.set(PesiTransformer.SOURCE_FE);
- }else if (refUuid.equals(PesiTransformer.uuidSourceRefErms)){
- bitSet.set(PesiTransformer.SOURCE_ERMS);
- }else if (refUuid.equals(PesiTransformer.uuidSourceRefIndexFungorum)){
- bitSet.set(PesiTransformer.SOURCE_IF);
- }else{
- if (logger.isDebugEnabled()){logger.debug("Not a PESI source");};
- }
- }
- return bitSet;
-
- }
-
- protected static NonViralNameDefaultCacheStrategy getCacheStrategy(TaxonName taxonName) {
+ protected static TaxonNameDefaultCacheStrategy getCacheStrategy(TaxonName taxonName) {
taxonName = CdmBase.deproxy(taxonName);
- NonViralNameDefaultCacheStrategy cacheStrategy;
+ TaxonNameDefaultCacheStrategy cacheStrategy;
if (taxonName.isZoological()){
cacheStrategy = zooNameStrategy;
}else if (taxonName.isBotanical()) {
private static Integer getRelTaxonQualifierFk(RelationshipBase<?, ?, ?> relationship) {
return PesiTransformer.taxonRelation2RelTaxonQualifierFk(relationship);
}
- /**
- * Returns the <code>Notes</code> attribute.
- * @param relationship The {@link RelationshipBase Relationship}.
- * @return The <code>Notes</code> attribute.
- * @see MethodMapper
- */
- @SuppressWarnings("unused")
- private static String getNotes(RelationshipBase<?, ?, ?> relationship) {
- // TODO
- return null;
- }
+ //TODO still in use?
+ private static String getSynonymTypeCache(Synonym synonym, PesiExportState state) {
+ String result = null;
+ NomenclaturalCode code = null;
+ code = CdmBase.deproxy(synonym, Synonym.class).getAcceptedTaxon().getName().getNameType();
+
+ if (code != null) {
+ result = state.getConfig().getTransformer().getCacheBySynonymType(synonym, code);
+ } else {
+ logger.error("NomenclaturalCode is NULL while creating the following synonym: " + synonym.getUuid());
+ }
+ return result;
+ }
+
+// ********************************** MAPPINGS ********************************/
/**
* Returns the CDM to PESI specific export mappings.
mapping.addMapper(MethodMapper.NewInstance("DerivedFromGuid", this));
mapping.addMapper(MethodMapper.NewInstance("CacheCitation", this));
- mapping.addMapper(MethodMapper.NewInstance("AuthorString", this)); //For Taxon because Misallied Names are handled differently
+ mapping.addMapper(MethodMapper.NewInstance("AuthorString", this)); //For Taxon because misapplied names are handled differently
+ mapping.addMapper(MethodMapper.NewInstance("FullName", this)); //For Taxon because misapplied names are handled differently
mapping.addMapper(MethodMapper.NewInstance("WebShowName", this));
// DisplayName
mapping.addMapper(DbLastActionMapper.NewInstance("LastAction", true));
//experts
- ExtensionType extensionTypeSpeciesExpertName = (ExtensionType)getTermService().find(PesiTransformer.speciesExpertNameUuid);
- mapping.addMapper(DbExtensionMapper.NewInstance(extensionTypeSpeciesExpertName, "SpeciesExpertName"));
- ExtensionType extensionTypeExpertName = (ExtensionType)getTermService().find(PesiTransformer.expertNameUuid);
- mapping.addMapper(DbExtensionMapper.NewInstance(extensionTypeExpertName, "ExpertName"));
+// mapping.addMapper(DbExtensionMapper.NewInstance(extensionTypeSpeciesExpertName, "SpeciesExpertName"));
+ mapping.addMapper(MethodMapper.NewInstance("SpeciesExpertName", this, TaxonBase.class));
+// ExtensionType extensionTypeExpertName = (ExtensionType)getTermService().find(PesiTransformer.uuidExtExpertName);
+// mapping.addMapper(DbExtensionMapper.NewInstance(extensionTypeExpertName, "ExpertName"));
+ mapping.addMapper(MethodMapper.NewInstance("ExpertName", this, TaxonBase.class));
-// mapping.addMapper(MethodMapper.NewInstance("ParentTaxonFk", this, TaxonBase.class, PesiExportState.class)); //by AM, doesn't work, FK exception
+ //ParentTaxonFk handled in Phase02 now
mapping.addMapper(ObjectChangeMapper.NewInstance(TaxonBase.class, TaxonName.class, "Name"));
addNameMappers(mapping);
mapping.addMapper(IdMapper.NewInstance("TaxonId"));
- // mapping.addMapper(MethodMapper.NewInstance("TaxonStatusFk", this.getClass(), "getTaxonStatusFk", standardMethodParameter, PesiExportState.class));
-
mapping.addMapper(MethodMapper.NewInstance("KingdomFk", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("RankFk", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("RankCache", this, TaxonName.class, PesiExportState.class));
- mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusFk", Types.INTEGER , PesiTransformer.T_STATUS_UNACCEPTED));
- mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusCache", Types.VARCHAR , state.getTransformer().getTaxonStatusCacheByKey( PesiTransformer.T_STATUS_UNACCEPTED)));
+ mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusFk", Types.INTEGER, PesiTransformer.T_STATUS_UNACCEPTED));
+ mapping.addMapper(DbConstantMapper.NewInstance("TaxonStatusCache", Types.VARCHAR, state.getTransformer().getTaxonStatusCacheByKey( PesiTransformer.T_STATUS_UNACCEPTED)));
mapping.addMapper(DbStringMapper.NewInstance("AuthorshipCache", "AuthorString").setBlankToNull(true));
+ mapping.addMapper(MethodMapper.NewInstance("FullName", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("WebShowName", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("GUID", this, TaxonName.class));
-
-
// DisplayName
mapping.addMapper(MethodMapper.NewInstance("DisplayName", this, TaxonName.class));
mapping.addMapper(DbLastActionMapper.NewInstance("LastAction", true));
addNameMappers(mapping);
- //TODO add author mapper, TypeNameFk
-
return mapping;
}
private void addNameMappers(PesiExportMapping mapping) {
+
+ //epithets
mapping.addMapper(DbStringMapper.NewInstance("GenusOrUninomial", "GenusOrUninomial"));
mapping.addMapper(DbStringMapper.NewInstance("InfraGenericEpithet", "InfraGenericEpithet"));
mapping.addMapper(DbStringMapper.NewInstance("SpecificEpithet", "SpecificEpithet"));
mapping.addMapper(DbStringMapper.NewInstance("InfraSpecificEpithet", "InfraSpecificEpithet"));
+ //full name
// mapping.addMapper(DbStringMapper.NewInstance("NameCache", "WebSearchName")); //does not work as we need other cache strategy
mapping.addMapper(MethodMapper.NewInstance("WebSearchName", this, TaxonName.class));
-// mapping.addMapper(DbStringMapper.NewInstance("TitleCache", "FullName")); //does not work as we need other cache strategy
- mapping.addMapper(MethodMapper.NewInstance("FullName", this, TaxonName.class));
-
-
+ //nom ref
mapping.addMapper(MethodMapper.NewInstance("NomRefString", this, TaxonName.class));
+ //status
mapping.addMapper(MethodMapper.NewInstance("NameStatusFk", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("NameStatusCache", this, TaxonName.class, PesiExportState.class));
- mapping.addMapper(MethodMapper.NewInstance("TypeFullnameCache", this, TaxonName.class));
- //TODO TypeNameFk
-
- //quality status
mapping.addMapper(MethodMapper.NewInstance("QualityStatusFk", this, TaxonName.class));
mapping.addMapper(MethodMapper.NewInstance("QualityStatusCache", this, TaxonName.class, PesiExportState.class));
+ //types
+ mapping.addMapper(MethodMapper.NewInstance("TypeFullnameCache", this, TaxonName.class));
+ //TypeNameFk handled in Phase3
+
+ //supplemental
mapping.addMapper(MethodMapper.NewInstance("IdInSource", this, IdentifiableEntity.class));
mapping.addMapper(MethodMapper.NewInstance("OriginalDB", this, IdentifiableEntity.class) );
private PesiExportMapping getSynRelMapping() {
PesiExportMapping mapping = new PesiExportMapping(dbTableNameSynRel);
+ logger.warn("SynRelMapping currently not implemented. Needs to be checked");
- mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getTaxonFk1", RelationshipBase.class, PesiExportState.class));
- mapping.addMapper(MethodMapper.NewInstance("TaxonFk2", this.getClass(), "getTaxonFk2", RelationshipBase.class, PesiExportState.class));
- mapping.addMapper(MethodMapper.NewInstance("RelTaxonQualifierFk", this, RelationshipBase.class));
- mapping.addMapper(MethodMapper.NewInstance("RelQualifierCache", this, RelationshipBase.class, PesiExportState.class));
- mapping.addMapper(MethodMapper.NewInstance("Notes", this, RelationshipBase.class));
+ mapping.addMapper(MethodMapper.NewInstance("TaxonFk1", this.getClass(), "getSynonym", Synonym.class, PesiExportState.class));
+ mapping.addMapper(DbObjectMapper.NewInstance("acceptedTaxon", "TaxonFk2"));
+ mapping.addMapper(DbObjectMapper.NewInstance("type", "RelTaxonQualifierFk"));
+ mapping.addMapper(MethodMapper.NewInstance("RelQualifierCache", this.getClass(), "getSynonymTypeCache", Synonym.class, PesiExportState.class));
+ // TODO
+// mapping.addMapper(MethodMapper.NewInstance("Notes", this, RelationshipBase.class));
return mapping;
}
- private PesiExportMapping getAdditionalSourceMapping(PesiExportState state) throws UndefinedTransformerMethodException{
+ private PesiExportMapping getAdditionalSourceMapping(PesiExportState state) {
PesiExportMapping mapping = new PesiExportMapping(dbTableAdditionalSourceRel);
mapping.addMapper(IdMapper.NewInstance("TaxonFk"));
// mapping.addMapper(DbObjectMapper.NewInstance("NomenclaturalReference", "SourceNameCache", IS_CACHE));
mapping.addMapper(MethodMapper.NewInstance("SourceNameCache", this, TaxonName.class));
-
//we have only nomenclatural references here
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseFk", Types.INTEGER , PesiTransformer.NOMENCLATURAL_REFERENCE));
mapping.addMapper(DbConstantMapper.NewInstance("SourceUseCache", Types.VARCHAR, state.getTransformer().getSourceUseCacheByKey( PesiTransformer.NOMENCLATURAL_REFERENCE)));
return mapping;
}
+
+ @Override
+ protected boolean doCheck(PesiExportState state) {
+ return true;
+ }
+
+ @Override
+ protected boolean isIgnore(PesiExportState state) {
+ return ! state.getConfig().isDoTaxa();
+ }
}