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.lang.reflect.Method;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;
|
18
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
19
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
20
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
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;
|
24
|
import eu.etaxonomy.cdm.io.common.Source;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
27
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
28
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
29
|
|
30
|
|
31
|
/**
|
32
|
* TODO add the following to a wiki page:
|
33
|
* 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
|
34
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
35
|
*
|
36
|
*
|
37
|
* @author a.mueller
|
38
|
*
|
39
|
*/
|
40
|
public class SalvadorActivator {
|
41
|
private static final Logger logger = Logger.getLogger(SalvadorActivator.class);
|
42
|
|
43
|
//database validation status (create, update, validate ...)
|
44
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
45
|
static final Source berlinModelSource = BerlinModelSources.El_Salvador();
|
46
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2Salvador();
|
47
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
48
|
static final UUID treeUuid = UUID.fromString("b010c84d-6049-45f4-9f13-c065101eaa26");
|
49
|
static final UUID secUuid = UUID.fromString("d03ef02a-f226-4cb1-bdb4-f6c154f08a34");
|
50
|
static final int sourceSecId = 7331;
|
51
|
|
52
|
static final UUID featureTreeUuid = UUID.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568");
|
53
|
static final Object[] featureKeyList = new Integer[]{302, 303, 306, 307, 309, 310, 311, 312, 350, 1500, 1800, 1900, 1950, 1980, 2000, 10299};
|
54
|
static boolean isIgnore0AuthorTeam = true; //special case for Salvador.
|
55
|
static boolean doExport = false;
|
56
|
static boolean useClassification = true;
|
57
|
|
58
|
//check - import
|
59
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
60
|
static final IImportConfigurator.EDITOR editor = IImportConfigurator.EDITOR.EDITOR_AS_EDITOR;
|
61
|
|
62
|
//NomenclaturalCode
|
63
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
64
|
|
65
|
//ignore null
|
66
|
static final boolean ignoreNull = true;
|
67
|
|
68
|
// ****************** ALL *****************************************
|
69
|
|
70
|
//authors
|
71
|
static final boolean doAuthors = true;
|
72
|
//references
|
73
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
74
|
//names
|
75
|
static final boolean doTaxonNames = true;
|
76
|
static final boolean doRelNames = true;
|
77
|
static final boolean doNameStatus = true;
|
78
|
static final boolean doTypes = false; //Types do not exist in El_Salvador DB
|
79
|
static final boolean doNameFacts = false; //Name Facts do not exist in El_Salvador DB
|
80
|
|
81
|
//taxa
|
82
|
static final boolean doTaxa = true;
|
83
|
static final boolean doRelTaxa = true;
|
84
|
static final boolean doFacts = true;
|
85
|
static final boolean doOccurences = false; //Occurrences do not exist in El_Salvador DB
|
86
|
static final boolean doCommonNames = false; //CommonNames do not exist in Salvador DB
|
87
|
|
88
|
//etc.
|
89
|
static final boolean doMarker = true;
|
90
|
static final boolean doUser = true;
|
91
|
|
92
|
|
93
|
// ************************ NONE **************************************** //
|
94
|
|
95
|
// //authors
|
96
|
// static final boolean doAuthors = false;
|
97
|
// //references
|
98
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.CONCEPT_REFERENCES;
|
99
|
// //names
|
100
|
// static final boolean doTaxonNames = false;
|
101
|
// static final boolean doRelNames = false;
|
102
|
// static final boolean doNameStatus = false;
|
103
|
// static final boolean doTypes = false;
|
104
|
// static final boolean doNameFacts = false;
|
105
|
//
|
106
|
// //taxa
|
107
|
// static final boolean doTaxa = true;
|
108
|
// static final boolean doRelTaxa = true;
|
109
|
// static final boolean doFacts = false;
|
110
|
// static final boolean doOccurences = false;
|
111
|
//
|
112
|
// //etc.
|
113
|
// static final boolean doMarker = false;
|
114
|
// static final boolean doUser = false;
|
115
|
|
116
|
|
117
|
public boolean doImport(ICdmDataSource destination){
|
118
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") ...");
|
119
|
|
120
|
//make BerlinModel Source
|
121
|
Source source = berlinModelSource;
|
122
|
|
123
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
124
|
|
125
|
config.setClassificationUuid(treeUuid);
|
126
|
config.setSecUuid(secUuid);
|
127
|
config.setSourceSecId(sourceSecId);
|
128
|
config.setNomenclaturalCode(nomenclaturalCode);
|
129
|
config.setIgnoreNull(ignoreNull);
|
130
|
|
131
|
config.setDoAuthors(doAuthors);
|
132
|
config.setDoReferences(doReferences);
|
133
|
config.setDoTaxonNames(doTaxonNames);
|
134
|
config.setDoRelNames(doRelNames);
|
135
|
config.setDoNameStatus(doNameStatus);
|
136
|
config.setDoTypes(doTypes);
|
137
|
config.setDoNameFacts(doNameFacts);
|
138
|
|
139
|
config.setDoTaxa(doTaxa);
|
140
|
config.setDoRelTaxa(doRelTaxa);
|
141
|
config.setDoFacts(doFacts);
|
142
|
config.setDoOccurrence(doOccurences);
|
143
|
config.setDoCommonNames(doCommonNames);
|
144
|
|
145
|
config.setDoMarker(doMarker);
|
146
|
config.setDoUser(doUser);
|
147
|
|
148
|
config.setDbSchemaValidation(hbm2dll);
|
149
|
|
150
|
config.setCheck(check);
|
151
|
config.setEditor(editor);
|
152
|
config.setIgnore0AuthorTeam(isIgnore0AuthorTeam);
|
153
|
config.setUseClassification(useClassification);
|
154
|
|
155
|
config.setNamerelationshipTypeMethod(getHandleNameRelationshipTypeMethod());
|
156
|
config.setUserTransformationMethod(getTransformUsernameMethod());
|
157
|
|
158
|
// invoke import
|
159
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
160
|
boolean result = bmImport.invoke(config);
|
161
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
162
|
return result;
|
163
|
}
|
164
|
|
165
|
|
166
|
/**
|
167
|
* @param args
|
168
|
*/
|
169
|
public static void main(String[] args) {
|
170
|
SalvadorActivator activator = new SalvadorActivator();
|
171
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
172
|
|
173
|
activator.doImport(destination);
|
174
|
if (doExport == true){
|
175
|
SalvadorExport export = new SalvadorExport();
|
176
|
export.doExport(destination);
|
177
|
}
|
178
|
}
|
179
|
|
180
|
|
181
|
private Method getHandleNameRelationshipTypeMethod(){
|
182
|
String methodName = "handleNameRelationshipType";
|
183
|
try {
|
184
|
Method method = this.getClass().getDeclaredMethod(methodName, Integer.class, NonViralName.class, NonViralName.class);
|
185
|
method.setAccessible(true);
|
186
|
return method;
|
187
|
} catch (Exception e) {
|
188
|
logger.error("Problem creating Method: " + methodName);
|
189
|
return null;
|
190
|
}
|
191
|
}
|
192
|
|
193
|
|
194
|
//used by BerlinModelImportConfigurator
|
195
|
@SuppressWarnings("unused")
|
196
|
private static boolean handleNameRelationshipType(Integer relQualifierFk, NonViralName nameTo, NonViralName nameFrom){
|
197
|
if (relQualifierFk == 72){
|
198
|
nameTo.getHomotypicalGroup().merge(nameFrom.getHomotypicalGroup());
|
199
|
return true;
|
200
|
}
|
201
|
return false;
|
202
|
}
|
203
|
|
204
|
private Method getTransformUsernameMethod(){
|
205
|
String methodName = "transformUsername";
|
206
|
try {
|
207
|
Method method = this.getClass().getDeclaredMethod(methodName, String.class);
|
208
|
method.setAccessible(true);
|
209
|
return method;
|
210
|
} catch (Exception e) {
|
211
|
logger.error("Problem creating Method: " + methodName);
|
212
|
return null;
|
213
|
}
|
214
|
}
|
215
|
|
216
|
//used by BerlinModelImportConfigurator
|
217
|
@SuppressWarnings("unused")
|
218
|
private static String transformUsername(String nameToBeTransformed){
|
219
|
if (nameToBeTransformed == null){
|
220
|
return null;
|
221
|
}else if ("W.G.Berendsohn".equals(nameToBeTransformed)){
|
222
|
return "wgb";
|
223
|
}else if(nameToBeTransformed.startsWith("fs") || nameToBeTransformed.equals("BGBM\\fs")){
|
224
|
return "Frank Specht";
|
225
|
}
|
226
|
return nameToBeTransformed;
|
227
|
}
|
228
|
|
229
|
}
|