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 PesiExportActivatorERMS {
|
29
|
@SuppressWarnings("unused")
|
30
|
private static final Logger logger = Logger.getLogger(PesiExportActivatorERMS.class);
|
31
|
|
32
|
static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql_erms();
|
33
|
// static final ICdmDataSource cdmSource = CdmDestinations.cdm_test_local_mysql_erms2();
|
34
|
|
35
|
//database validation status (create, update, validate ...)
|
36
|
static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI();
|
37
|
// static final Source pesiDestination = PesiDestinations.pesi_test_local_CDM_ERMS2PESI_2();
|
38
|
|
39
|
// ****************** ALL *****************************************
|
40
|
|
41
|
// boolean deleteAll = true;
|
42
|
// DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
43
|
// boolean doTaxa = true;
|
44
|
// boolean doTreeIndex = true;
|
45
|
// boolean doInferredSynonyms = false; //xx takes long, unclear what it does
|
46
|
// boolean doRelTaxa = true;
|
47
|
// boolean doAdditionalTaxonSource = true;
|
48
|
// boolean doDescriptions = false;
|
49
|
// boolean doEcology = false;
|
50
|
|
51
|
// ************************ NONE **************************************** //
|
52
|
|
53
|
boolean deleteAll = false;
|
54
|
static DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
55
|
boolean doTaxa = false;
|
56
|
boolean doTreeIndex = doTaxa; //only with doTaxa
|
57
|
boolean doInferredSynonyms = false; //only with doTaxa
|
58
|
boolean doRelTaxa = false;
|
59
|
boolean doAdditionalTaxonSource = false;
|
60
|
boolean doDescriptions = false;
|
61
|
boolean doEcology = true;
|
62
|
|
63
|
static boolean doPureNames = false; //ERMS has no pure names
|
64
|
|
65
|
//check - export
|
66
|
static final CHECK check = CHECK.EXPORT_WITHOUT_CHECK;
|
67
|
|
68
|
//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
|
69
|
static final int nameIdStart = 10000000;
|
70
|
static final IdType idType = IdType.CDM_ID_WITH_EXCEPTIONS;
|
71
|
|
72
|
static final int partitionSize = 1000;
|
73
|
|
74
|
public boolean doExport(ICdmDataSource source, Source destination){
|
75
|
System.out.println("Start export from " + source.getDatabase() + " to PESI ("+ pesiDestination.getDatabase() + ") ...");
|
76
|
|
77
|
PesiTransformer transformer = new PesiTransformer(destination);
|
78
|
|
79
|
PesiExportConfigurator config = PesiExportConfigurator.NewInstance(destination, source, transformer);
|
80
|
|
81
|
config.setDoTreeIndex(doTreeIndex); //only with doTaxa
|
82
|
config.setDoInferredSynonyms(doInferredSynonyms); //only with doTaxa
|
83
|
|
84
|
config.setDoReferences(doReferences);
|
85
|
config.setDoTaxa(doTaxa);
|
86
|
config.setDoRelTaxa(doRelTaxa);
|
87
|
config.setDoAdditionalTaxonSource(doAdditionalTaxonSource);
|
88
|
config.setDoDescription(doDescriptions);
|
89
|
config.setDoEcology(doEcology);
|
90
|
|
91
|
// config.setDoOccurrence(doOccurrence);
|
92
|
// config.setDoOccurrenceSource(doOccurrenceSource);
|
93
|
// config.setDoNotes(doNotes);
|
94
|
// config.setDoNoteSources(doNoteSources);
|
95
|
// config.setDoImages(doImage);
|
96
|
|
97
|
config.setDoPureNames(doPureNames);
|
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
|
PesiExportActivatorERMS ex = new PesiExportActivatorERMS();
|
117
|
ICdmDataSource source = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmSource;
|
118
|
|
119
|
ex.doExport(source, pesiDestination);
|
120
|
System.exit(0);
|
121
|
}
|
122
|
}
|