commit 5ba511b13432a1bc4c9727c75211456295059d88
Author: Cherian Mathew <c.mathew@bgbm.org>
Date:   Thu Apr 18 13:47:37 2013 +0000

    Catalogue of Life (i4Life) Dwca import / export activators

diff --git a/.gitattributes b/.gitattributes
index f765c490..fa1b683f 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -39,6 +39,8 @@ app-import/src/main/java/eu/etaxonomy/cdm/app/excelImport/taxa/NormalExplicitAct
 app-import/src/main/java/eu/etaxonomy/cdm/app/excelImport/taxa/UseSummaryActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/exel/NormalExplicitTestActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/globis/GlobisActivator.java -text
+app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaExportActivator.java -text
+app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaImportActivator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/images/AbstractImageImporter.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/images/ImageImportConfigurator.java -text
 app-import/src/main/java/eu/etaxonomy/cdm/app/images/ImageImportState.java -text
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaExportActivator.java b/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaExportActivator.java
new file mode 100644
index 00000000..e9fc9146
--- /dev/null
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaExportActivator.java
@@ -0,0 +1,187 @@
+/**
+* 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.i4life.col;
+
+import java.io.File;
+import java.net.URI;
+import java.util.Arrays;
+import java.util.List;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+import org.joda.time.DateTime;
+
+import eu.etaxonomy.cdm.app.common.CdmDestinations;
+import eu.etaxonomy.cdm.common.monitor.DefaultProgressMonitor;
+import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
+import eu.etaxonomy.cdm.io.common.IExportConfigurator.CHECK;
+import eu.etaxonomy.cdm.io.dwca.out.DwcaEmlRecord;
+import eu.etaxonomy.cdm.io.dwca.out.DwcaTaxExportConfigurator;
+import eu.etaxonomy.cdm.model.agent.Institution;
+import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
+import eu.etaxonomy.cdm.model.agent.Person;
+
+
+/**
+ *
+ * @author a.mueller
+ *
+ */
+public class ColDwcaExportActivator {
+	@SuppressWarnings("unused")
+	private static final Logger logger = Logger.getLogger(ColDwcaExportActivator.class);
+
+	//database validation status (create, update, validate ...)
+	private static final String fileDestination = "C:\\tmp\\dwcaTmp\\cyprus\\";
+//	private static final ICdmDataSource cdmSource = CdmDestinations.cdm_local_cichorieae();
+//	private static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql();
+//	private static final ICdmDataSource cdmSource = CdmDestinations.cdm_production_cichorieae();
+//	private static final ICdmDataSource cdmSource = CdmDestinations.cdm_flora_central_africa_production();
+	private static final ICdmDataSource cdmSource = CdmDestinations.cdm_cyprus_production();
+
+	private IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
+	
+	private static DateTime dateTime = new DateTime();
+	private static String date = dateTime.getYear() + "-" + dateTime.getMonthOfYear() + "-" + dateTime.getDayOfMonth();
+	
+	private static final String defaultBibliographicCitation = "ICN (Hand, R., Kilian, N. & Raab-Straube, E. von; general editors) 2009+ (continuously updated): International Cichorieae Network: Cichorieae Portal. Published on the Internet at http://wp6-cichorieae.e-taxonomy.eu/portal/; " + 
+		"accessed ["+date+"].";
+
+	private static final String taxonSourceDefault = "http://wp6-cichorieae.e-taxonomy.eu/portal/?q=cdm_dataportal/taxon/{id}";
+	
+	//check - import
+	private static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
+
+	private static List<UUID> featureExclusions = Arrays.asList(new UUID[]{
+			UUID.fromString("5deff505-1a32-4817-9a74-50e6936fd630"),   //occurrences
+			UUID.fromString("8075074c-ace8-496b-ac82-47c14553f7fd"),    //Editor_Parenthesis
+			UUID.fromString("c0cc5ebe-1f0c-4c31-af53-d486858ea415"),   //Image Sources
+			UUID.fromString("9f6c551d-0f19-45ea-a855-4946f6fc1093"),		//Credits
+			UUID.fromString("cbf12c6c-94e6-4724-9c48-0f6f10d83e1c"),   //Editor Brackets
+			UUID.fromString("0508114d-4158-48b5-9100-369fa75120d3")     //inedited
+	});
+	
+	
+// ****************** ALL *****************************************
+	
+//	private boolean doTaxa = true;
+//	private boolean doResourceRelation = true;
+//	private boolean doTypesAndSpecimen = true;
+//	private boolean doVernacularNames = true;
+//	private boolean doReferences = true;
+//	private boolean doDescription = true;
+//	private boolean doDistributions = true;
+//	private boolean doImages = false;
+//	private boolean doMetaData = true;
+//	private boolean doEml = true;
+
+// ************************ NONE **************************************** //
+	
+	private boolean doTaxa = true;
+	private boolean doResourceRelation = false;
+	private boolean doTypesAndSpecimen = false;
+	private boolean doVernacularNames = false;
+	private boolean doReferences = false;
+	private boolean doDescription = false;
+	private boolean doDistributions = false;
+	private boolean doImages = false;
+	private boolean doMetaData = true;
+	private boolean doEml = false;
+	
+	public boolean 	doExport(ICdmDataSource source){
+		System.out.println("Start export to DWC-A ("+ fileDestination + ") ...");
+		
+//		CdmUpdater su = CdmUpdater.NewInstance();
+//		IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
+//		
+//		try {
+//			su.updateToCurrentVersion(source, monitor);
+//		} catch (Exception e) {
+//			e.printStackTrace();
+//		}
+//		if (true){
+//			return true;
+//		}
+		
+		//make file destination
+		String destination = fileDestination;
+		DwcaEmlRecord emlRecord = getEmlRecord();
+		
+		DwcaTaxExportConfigurator config = DwcaTaxExportConfigurator.NewInstance(source, new File(destination), emlRecord);
+		
+		config.setDoTaxa(doTaxa);
+		config.setDoResourceRelation(doResourceRelation);
+		config.setDoTypesAndSpecimen(doTypesAndSpecimen);
+		config.setDoVernacularNames(doVernacularNames);
+		config.setDoReferences(doReferences);
+		config.setDoDescription(doDescription);
+		config.setDoDistributions(doDistributions);
+		config.setDoImages(doImages);
+		config.setDoMetaData(doMetaData);
+		config.setDoEml(doEml);
+		config.setCheck(check);
+		config.setProgressMonitor(monitor);
+		config.setDefaultBibliographicCitation(defaultBibliographicCitation);
+		config.setDefaultTaxonSource(taxonSourceDefault);
+		monitor.beginTask("DwcA-Export", 10);
+		
+		config.setFeatureExclusions(featureExclusions);
+		// invoke import
+		CdmDefaultExport<DwcaTaxExportConfigurator> bmExport = new CdmDefaultExport<DwcaTaxExportConfigurator>();
+		boolean result = bmExport.invoke(config);
+		
+		System.out.println("End export to DWC-A ("+ fileDestination + ")..." + (result? "(successful)":"(with errors)"));
+		return result;
+	}
+
+
+	private DwcaEmlRecord getEmlRecord() {
+		DwcaEmlRecord emlRecord = new DwcaEmlRecord();
+		emlRecord.setIdentifier("My Identifier");
+		emlRecord.setTitle("Flora of cyprus");
+		emlRecord.setPublicationDate(new DateTime());
+		emlRecord.setExpectedCitation("Expected Citation");
+		emlRecord.setAbstractInfo("The abstract");
+		emlRecord.setAdditionalInformation("Add info");
+		emlRecord.setResourceLanguage(null);
+		emlRecord.setResourceUrl(URI.create("http://www.flora-of-cyprus.eu//portal/"));
+		emlRecord.setMetaDataLanguage(null);
+		emlRecord.setResourceLogoUri(null);
+		emlRecord.setCreativeCommonsLicensing(null);
+		emlRecord.setProjectTitle("Projekt tit");
+		emlRecord.setProjectLead("Proj Lead");
+		emlRecord.setProjectDescription("Proj Desc");
+		
+		Person person = Person.NewInstance();
+		Institution institution = Institution.NewInstance();
+		
+		InstitutionalMembership m = person.addInstitutionalMembership(institution, null, null, null);
+		emlRecord.setResourceCreator(m);
+		
+		return emlRecord;
+	}
+
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		ColDwcaExportActivator ex = new ColDwcaExportActivator();
+		ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
+
+		ex.doExport(source);
+	}
+	
+	
+	
+
+}
diff --git a/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaImportActivator.java b/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaImportActivator.java
new file mode 100644
index 00000000..978dca5d
--- /dev/null
+++ b/app-import/src/main/java/eu/etaxonomy/cdm/app/i4life/col/ColDwcaImportActivator.java
@@ -0,0 +1,152 @@
+/**
+* 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.i4life.col;
+
+import java.net.URI;
+import java.util.UUID;
+
+import org.apache.log4j.Logger;
+
+import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
+import eu.etaxonomy.cdm.app.common.CdmDestinations;
+import eu.etaxonomy.cdm.database.DbSchemaValidation;
+import eu.etaxonomy.cdm.database.ICdmDataSource;
+import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
+import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
+import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
+import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
+import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator.DatasetUse;
+import eu.etaxonomy.cdm.io.dwca.in.IImportMapping.MappingType;
+import eu.etaxonomy.cdm.model.agent.Person;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
+
+/**
+ * @author a.mueller
+ * @created 10.11.2011
+ */
+public class ColDwcaImportActivator {
+	private static final Logger logger = Logger.getLogger(ColDwcaImportActivator.class);
+	
+	//database validation status (create, update, validate ...)
+	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
+	static final URI source = dwca_col_All();
+
+	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_dwca();
+
+
+	static boolean isNoQuotes = true;
+	
+	//classification
+	static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
+	
+	//default nom code is ICZN as it allows adding publication year 
+	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
+
+	
+	//check - import
+	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
+	static int partitionSize = 1000;
+	
+	//config
+	static DatasetUse datasetUse = DatasetUse.ORIGINAL_SOURCE;
+	static boolean scientificNameIdAsOriginalSourceId = true;
+	static boolean guessNomRef = true;
+	private boolean handleAllRefsAsCitation = true;
+	
+	//validate
+	static boolean validateRankConsistency = false;
+	
+	
+	//taxa
+	static final boolean doTaxa = true;
+	static final boolean doDistribution = false;
+	//deduplicate
+	static final boolean doDeduplicate = false;
+	
+	
+	
+	static final MappingType mappingType = MappingType.InMemoryMapping;
+	
+	private void doImport(ICdmDataSource cdmDestination){
+		
+		//make Source
+		DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
+		config.addObserver(new LoggingIoObserver());
+		config.setClassificationUuid(classificationUuid);
+		config.setCheck(check);
+		config.setDbSchemaValidation(hbm2dll);
+		config.setMappingType(mappingType);
+		
+		config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
+		config.setValidateRankConsistency(validateRankConsistency);
+		config.setDefaultPartitionSize(partitionSize);
+		config.setNomenclaturalCode(defaultNomCode);
+		config.setDatasetUse(datasetUse);
+		config.setGuessNomenclaturalReferences(guessNomRef);
+		config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
+		config.setNoQuotes(isNoQuotes);
+		
+		CdmDefaultImport myImport = new CdmDefaultImport();
+
+		
+		//...
+		if (true){
+			System.out.println("Start import from ("+ source.toString() + ") ...");
+			config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
+			myImport.invoke(config);
+			System.out.println("End import from ("+ source.toString() + ")...");
+		}
+		
+		
+		
+		//deduplicate
+		if (doDeduplicate){
+			ICdmApplicationConfiguration app = myImport.getCdmAppController();
+			int count = app.getAgentService().deduplicate(Person.class, null, null);
+			logger.warn("Deduplicated " + count + " persons.");
+//			count = app.getAgentService().deduplicate(Team.class, null, null);
+//			logger.warn("Deduplicated " + count + " teams.");
+			count = app.getReferenceService().deduplicate(Reference.class, null, null);
+			logger.warn("Deduplicated " + count + " references.");
+		}
+		
+	}
+
+	private Reference<?> getSourceReference(String string) {
+		Reference<?> result = ReferenceFactory.newGeneric();
+		result.setTitleCache(string);
+		return result;
+	}
+
+	//Dwca
+	public static URI dwca_test_in() {
+//		URI sourceUrl = URI.create("http://dev.e-taxonomy.eu/trac/export/14463/trunk/cdmlib/cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/DwcaZipToStreamConverterTest-input.zip");
+		URI sourceUrl = URI.create("file:///C:/Users/pesiimport/Documents/pesi_cdmlib/cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/DwcaZipToStreamConverterTest-input.zip");
+		return sourceUrl;
+	}
+	
+	
+	//CoL
+	public static URI dwca_col_All() {
+		URI sourceUrl = URI.create("file:////Pesiimport3/col/col_20Nov2012.zip");
+		return sourceUrl;
+	}
+
+	/**
+	 * @param args
+	 */
+	public static void main(String[] args) {
+		ColDwcaImportActivator me = new ColDwcaImportActivator();
+		me.doImport(cdmDestination);
+	}
+	
+}
