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.berlinModelImport;
|
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.CdmDestinations;
|
18
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
19
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
20
|
import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;
|
21
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
22
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
23
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
24
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
26
|
import eu.etaxonomy.cdm.io.common.Source;
|
27
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
28
|
import eu.etaxonomy.cdm.model.common.Language;
|
29
|
import eu.etaxonomy.cdm.model.common.Representation;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
32
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
33
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
|
36
|
|
37
|
/**
|
38
|
* TODO add the following to a wiki page:
|
39
|
* 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
|
40
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
41
|
*
|
42
|
*
|
43
|
* @author a.mueller
|
44
|
*
|
45
|
*/
|
46
|
public class EuroMedActivator {
|
47
|
@SuppressWarnings("unused")
|
48
|
private static final Logger logger = Logger.getLogger(EuroMedActivator.class);
|
49
|
|
50
|
//database validation status (create, update, validate ...)
|
51
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
52
|
// static final Source berlinModelSource = BerlinModelSources.euroMed();
|
53
|
static final Source berlinModelSource = BerlinModelSources.euroMed_PESI3();
|
54
|
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_pesi_euroMed();
|
56
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_euromed();
|
57
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
58
|
|
59
|
static final boolean includePesiExport = false;
|
60
|
|
61
|
static final int sourceSecId = 7000000; //500000
|
62
|
static final UUID classificationUuid = UUID.fromString("314a68f9-8449-495a-91c2-92fde8bcf344");
|
63
|
static final boolean useSingleClassification = true;
|
64
|
|
65
|
static final UUID featureTreeUuid = UUID.fromString("6a5e1c2b-ec0d-46c8-9c7d-a2059267ffb7");
|
66
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
67
|
|
68
|
// set to zero for unlimited nameFacts
|
69
|
static final int maximumNumberOfNameFacts = 0;
|
70
|
|
71
|
static final int partitionSize = 2500;
|
72
|
|
73
|
//check - import
|
74
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
75
|
|
76
|
//editor - import
|
77
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
78
|
|
79
|
//NomeclaturalCode
|
80
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
81
|
|
82
|
//ignore null
|
83
|
static final boolean ignoreNull = true;
|
84
|
|
85
|
static final boolean switchSpeciesGroup = true;
|
86
|
|
87
|
static boolean useClassification = true;
|
88
|
|
89
|
static boolean isSplitTdwgCodes = false;
|
90
|
static boolean useEmAreaVocabulary = true;
|
91
|
|
92
|
private boolean removeHttpMapsAnchor = true;
|
93
|
|
94
|
|
95
|
static final String infrGenericRankAbbrev = "[unranked]";
|
96
|
static final String infrSpecificRankAbbrev = "[unranked]";
|
97
|
|
98
|
|
99
|
static String taxonTable = "v_cdm_exp_taxaAll";
|
100
|
static String classificationQuery = " SELECT DISTINCT t.PTRefFk, r.RefCache FROM PTaxon t INNER JOIN Reference r ON t.PTRefFk = r.RefId WHERE t.PTRefFk = " + sourceSecId;
|
101
|
static String relPTaxonIdQuery = " SELECT TOP (100) PERCENT r.RelPTaxonId " +
|
102
|
" FROM RelPTaxon AS r INNER JOIN v_cdm_exp_taxaDirect AS a ON r.PTNameFk2 = a.PTNameFk AND r.PTRefFk2 = a.PTRefFk" +
|
103
|
" ORDER BY r.RelPTaxonId "; // AND r.RelQualifierFk =1
|
104
|
static String nameIdTable = " v_cdm_exp_namesAll ";
|
105
|
static String referenceIdTable = " v_cdm_exp_refAll ";
|
106
|
static String factFilter = " factId IN ( SELECT factId FROM v_cdm_exp_factsAll WHERE FactCategoryFk NOT IN (12, 14, 249, 251))";
|
107
|
static String occurrenceFilter = " occurrenceId IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
108
|
static String occurrenceSourceFilter = " occurrenceFk IN ( SELECT occurrenceId FROM v_cdm_exp_occurrenceAll )";
|
109
|
static String commonNameFilter = " commonNameId IN ( SELECT commonNameId FROM v_cdm_exp_commonNamesAll )";
|
110
|
static String webMarkerFilter = " TableNameFk <> 500 OR ( RIdentifierFk IN (SELECT RIdentifier FROM v_cdm_exp_taxaAll)) ";
|
111
|
static String authorTeamFilter = null; // " authorTeamId IN (SELECT authorTeamId FROM v_cdm_exp_authorTeamsAll) ";
|
112
|
static String authorFilter = null; // " authorId IN (SELECT authorId FROM v_cdm_exp_authorsAll) ";
|
113
|
|
114
|
|
115
|
|
116
|
// **************** ALL *********************
|
117
|
|
118
|
// static final boolean doUser = true;
|
119
|
// //authors
|
120
|
// static final boolean doAuthors = true;
|
121
|
// //references
|
122
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
123
|
// //names
|
124
|
// static final boolean doTaxonNames = true;
|
125
|
// static final boolean doRelNames = true;
|
126
|
// static final boolean doNameStatus = true;
|
127
|
// static final boolean doTypes = false; //serious types do not exist in E+M
|
128
|
// static final boolean doNameFacts = true;
|
129
|
//
|
130
|
// //taxa
|
131
|
// static final boolean doTaxa = true;
|
132
|
// static final boolean doRelTaxa = false;
|
133
|
// static final boolean doFacts = true;
|
134
|
// static final boolean doOccurences = true;
|
135
|
// static final boolean doCommonNames = true;
|
136
|
//
|
137
|
// //etc.
|
138
|
// static final boolean doMarker = true;
|
139
|
|
140
|
|
141
|
// **************** SELECTED *********************
|
142
|
|
143
|
static final boolean doUser = false;
|
144
|
//authors
|
145
|
static final boolean doAuthors = false;
|
146
|
//references
|
147
|
static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
148
|
//names
|
149
|
static final boolean doTaxonNames = false;
|
150
|
static final boolean doRelNames = false;
|
151
|
static final boolean doNameStatus = false;
|
152
|
static final boolean doTypes = false;
|
153
|
static final boolean doNameFacts = false;
|
154
|
|
155
|
//taxa
|
156
|
static final boolean doTaxa = false;
|
157
|
static final boolean doRelTaxa = true;
|
158
|
static final boolean doFacts = false;
|
159
|
static final boolean doOccurences = false;
|
160
|
static final boolean doCommonNames = false;
|
161
|
|
162
|
//etc.
|
163
|
static final boolean doMarker = false;
|
164
|
|
165
|
|
166
|
public void importEm2CDM (Source source, ICdmDataSource destination, DbSchemaValidation hbm2dll){
|
167
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
168
|
//make BerlinModel Source
|
169
|
|
170
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
171
|
|
172
|
config.setClassificationUuid(classificationUuid);
|
173
|
config.setSourceSecId(sourceSecId);
|
174
|
|
175
|
config.setNomenclaturalCode(nomenclaturalCode);
|
176
|
|
177
|
config.setIgnoreNull(ignoreNull);
|
178
|
config.setDoAuthors(doAuthors);
|
179
|
config.setDoReferences(doReferences);
|
180
|
config.setDoTaxonNames(doTaxonNames);
|
181
|
config.setDoRelNames(doRelNames);
|
182
|
config.setDoNameStatus(doNameStatus);
|
183
|
config.setDoTypes(doTypes);
|
184
|
config.setDoNameFacts(doNameFacts);
|
185
|
config.setUseClassification(useClassification);
|
186
|
config.setSourceRefUuid(BerlinModelTransformer.uuidSourceRefEuroMed);
|
187
|
|
188
|
config.setDoTaxa(doTaxa);
|
189
|
config.setDoRelTaxa(doRelTaxa);
|
190
|
config.setDoFacts(doFacts);
|
191
|
config.setDoOccurrence(doOccurences);
|
192
|
config.setDoCommonNames(doCommonNames);
|
193
|
|
194
|
config.setDoMarker(doMarker);
|
195
|
config.setDoUser(doUser);
|
196
|
config.setEditor(editor);
|
197
|
config.setDbSchemaValidation(hbm2dll);
|
198
|
|
199
|
// maximum number of name facts to import
|
200
|
config.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
201
|
|
202
|
config.setInfrGenericRankAbbrev(infrGenericRankAbbrev);
|
203
|
config.setInfrSpecificRankAbbrev(infrSpecificRankAbbrev);
|
204
|
config.setRemoveHttpMapsAnchor(removeHttpMapsAnchor);
|
205
|
|
206
|
// filter
|
207
|
config.setTaxonTable(taxonTable);
|
208
|
config.setClassificationQuery(classificationQuery);
|
209
|
config.setRelTaxaIdQuery(relPTaxonIdQuery);
|
210
|
config.setNameIdTable(nameIdTable);
|
211
|
config.setReferenceIdTable(referenceIdTable);
|
212
|
config.setAuthorTeamFilter(authorTeamFilter);
|
213
|
config.setAuthorFilter(authorFilter);
|
214
|
config.setFactFilter(factFilter);
|
215
|
config.setCommonNameFilter(commonNameFilter);
|
216
|
config.setOccurrenceFilter(occurrenceFilter);
|
217
|
config.setOccurrenceSourceFilter(occurrenceSourceFilter);
|
218
|
config.setWebMarkerFilter(webMarkerFilter);
|
219
|
config.setUseSingleClassification(useSingleClassification);
|
220
|
|
221
|
//TDWG codes
|
222
|
config.setSplitTdwgCodes(isSplitTdwgCodes);
|
223
|
config.setUseEmAreaVocabulary(useEmAreaVocabulary);
|
224
|
|
225
|
config.setCheck(check);
|
226
|
config.setEditor(editor);
|
227
|
config.setRecordsPerTransaction(partitionSize);
|
228
|
|
229
|
config.setSwitchSpeciesGroup(switchSpeciesGroup);
|
230
|
|
231
|
// invoke import
|
232
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
233
|
bmImport.invoke(config);
|
234
|
|
235
|
if (doTaxonNames && (config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
236
|
ICdmApplicationConfiguration app = bmImport.getCdmAppController();
|
237
|
Rank sectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid());
|
238
|
Representation repr = sectBot.getRepresentation(Language.ENGLISH());
|
239
|
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim());
|
240
|
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim());
|
241
|
sectBot.setTitleCache(null, false); //to definetely update the titleCache also
|
242
|
app.getTermService().saveOrUpdate(sectBot);
|
243
|
|
244
|
Rank subSectBot = (Rank)app.getTermService().find(Rank.SECTION_BOTANY().getUuid());
|
245
|
repr = subSectBot.getRepresentation(Language.ENGLISH());
|
246
|
repr.setAbbreviatedLabel(repr.getAbbreviatedLabel().replace("(bot.)", "").trim());
|
247
|
repr.setLabel(repr.getLabel().replace("(Botany)", "").trim());
|
248
|
subSectBot.setTitleCache(null, false); //to definetely update the titleCache also
|
249
|
app.getTermService().saveOrUpdate(subSectBot);
|
250
|
|
251
|
}
|
252
|
|
253
|
if (doFacts && (config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
254
|
ICdmApplicationConfiguration app = bmImport.getCdmAppController();
|
255
|
|
256
|
//make feature tree
|
257
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
258
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
259
|
tree.getRoot().addChild(imageNode);
|
260
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
261
|
tree.getRoot().addChild(distributionNode, 2);
|
262
|
FeatureNode commonNameNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
263
|
tree.getRoot().addChild(commonNameNode, 3);
|
264
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
265
|
|
266
|
//Change common name label
|
267
|
DefinedTermBase<?> commonNameFeature = app.getTermService().find(Feature.COMMON_NAME().getUuid());
|
268
|
commonNameFeature.setLabel("Common Names", Language.ENGLISH());
|
269
|
commonNameFeature.setTitleCache(null, false); //to definetely update the titleCache also
|
270
|
app.getTermService().saveOrUpdate(commonNameFeature);
|
271
|
}
|
272
|
|
273
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
274
|
|
275
|
}
|
276
|
|
277
|
/**
|
278
|
* @param args
|
279
|
*/
|
280
|
public static void main(String[] args) {
|
281
|
EuroMedActivator importActivator = new EuroMedActivator();
|
282
|
Source source = berlinModelSource;
|
283
|
ICdmDataSource cdmRepository = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
284
|
|
285
|
importActivator.importEm2CDM(source, cdmRepository, hbm2dll);
|
286
|
if (includePesiExport){
|
287
|
//not available from here since E+M was moved to app-import
|
288
|
// PesiExportActivatorEM exportActivator = new PesiExportActivatorEM();
|
289
|
// exportActivator.doExport(cdmRepository);
|
290
|
}
|
291
|
|
292
|
}
|
293
|
|
294
|
}
|