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
|
*/
|
29
|
public class PesiExportActivatorFE {
|
30
|
@SuppressWarnings("unused")
|
31
|
private static final Logger logger = Logger.getLogger(PesiExportActivatorFE.class);
|
32
|
|
33
|
//database validation status (create, update, validate ...)
|
34
|
static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_FE2PESI();
|
35
|
// static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI();
|
36
|
|
37
|
static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_faunaEu_mysql();
|
38
|
// static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql();
|
39
|
|
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
|
|
43
|
static final int partitionSize = 2000;
|
44
|
|
45
|
//check - export
|
46
|
static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
|
47
|
|
48
|
static final boolean deleteAll = true;
|
49
|
|
50
|
static final IdType idType = IdType.CDM_ID_WITH_EXCEPTIONS;
|
51
|
|
52
|
// ****************** ALL *****************************************
|
53
|
|
54
|
//references
|
55
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
56
|
|
57
|
//taxa
|
58
|
static final boolean doTaxa = true;
|
59
|
static final boolean doRelTaxa = true;
|
60
|
static final boolean doNotes = true;
|
61
|
static final boolean doNoteSources = true;
|
62
|
static final boolean doAdditionalTaxonSource = true;
|
63
|
static final boolean doOccurrence = true;
|
64
|
static final boolean doOccurrenceSource = true;
|
65
|
static final boolean doImage = true;
|
66
|
static final boolean doTreeIndex = true;
|
67
|
static final boolean doRank = true;
|
68
|
static final boolean doInferredSynonyms = true;
|
69
|
static final boolean doPureNames = false; // !!!
|
70
|
static final boolean doDescription = true;
|
71
|
|
72
|
|
73
|
// ************************ NONE **************************************** //
|
74
|
|
75
|
// //references
|
76
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
77
|
//
|
78
|
// //taxa
|
79
|
// static final boolean doTaxa = false;
|
80
|
// static final boolean doRelTaxa = false;
|
81
|
// static final boolean doNotes = false;
|
82
|
// static final boolean doNoteSources = false;
|
83
|
// static final boolean doAdditionalTaxonSource = false;
|
84
|
// static final boolean doOccurrence = false;
|
85
|
// static final boolean doOccurrenceSource = false;
|
86
|
// static final boolean doImage = false;
|
87
|
// static final boolean doTreeIndex = true;
|
88
|
// static final boolean doRank = true;
|
89
|
// static final boolean doInferredSynonyms = true;
|
90
|
// static final boolean doDescription = false;
|
91
|
|
92
|
|
93
|
public boolean doExport(ICdmDataSource source){
|
94
|
System.out.println("Start export to PESI ("+ pesiDestination.getDatabase() + ") ...");
|
95
|
|
96
|
//make PESI Source
|
97
|
Source destination = pesiDestination;
|
98
|
PesiTransformer transformer = new PesiTransformer(destination);
|
99
|
|
100
|
PesiExportConfigurator config = PesiExportConfigurator.NewInstance(destination, source, transformer);
|
101
|
|
102
|
config.setDoTaxa(doTaxa);
|
103
|
config.setDoRelTaxa(doRelTaxa);
|
104
|
config.setDoOccurrence(doOccurrence);
|
105
|
config.setDoReferences(doReferences);
|
106
|
config.setDoImages(doImage);
|
107
|
config.setDoNotes(doNotes);
|
108
|
config.setDoNoteSources(doNoteSources);
|
109
|
config.setDoOccurrenceSource(doOccurrenceSource);
|
110
|
config.setDoTreeIndex(doTreeIndex);
|
111
|
config.setDoInferredSynonyms(doInferredSynonyms);
|
112
|
config.setDoPureNames(doPureNames);
|
113
|
config.setDoDescription(doDescription);
|
114
|
|
115
|
config.setCheck(check);
|
116
|
config.setLimitSave(partitionSize);
|
117
|
config.setIdType(idType);
|
118
|
config.setNameIdStart(nameIdStart);
|
119
|
if (deleteAll){
|
120
|
destination.update("EXEC sp_deleteAllData");
|
121
|
}
|
122
|
|
123
|
|
124
|
// invoke export
|
125
|
CdmDefaultExport<PesiExportConfigurator> pesiExport = new CdmDefaultExport<PesiExportConfigurator>();
|
126
|
|
127
|
boolean result = pesiExport.invoke(config).isSuccess();
|
128
|
|
129
|
System.out.println("End export to PESI ("+ destination.getDatabase() + ")..." + (result? "(successful)":"(with errors)"));
|
130
|
return result;
|
131
|
}
|
132
|
|
133
|
/**
|
134
|
* @param args
|
135
|
*/
|
136
|
public static void main(String[] args) {
|
137
|
PesiExportActivatorFE ex = new PesiExportActivatorFE();
|
138
|
ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
|
139
|
|
140
|
ex.doExport(source);
|
141
|
}
|
142
|
|
143
|
}
|