Project

General

Profile

Download (4.72 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2009 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.app.pesi;
10

    
11
import org.apache.log4j.Logger;
12

    
13
import eu.etaxonomy.cdm.app.common.CdmDestinations;
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
16
import eu.etaxonomy.cdm.io.common.DbExportConfiguratorBase.IdType;
17
import eu.etaxonomy.cdm.io.common.IExportConfigurator.CHECK;
18
import eu.etaxonomy.cdm.io.common.IExportConfigurator.DO_REFERENCES;
19
import eu.etaxonomy.cdm.io.common.Source;
20
import eu.etaxonomy.cdm.io.pesi.out.PesiExportConfigurator;
21
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
22

    
23
/**
24
 * @author a.mueller
25
 * @author e.-m.lee
26
 * @since 16.02.2010
27
 */
28
public class PesiExportActivatorEM {
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(PesiExportActivatorEM.class);
31

    
32
//	static final ICdmDataSource cdmSource = CdmDestinations.test_cdm_pesi_euroMed();
33
	static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql_euromed();
34

    
35
	//database validation status (create, update, validate ...)
36
	static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_EM2PESI();
37
//	static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_EM2PESI_2();
38

    
39
// ****************** ALL *****************************************
40

    
41
	boolean deleteAll = false;
42
	DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
43
	boolean doTaxa = true;
44
	boolean doTaxaPhase1 = true;   //better do not use, Phase1 is needed in Phase3
45
	boolean doPureNames = true;
46
	boolean doTreeIndex = true;
47
	boolean doParentAndBiota = true;
48
	boolean doInferredSynonyms = false;   //no inferred synonyms in E+M
49
	boolean doRelTaxa = true;
50
	boolean doAdditionalTaxonSource = true;
51
    boolean doDescriptions = true;
52
	boolean doEcologyAndLink = true;
53

    
54
// ************************ NONE **************************************** //
55

    
56
//    boolean deleteAll = false;
57
//    DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
58
//    boolean doTaxa = false;
59
//    boolean doPureNames = false;
60
//    boolean doTreeIndex = false;
61
//    boolean doParentAndBiota = false;
62
//    boolean doInferredSynonyms = false;   //no inferred synonyms in E+M
63
//    boolean doRelTaxa = false;
64
//    boolean doAdditionalTaxonSource = false;
65
//    boolean doDescriptions = false;
66
//    boolean doEcologyAndLink = false;
67

    
68

    
69
    //check - export
70
    static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
71

    
72
    //Taxon names can't be mapped to their CDM ids as PESI Taxon table mainly holds taxa and there IDs. We ad nameIdStart to the TaxonName id to get a unique id
73
    static final int nameIdStart = 10000000;
74
    static final IdType idType = IdType.CDM_ID_WITH_EXCEPTIONS;
75

    
76
    static final int partitionSize = 1000;
77

    
78
	public boolean 	doExport(ICdmDataSource source){
79
	    System.out.println("Start export from " + source.getDatabase() + " to PESI ("+ pesiDestination.getDatabase() + ") ...");
80

    
81
		//make PESI Source
82
		Source destination = pesiDestination;
83
		PesiTransformer transformer = new PesiTransformer(destination);
84

    
85
		PesiExportConfigurator config = PesiExportConfigurator.NewInstance(destination, source, transformer);
86

    
87
		config.setDoTaxa(doTaxa);
88
		config.setDoPureNames(doPureNames);
89
		config.setDoTaxaPhase1(doTaxaPhase1);
90
		config.setDoRelTaxa(doRelTaxa);
91
		config.setDoReferences(doReferences);
92
		config.setDoTreeIndex(doTreeIndex);
93
		config.setDoParentAndBiota(doParentAndBiota);
94
		config.setDoInferredSynonyms(doInferredSynonyms);
95
		config.setDoDescription(doDescriptions);
96
		config.setDoAdditionalTaxonSource(doAdditionalTaxonSource);
97
		config.setDoEcologyAndLink(doEcologyAndLink);
98

    
99
		config.setCheck(check);
100
		config.setLimitSave(partitionSize);
101
		config.setIdType(idType);
102
		config.setNameIdStart(nameIdStart);
103
		if (deleteAll){
104
			destination.update("EXEC sp_deleteAllData");
105
		}
106

    
107
		// invoke export
108
		CdmDefaultExport<PesiExportConfigurator> pesiExport = new CdmDefaultExport<>();
109
		boolean result = pesiExport.invoke(config).isSuccess();
110

    
111
		System.out.println("End export to PESI ("+ destination.getDatabase() + ")..." + (result? "(successful)":"(with errors)"));
112
		return result;
113
	}
114

    
115
	public static void main(String[] args) {
116
		PesiExportActivatorEM ex = new PesiExportActivatorEM();
117
		ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
118
//		Connection con = pesiDestination.getConnection();
119
//		System.out.println(con);
120
		ex.doExport(source);
121
		System.exit(0);
122
	}
123

    
124
}
(8-8/12)