Project

General

Profile

Download (5.39 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
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
23

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

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

    
39
	static final ICdmDataSource cdmSource = CdmDestinations.cdm_pesi_erms();
40
	//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
41
	static final int nameIdStart = 10000000;
42
	static final IdType idType = IdType.CDM_ID_WITH_EXCEPTIONS;
43

    
44
	static final int partitionSize = 1000;
45

    
46
	//check - export
47
	static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
48

    
49
	//NomenclaturalCode
50
	static final NomenclaturalCode nomenclaturalCode  = NomenclaturalCode.ICNAFP;
51

    
52
	static final boolean deleteAll = true;
53

    
54

    
55
// ****************** ALL *****************************************
56

    
57
	//references
58
	static final DO_REFERENCES doReferences =  DO_REFERENCES.ALL;
59

    
60
	//taxa
61
	static final boolean doTaxa = true;
62
	static final boolean doPureNames = true;
63
	static final boolean doTreeIndex = true;
64
	static final boolean doParentAndBiota = true;
65
	static final boolean doRank = true;
66
	static final boolean doInferredSynonyms = false;   //no inferred synonyms in E+M
67
	static final boolean doRelTaxa = true;
68
	static final boolean doDescriptions = true;
69

    
70
	static final boolean doNotes = true;
71
	static final boolean doNoteSources = true;
72
	static final boolean doAdditionalTaxonSource = true;
73
	static final boolean doOccurrence = true;
74
	static final boolean doOccurrenceSource = true;
75
	static final boolean doImage = true;
76

    
77

    
78
// ************************ NONE **************************************** //
79

    
80
//	//references
81
//	static final DO_REFERENCES doReferences =  DO_REFERENCES.NONE;
82
//
83
//	//taxa
84
//	static final boolean doTaxa = false;
85
//	static final boolean doPureNames = false;
86
//	static final boolean doRelTaxa = false;
87
//	static final boolean doNotes = false;
88
//	static final boolean doNoteSources = false;
89
//	static final boolean doAdditionalTaxonSource = false;
90
//	static final boolean doOccurrence = false;
91
//	static final boolean doOccurrenceSource = false;
92
//	static final boolean doImage = false;
93
//	static final boolean doTreeIndex = false;
94
//	static final boolean doRank = true;
95
//	static final boolean doInferredSynonyms = true;
96

    
97

    
98
	public boolean 	doExport(ICdmDataSource source){
99
		System.out.println("Start export to PESI ("+ pesiDestination.getDatabase() + ") ...");
100

    
101
		//make PESI Source
102
		Source destination = pesiDestination;
103
		PesiTransformer transformer = new PesiTransformer(destination);
104

    
105
		PesiExportConfigurator config = PesiExportConfigurator.NewInstance(destination, source, transformer);
106

    
107
		config.setDoTaxa(doTaxa);
108
		config.setDoPureNames(doPureNames);
109
		config.setDoRelTaxa(doRelTaxa);
110
		config.setDoOccurrence(doOccurrence);
111
		config.setDoReferences(doReferences);
112
		config.setDoImages(doImage);
113
		config.setDoNotes(doNotes);
114
		config.setDoNoteSources(doNoteSources);
115
		config.setDoOccurrenceSource(doOccurrenceSource);
116
		config.setDoTreeIndex(doTreeIndex);
117
		config.setDoTreeIndex(doParentAndBiota);
118
		config.setDoRank(doRank);
119
		config.setDoInferredSynonyms(doInferredSynonyms);
120
		config.setDoDescription(doDescriptions);
121

    
122
		config.setCheck(check);
123
		config.setLimitSave(partitionSize);
124
		config.setIdType(idType);
125
		config.setNameIdStart(nameIdStart);
126
		if (deleteAll){
127
			destination.update("EXEC sp_deleteAllData");
128
		}
129

    
130
		// invoke export
131
		CdmDefaultExport<PesiExportConfigurator> pesiExport = new CdmDefaultExport<PesiExportConfigurator>();
132
		boolean result = pesiExport.invoke(config).isSuccess();
133

    
134
		System.out.println("End export to PESI ("+ destination.getDatabase() + ")..." + (result? "(successful)":"(with errors)"));
135
		return result;
136
	}
137

    
138
	/**
139
	 * @param args
140
	 */
141
	public static void main(String[] args) {
142
		PesiExportActivatorEM ex = new PesiExportActivatorEM();
143
		ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
144
//		Connection con = pesiDestination.getConnection();
145
//		System.out.println(con);
146
		ex.doExport(source);
147
	}
148

    
149
}
(6-6/10)