1
|
/**
|
2
|
* Copyright (C) 2007 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
|
|
10
|
package eu.etaxonomy.cdm.app.pesi;
|
11
|
|
12
|
import java.util.UUID;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
17
|
import eu.etaxonomy.cdm.app.common.BerlinModelSources;
|
18
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
19
|
import eu.etaxonomy.cdm.app.common.TreeCreator;
|
20
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
21
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
22
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
23
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
24
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
27
|
import eu.etaxonomy.cdm.io.common.Source;
|
28
|
import eu.etaxonomy.cdm.io.pesi.out.PesiTransformer;
|
29
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
31
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
32
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
33
|
|
34
|
|
35
|
/**
|
36
|
* TODO add the following to a wiki page:
|
37
|
* HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
|
38
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
39
|
*
|
40
|
*
|
41
|
* @author a.mueller
|
42
|
*
|
43
|
*/
|
44
|
public class EuroMedActivator {
|
45
|
@SuppressWarnings("unused")
|
46
|
private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
|
47
|
|
48
|
//database validation status (create, update, validate ...)
|
49
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
50
|
// static final Source berlinModelSource = BerlinModelSources.euroMed();
|
51
|
static final Source berlinModelSource = BerlinModelSources.PESI3_euroMed();
|
52
|
|
53
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
|
54
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
55
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
56
|
|
57
|
static final int sourceSecId = 7000000; //500000
|
58
|
static final UUID classificationUuid = UUID.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
|
59
|
static final boolean useSingleClassification = true;
|
60
|
|
61
|
static final UUID featureTreeUuid = UUID.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
|
62
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
63
|
|
64
|
// set to zero for unlimited nameFacts
|
65
|
static final int maximumNumberOfNameFacts = 0;
|
66
|
|
67
|
static final int partitionSize = 5000;
|
68
|
|
69
|
//check - import
|
70
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
71
|
|
72
|
//editor - import
|
73
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
74
|
|
75
|
//NomeclaturalCode
|
76
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICBN;
|
77
|
|
78
|
//ignore null
|
79
|
static final boolean ignoreNull = true;
|
80
|
|
81
|
static final boolean switchSpeciesGroup = true;
|
82
|
|
83
|
static boolean useClassification = true;
|
84
|
|
85
|
static boolean isSplitTdwgCodes = false;
|
86
|
|
87
|
static String taxonTable = "v_cdm_exp_taxaAll";
|
88
|
static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM _EM_CDM_exp_taxaDirect t INNER JOIN Reference r ON t.PTRefFk = r.RefId ";
|
89
|
static String relPTaxonIdQuery = " SELECT r.RelPTaxonId " +
|
90
|
" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk ";
|
91
|
static String nameIdTable = " v_cdm_exp_namesAll ";
|
92
|
static String referenceIdTable = " v_cdm_exp_refAll ";
|
93
|
static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll )";
|
94
|
static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
95
|
static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
96
|
static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
|
97
|
static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
|
98
|
static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
|
99
|
static String authorFilter = null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
|
100
|
|
101
|
|
102
|
|
103
|
// **************** ALL *********************
|
104
|
|
105
|
static final boolean doUser = true;
|
106
|
//authors
|
107
|
static final boolean doAuthors = true;
|
108
|
//references
|
109
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
110
|
//names
|
111
|
static final boolean doTaxonNames = true;
|
112
|
static final boolean doRelNames = true;
|
113
|
static final boolean doNameStatus = true;
|
114
|
static final boolean doTypes = false; //serious types do not exist in E+M
|
115
|
static final boolean doNameFacts = true;
|
116
|
|
117
|
//taxa
|
118
|
static final boolean doTaxa = true;
|
119
|
static final boolean doRelTaxa = true;
|
120
|
static final boolean doFacts = true;
|
121
|
static final boolean doOccurences = true;
|
122
|
static final boolean doCommonNames = true;
|
123
|
|
124
|
//etc.
|
125
|
static final boolean doMarker = true;
|
126
|
|
127
|
|
128
|
// **************** SELECTED *********************
|
129
|
|
130
|
// static final boolean doUser = true;
|
131
|
// //authors
|
132
|
// static final boolean doAuthors = false;
|
133
|
// //references
|
134
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
135
|
// //names
|
136
|
// static final boolean doTaxonNames = false;
|
137
|
// static final boolean doRelNames = false;
|
138
|
// static final boolean doNameStatus = false;
|
139
|
// static final boolean doTypes = false;
|
140
|
// static final boolean doNameFacts = false;
|
141
|
//
|
142
|
// //taxa
|
143
|
// static final boolean doTaxa = false;
|
144
|
// static final boolean doRelTaxa = false;
|
145
|
// static final boolean doFacts = false;
|
146
|
// static final boolean doOccurences = false;
|
147
|
// static final boolean doCommonNames = false;
|
148
|
//
|
149
|
// //etc.
|
150
|
// static final boolean doMarker = false;
|
151
|
|
152
|
|
153
|
/**
|
154
|
* @param args
|
155
|
*/
|
156
|
public static void main(String[] args) {
|
157
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
158
|
|
159
|
//make BerlinModel Source
|
160
|
Source source = berlinModelSource;
|
161
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
162
|
|
163
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
164
|
|
165
|
config.setClassificationUuid(classificationUuid);
|
166
|
config.setSourceSecId(sourceSecId);
|
167
|
|
168
|
config.setNomenclaturalCode(nomenclaturalCode);
|
169
|
|
170
|
config.setIgnoreNull(ignoreNull);
|
171
|
config.setDoAuthors(doAuthors);
|
172
|
config.setDoReferences(doReferences);
|
173
|
config.setDoTaxonNames(doTaxonNames);
|
174
|
config.setDoRelNames(doRelNames);
|
175
|
config.setDoNameStatus(doNameStatus);
|
176
|
config.setDoTypes(doTypes);
|
177
|
config.setDoNameFacts(doNameFacts);
|
178
|
config.setUseClassification(useClassification);
|
179
|
config.setSourceRefUuid(PesiTransformer.uuidSourceRefEuroMed);
|
180
|
|
181
|
config.setDoTaxa(doTaxa);
|
182
|
config.setDoRelTaxa(doRelTaxa);
|
183
|
config.setDoFacts(doFacts);
|
184
|
config.setDoOccurrence(doOccurences);
|
185
|
config.setDoCommonNames(doCommonNames);
|
186
|
|
187
|
config.setDoMarker(doMarker);
|
188
|
config.setDoUser(doUser);
|
189
|
config.setEditor(editor);
|
190
|
config.setDbSchemaValidation(hbm2dll);
|
191
|
|
192
|
// maximum number of name facts to import
|
193
|
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
194
|
|
195
|
// filter
|
196
|
config.setTaxonTable(taxonTable);
|
197
|
config.setClassificationQuery(classificationQuery);
|
198
|
config.setRelTaxaIdQuery(relPTaxonIdQuery);
|
199
|
config.setNameIdTable(nameIdTable);
|
200
|
config.setReferenceIdTable(referenceIdTable);
|
201
|
config.setAuthorTeamFilter(authorTeamFilter);
|
202
|
config.setAuthorFilter(authorFilter);
|
203
|
config.setFactFilter(factFilter);
|
204
|
config.setCommonNameFilter(commonNameFilter);
|
205
|
config.setOccurrenceFilter(occurrenceFilter);
|
206
|
config.setOccurrenceSourceFilter(occurrenceSourceFilter);
|
207
|
config.setWebMarkerFilter(webMarkerFilter);
|
208
|
config.setUseSingleClassification(useSingleClassification);
|
209
|
|
210
|
//TDWG codes
|
211
|
config.setSplitTdwgCodes(isSplitTdwgCodes);
|
212
|
|
213
|
|
214
|
config.setCheck(check);
|
215
|
config.setEditor(editor);
|
216
|
config.setRecordsPerTransaction(partitionSize);
|
217
|
|
218
|
config.setSwitchSpeciesGroup(switchSpeciesGroup);
|
219
|
|
220
|
// invoke import
|
221
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
222
|
bmImport.invoke(config);
|
223
|
|
224
|
if (doFacts && config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ){
|
225
|
ICdmApplicationConfiguration app = bmImport.getCdmAppController();
|
226
|
|
227
|
//make feature tree
|
228
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
229
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
230
|
tree.getRoot().addChild(imageNode);
|
231
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
232
|
tree.getRoot().addChild(distributionNode, 2);
|
233
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
234
|
}
|
235
|
|
236
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
237
|
|
238
|
}
|
239
|
|
240
|
}
|