commit 512f31a5082e314c9026e6763ee68c2f8ab9e1c4
Author: Andreas Müller <a.mueller@bgbm.org>
Date:   Mon Mar 26 10:52:19 2012 +0000

    updates to Vibrant activators

diff --git a/.gitattributes b/.gitattributes
index 28da83a8..c69f11ca 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -69,6 +69,7 @@ app-import/src/main/java/eu/etaxonomy/cdm/app/tcs/TcsSources.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/tcs/TcsXmlTestActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/util/TestDatabase.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/util/TestTransaction.java -text
+app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/EuroMedActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/IopiActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/MclActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/VibrantActivator.java -text
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/EuroMedActivator.java b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/EuroMedActivator.java
new file mode 100644
index 00000000..c91ff2bf
--- /dev/null
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/EuroMedActivator.java
@@ -0,0 +1,281 @@
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy 
+* http://www.e-taxonomy.eu
+* 
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.cdm.app.vibrant;
+
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.app.common.BerlinModelSources;
+import eu.etaxonomy.cdm.app.common.CdmDestinations;
+import eu.etaxonomy.cdm.app.common.TreeCreator;
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
+import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
+import eu.etaxonomy.cdm.io.common.Source;
+import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
+import eu.etaxonomy.cdm.model.common.ExtensionType;
+import eu.etaxonomy.cdm.model.description.Feature;
+import eu.etaxonomy.cdm.model.description.FeatureNode;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+
+
+/**
+ * TODO add the following to a wiki page:
+ * HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen 
+ * you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
+ * 
+ * 
+ * @author a.mueller
+ *
+ */
+public class EuroMedActivator {
+	private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
+
+	//database validation status (create, update, validate ...)
+	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
+//	static final Source berlinModelSource = BerlinModelSources.euroMed();
+	static final Source berlinModelSource = BerlinModelSources.PESI3_euroMed();
+	
+//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
+//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
+	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
+	
+	static final boolean includePesiExport = false;
+	
+	static final int sourceSecId = 7000000; //500000
+	static final UUID classificationUuid = UUID.fromString("5e05ebc5-6075-45ff-81df-4cefafafa4a3");
+	static final boolean useSingleClassification = true;
+	
+	static final UUID featureTreeUuid = UUID.fromString("eff345e7-0619-4ec3-955d-997c1fafffc3");
+	static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41}; 	
+	
+	// set to zero for unlimited nameFacts
+	static final int maximumNumberOfNameFacts = 0;
+	
+	static final int partitionSize = 2500;
+	
+	//check - import
+	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
+
+	//editor - import
+	static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
+	
+	//NomeclaturalCode
+	static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
+
+	//ignore null
+	static final boolean ignoreNull = true;
+	
+	static final boolean switchSpeciesGroup = true;
+	
+	static boolean useClassification = true;
+	
+	static boolean 	isSplitTdwgCodes = false;
+	
+	static String taxonTable = "v_cdm_exp_taxaAll";
+	static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId; 
+	static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " + 
+					" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk ";
+	static String nameIdTable = " v_cdm_exp_namesAll ";
+	static String referenceIdTable = " v_cdm_exp_refAll ";
+	static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll )";
+	static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
+	static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )"; 
+	static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
+	static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
+	static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
+	static String authorFilter = null;  // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) "; 
+	
+
+	
+// **************** ALL *********************	
+
+	static final boolean doUser = true;
+	//authors
+	static final boolean doAuthors = true;
+	//references
+	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
+	//names
+	static final boolean doTaxonNames = true;
+	static final boolean doRelNames = true;
+	static final boolean doNameStatus = true;
+	static final boolean doTypes = false;  //serious types do not exist in E+M
+	static final boolean doNameFacts = true;
+	
+	//taxa
+	static final boolean doTaxa = true;
+	static final boolean doRelTaxa = true;
+	static final boolean doFacts = true;
+	static final boolean doOccurences = true;
+	static final boolean doCommonNames = true;
+
+	//etc.
+	static final boolean doMarker = true;
+
+	
+// **************** SELECTED *********************
+
+//	static final boolean doUser = true;
+//	//authors
+//	static final boolean doAuthors = false;
+//	//references
+//	static final DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
+//	//names
+//	static final boolean doTaxonNames = false;
+//	static final boolean doRelNames = false;
+//	static final boolean doNameStatus = false;
+//	static final boolean doTypes = false;
+//	static final boolean doNameFacts = false;
+//	
+//	//taxa 
+//	static final boolean doTaxa = false;
+//	static final boolean doRelTaxa = false;
+//	static final boolean doFacts = false;
+//	static final boolean doOccurences = false;
+//	static final boolean doCommonNames = false;
+//	
+//	//etc.
+//	static final boolean doMarker = false;
+	
+	
+	public void importEm2CDM (Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
+		System.out.println("Start import from BerlinModel("+ source.getDatabase() + ") to " + destination.getDatabase() + " ...");
+		//make BerlinModel Source
+				
+		BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source,  destination);
+		
+		config.setClassificationUuid(classificationUuid);
+		config.setSourceSecId(sourceSecId);
+		
+		config.setNomenclaturalCode(nomenclaturalCode);
+
+		try {
+			Method makeUrlMethod = MclActivator.class.getDeclaredMethod("makeUrlForTaxon", TaxonBase.class, ResultSet.class);
+			config.setMakeUrlForTaxon(makeUrlMethod);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return;
+		}
+		
+		
+		config.setIgnoreNull(ignoreNull);
+		config.setDoAuthors(doAuthors);
+		config.setDoReferences(doReferences);
+		config.setDoTaxonNames(doTaxonNames);
+		config.setDoRelNames(doRelNames);
+		config.setDoNameStatus(doNameStatus);
+		config.setDoTypes(doTypes);
+		config.setDoNameFacts(doNameFacts);
+		config.setUseClassification(useClassification);
+		config.setSourceRefUuid(PesiTransformer.uuidSourceRefEuroMed);
+		
+		config.setDoTaxa(doTaxa);
+		config.setDoRelTaxa(doRelTaxa);
+		config.setDoFacts(doFacts);
+		config.setDoOccurrence(doOccurences);
+		config.setDoCommonNames(doCommonNames);
+		
+		config.setDoMarker(doMarker);
+		config.setDoUser(doUser);
+		config.setEditor(editor);
+		config.setDbSchemaValidation(hbm2dll);
+		
+		// maximum number of name facts to import
+		config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
+		
+//		filter
+		config.setTaxonTable(taxonTable);
+		config.setClassificationQuery(classificationQuery);
+		config.setRelTaxaIdQuery(relPTaxonIdQuery);
+		config.setNameIdTable(nameIdTable);
+		config.setReferenceIdTable(referenceIdTable);
+		config.setAuthorTeamFilter(authorTeamFilter);
+		config.setAuthorFilter(authorFilter);
+		config.setFactFilter(factFilter);
+		config.setCommonNameFilter(commonNameFilter);
+		config.setOccurrenceFilter(occurrenceFilter);
+		config.setOccurrenceSourceFilter(occurrenceSourceFilter);
+		config.setWebMarkerFilter(webMarkerFilter);
+		config.setUseSingleClassification(useSingleClassification);
+		
+		//TDWG codes
+		config.setSplitTdwgCodes(isSplitTdwgCodes);
+		
+		
+		config.setCheck(check);
+		config.setEditor(editor);
+		config.setRecordsPerTransaction(partitionSize);
+		
+		config.setSwitchSpeciesGroup(switchSpeciesGroup);
+		
+		// invoke import
+		CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
+		bmImport.invoke(config);
+		
+		if (doFacts && config.getCheck().equals(CHECK.CHECK_AND_IMPORT)  || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK)    ){
+			ICdmApplicationConfiguration app = bmImport.getCdmAppController();
+			
+			//make feature tree
+			FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
+			FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
+			tree.getRoot().addChild(imageNode);
+			FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
+			tree.getRoot().addChild(distributionNode, 2); 
+			app.getFeatureTreeService().saveOrUpdate(tree);
+		}
+		
+		System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
+		
+	}
+	
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		EuroMedActivator importActivator = new EuroMedActivator();
+		Source source = berlinModelSource;
+		ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
+		
+		importActivator.importEm2CDM(source, cdmRepository, hbm2dll);
+	}
+	
+	private static final String URLbase = "http://ww2.bgbm.org/EuroPlusMed/PTaxonDetail.asp?";
+	public static Method makeUrlForTaxon(TaxonBase<?> taxon, ResultSet rs){
+		Method result = null;
+		ExtensionType urlExtensionType = ExtensionType.URL();
+		int nameFk;
+		try {
+			nameFk = rs.getInt("PTNameFk");
+		int refFkInt = rs.getInt("PTRefFk");
+			if (nameFk != 0 && refFkInt != 0){
+				String url = String.format(URLbase + "NameId=%s&PTRefFk=%s",nameFk, refFkInt);
+				taxon.addExtension(url, urlExtensionType);
+			}else{
+				logger.warn("NameFk or refFkInt is 0. Can't create url");
+			}
+		} catch (SQLException e) {
+			logger.warn("Exception when trying to access result set for url creation.");
+		}
+		
+		return result;
+	}
+
+}
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/MclActivator.java b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/MclActivator.java
index 5e0edd20..5baa484d 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/MclActivator.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/MclActivator.java
@@ -9,6 +9,9 @@
 
 package eu.etaxonomy.cdm.app.vibrant;
 
+import java.lang.reflect.Method;
+import java.sql.ResultSet;
+import java.sql.SQLException;
 import java.util.UUID;
 
 import org.apache.log4j.Logger;
@@ -24,8 +27,9 @@ import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
 import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
 import eu.etaxonomy.cdm.io.common.Source;
-import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
+import eu.etaxonomy.cdm.model.common.ExtensionType;
 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 
 
 /**
@@ -38,14 +42,13 @@ import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
  *
  */
 public class MclActivator {
-	@SuppressWarnings("unused")
 	private static final Logger logger = Logger.getLogger(MclActivator.class);
 
 	//database validation status (create, update, validate ...)
 	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
 	static final Source berlinModelSource = BerlinModelSources.mcl();
 	
-	static final ICdmDataSource cdmDestination = cdm_test_local_mcl();
+	static final ICdmDataSource cdmDestination = VibrantActivator.cdm_test_local_vibrant();
 //	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
 	
 	static final boolean useSingleClassification = true;
@@ -128,6 +131,15 @@ public class MclActivator {
 				
 		BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source,  destination);
 		
+		try {
+			Method makeUrlMethod = MclActivator.class.getDeclaredMethod("makeUrlForTaxon", TaxonBase.class, ResultSet.class);
+			config.setMakeUrlForTaxon(makeUrlMethod);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return;
+		}
+
+		
 		config.setClassificationUuid(classificationUuid);
 		config.setSourceSecId(sourceSecId);
 		
@@ -193,5 +205,26 @@ public class MclActivator {
 		String cdmUserName = "root";
 		return CdmDestinations.makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
 	}
+	
+	private static final String URLbase = "http://ww2.bgbm.org/mcl/PTaxonDetail.asp?";
+	public static Method makeUrlForTaxon(TaxonBase<?> taxon, ResultSet rs){
+		Method result = null;
+		ExtensionType urlExtensionType = ExtensionType.URL();
+		int nameFk;
+		try {
+			nameFk = rs.getInt("PTNameFk");
+		int refFkInt = rs.getInt("PTRefFk");
+			if (nameFk != 0 && refFkInt != 0){
+				String url = String.format(URLbase + "NameId=%s&PTRefFk=%s",nameFk, refFkInt);
+				taxon.addExtension(url, urlExtensionType);
+			}else{
+				logger.warn("NameFk or refFkInt is 0. Can't create url");
+			}
+		} catch (SQLException e) {
+			logger.warn("Exception when trying to access result set for url creation.");
+		}
+		
+		return result;
+	}
 
 }
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/VibrantActivator.java b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/VibrantActivator.java
index c71862d0..93014267 100644
--- a/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/VibrantActivator.java
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/app/vibrant/VibrantActivator.java
@@ -9,24 +9,14 @@
 
 package eu.etaxonomy.cdm.app.vibrant;
 
-import java.util.UUID;
-
 import org.apache.log4j.Logger;
 
 import eu.etaxonomy.cdm.app.common.BerlinModelSources;
 import eu.etaxonomy.cdm.app.common.CdmDestinations;
-import eu.etaxonomy.cdm.app.pesi.EuroMedActivator;
 import eu.etaxonomy.cdm.database.DatabaseTypeEnum;
 import eu.etaxonomy.cdm.database.DbSchemaValidation;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
-import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
-import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
-import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
-import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
-import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
 import eu.etaxonomy.cdm.io.common.Source;
-import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
-import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
 
 
 /**
@@ -43,7 +33,7 @@ public class VibrantActivator {
 	private static final Logger logger = Logger.getLogger(VibrantActivator.class);
 
 	//database validation status (create, update, validate ...)
-	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
+	static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
 	static final Source iopiSource = BerlinModelSources.iopi();
 	static final Source mclSource = BerlinModelSources.mcl();
 	static final Source emSource = BerlinModelSources.euroMed_local();
@@ -51,9 +41,9 @@ public class VibrantActivator {
 //	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
 	static final ICdmDataSource cdmDestination = cdm_test_local_vibrant();
 
-	static final boolean doMcl = true;
-	static final boolean doEuroMed = false;
-	static final boolean doIopi = true;
+	static final boolean doMcl = false;
+	static final boolean doEuroMed = true;
+	static final boolean doIopi = false;
 	
 	
 	/**
