Project

General

Profile

Download (4.83 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.app.common.PesiDestinations;
15
import eu.etaxonomy.cdm.database.ICdmDataSource;
16
import eu.etaxonomy.cdm.io.common.CdmDefaultExport;
17
import eu.etaxonomy.cdm.io.common.DbExportConfiguratorBase.IdType;
18
import eu.etaxonomy.cdm.io.common.IExportConfigurator.CHECK;
19
import eu.etaxonomy.cdm.io.common.IExportConfigurator.DO_REFERENCES;
20
import eu.etaxonomy.cdm.io.common.Source;
21
import eu.etaxonomy.cdm.io.pesi.out.PesiExportConfigurator;
22
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
23

    
24
/**
25
 * @author a.mueller
26
 * @author e.-m.lee
27
 * @since 16.02.2010
28
 */
29
public class PesiExportActivatorEM {
30

    
31
	@SuppressWarnings("unused")
32
	private static final Logger logger = Logger.getLogger(PesiExportActivatorEM.class);
33

    
34
//	static final ICdmDataSource cdmSource = CdmDestinations.test_cdm_pesi_euroMed();
35
//	static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql_euromed();
36
	static final ICdmDataSource cdmSource = CdmDestinations.cdm_pesi2019_final();
37

    
38
	//database validation status (create, update, validate ...)
39
	static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_EM2PESI();
40
//	static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_EM2PESI_2();
41

    
42
// ****************** ALL *****************************************
43

    
44
	boolean deleteAll = true;
45
	DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
46
	boolean doTaxa = true;
47
	boolean doRelTaxa = true;
48
	boolean doDescriptions = true;
49

    
50
	boolean doPureNames = doTaxa;
51
	boolean doTreeIndex = doTaxa;
52
	boolean doParentAndBiota = doTaxa;
53
    boolean doAdditionalTaxonSource = false;  //do not exist in E+M
54
    boolean doInferredSynonyms = false;   //no inferred synonyms in E+M
55
	boolean doEcologyAndLink = false;   //do not exist in E+M
56

    
57
// ************************ NONE **************************************** //
58

    
59
//	boolean deleteAll = false;
60
//	DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
61
//	boolean doTaxa = false;
62
//	boolean doRelTaxa = false;
63
//	boolean doDescriptions = true;
64
//
65
//    boolean doPureNames = doTaxa;
66
//    boolean doTreeIndex = doTaxa;
67
//    boolean doParentAndBiota = doTaxa;
68
//    boolean doAdditionalTaxonSource = false;  //do not exist in E+M
69
//    boolean doInferredSynonyms = false;   //no inferred synonyms in E+M
70
//    boolean doEcologyAndLink = false;   //do not exist in E+M
71

    
72
    //check - export
73
    static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
74

    
75
    //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
76
    static final int nameIdStart = 10000000;
77
    static final IdType idType = IdType.CDM_ID_WITH_EXCEPTIONS;
78

    
79
    static final int partitionSize = 1000;
80

    
81
	public boolean 	doExport(ICdmDataSource source){
82
	    System.out.println("Start export from " + source.getDatabase() + " to PESI ("+ pesiDestination.getDatabase() + ") ...");
83

    
84
		//make PESI Source
85
		Source destination = pesiDestination;
86
		PesiTransformer transformer = new PesiTransformer(destination);
87

    
88
		PesiExportConfigurator config = PesiExportConfigurator.NewInstance(destination, source, transformer);
89

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

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

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

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

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

    
126
}
(6-6/9)