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
|
import org.springframework.transaction.TransactionStatus;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
19
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
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;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
27
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
28
|
import eu.etaxonomy.cdm.io.common.Source;
|
29
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
30
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
31
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
32
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
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 SalvadorActivator {
|
45
|
private static final Logger logger = Logger.getLogger(SalvadorActivator.class);
|
46
|
|
47
|
//database validation status (create, update, validate ...)
|
48
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
49
|
static final Source berlinModelSource = BerlinModelSources.El_Salvador();
|
50
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
51
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_salvador_preview();
|
52
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_salvador_production();
|
53
|
static final UUID treeUuid = UUID.fromString("b010c84d-6049-45f4-9f13-c065101eaa26");
|
54
|
static final UUID secUuid = UUID.fromString("d03ef02a-f226-4cb1-bdb4-f6c154f08a34");
|
55
|
static final int sourceSecId = 7331;
|
56
|
|
57
|
static final UUID featureTreeUuid = UUID.fromString("9d0e5628-2eda-43ed-bc59-138a7e39ce56");
|
58
|
static final Object[] featureKeyList = new Integer[]{302, 303, 306, 307, 309, 310, 311, 312, 1500, 1800, 1900, 1950, 1980, 2000};
|
59
|
static boolean isIgnore0AuthorTeam = true; //special case for Salvador.
|
60
|
static boolean doExport = false;
|
61
|
static boolean useClassification = true;
|
62
|
|
63
|
//check - import
|
64
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
65
|
static final IImportConfigurator.EDITOR editor = IImportConfigurator.EDITOR.EDITOR_AS_EDITOR;
|
66
|
|
67
|
//NomenclaturalCode
|
68
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
69
|
|
70
|
//ignore null
|
71
|
static final boolean ignoreNull = true;
|
72
|
|
73
|
static final boolean isSalvador = true;
|
74
|
|
75
|
// ****************** ALL *****************************************
|
76
|
|
77
|
//authors
|
78
|
static final boolean doAuthors = true;
|
79
|
//references
|
80
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
81
|
//names
|
82
|
static final boolean doTaxonNames = true;
|
83
|
static final boolean doRelNames = true;
|
84
|
static final boolean doNameStatus = true;
|
85
|
static final boolean doTypes = false; //Types do not exist in El_Salvador DB
|
86
|
static final boolean doNameFacts = false; //Name Facts do not exist in El_Salvador DB
|
87
|
|
88
|
//taxa
|
89
|
static final boolean doTaxa = true;
|
90
|
static final boolean doRelTaxa = true;
|
91
|
static final boolean doFacts = true;
|
92
|
static final boolean doOccurences = false; //Occurrences do not exist in El_Salvador DB
|
93
|
static final boolean doCommonNames = false; //CommonNames do not exist in Salvador DB
|
94
|
|
95
|
//etc.
|
96
|
static final boolean doMarker = false; //#3937 markers must not be imported
|
97
|
static final boolean doUser = true;
|
98
|
|
99
|
|
100
|
static String factFilter = " factCategoryFk NOT IN ("
|
101
|
// + "302, 303, 306, 307, 309, 311, 310, "
|
102
|
+ "1980, 1500, 1950, 1700, 350) ";
|
103
|
|
104
|
|
105
|
// ************************ NONE **************************************** //
|
106
|
|
107
|
// //authors
|
108
|
// static final boolean doAuthors = false;
|
109
|
// //references
|
110
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.CONCEPT_REFERENCES;
|
111
|
// //names
|
112
|
// static final boolean doTaxonNames = false;
|
113
|
// static final boolean doRelNames = false;
|
114
|
// static final boolean doNameStatus = false;
|
115
|
// static final boolean doTypes = false;
|
116
|
// static final boolean doNameFacts = false;
|
117
|
//
|
118
|
// //taxa
|
119
|
// static final boolean doTaxa = true;
|
120
|
// static final boolean doRelTaxa = true;
|
121
|
// static final boolean doFacts = false;
|
122
|
// static final boolean doOccurences = false;
|
123
|
//
|
124
|
// //etc.
|
125
|
// static final boolean doMarker = false;
|
126
|
// static final boolean doUser = false;
|
127
|
|
128
|
|
129
|
public ImportResult doImport(ICdmDataSource destination){
|
130
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") ...");
|
131
|
|
132
|
//make BerlinModel Source
|
133
|
Source source = berlinModelSource;
|
134
|
|
135
|
BerlinModelImportConfigurator config = BerlinModelImportConfigurator.NewInstance(source, destination);
|
136
|
|
137
|
config.setClassificationUuid(treeUuid);
|
138
|
config.setSecUuid(secUuid);
|
139
|
config.setSourceSecId(sourceSecId);
|
140
|
config.setNomenclaturalCode(nomenclaturalCode);
|
141
|
config.setIgnoreNull(ignoreNull);
|
142
|
|
143
|
config.setDoAuthors(doAuthors);
|
144
|
config.setDoReferences(doReferences);
|
145
|
config.setDoTaxonNames(doTaxonNames);
|
146
|
config.setDoRelNames(doRelNames);
|
147
|
config.setDoNameStatus(doNameStatus);
|
148
|
config.setDoTypes(doTypes);
|
149
|
config.setDoNameFacts(doNameFacts);
|
150
|
|
151
|
config.setDoTaxa(doTaxa);
|
152
|
config.setDoRelTaxa(doRelTaxa);
|
153
|
config.setDoFacts(doFacts);
|
154
|
config.setDoOccurrence(doOccurences);
|
155
|
config.setDoCommonNames(doCommonNames);
|
156
|
|
157
|
config.setDoMarker(doMarker);
|
158
|
config.setDoUser(doUser);
|
159
|
|
160
|
config.setTaxonNoteAsFeature(true);
|
161
|
|
162
|
config.setDbSchemaValidation(hbm2dll);
|
163
|
|
164
|
config.setCheck(check);
|
165
|
config.setEditor(editor);
|
166
|
config.setIgnore0AuthorTeam(isIgnore0AuthorTeam);
|
167
|
config.setUseClassification(useClassification);
|
168
|
|
169
|
config.setNamerelationshipTypeMethod(getHandleNameRelationshipTypeMethod());
|
170
|
config.setUserTransformationMethod(getTransformUsernameMethod());
|
171
|
config.setSalvador(isSalvador);
|
172
|
config.setFactFilter(factFilter);
|
173
|
|
174
|
config.setFeatureTreeUuid(featureTreeUuid);
|
175
|
config.setFeatureTreeTitle("Salvador Portal Feature Tree");
|
176
|
|
177
|
// invoke import
|
178
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
179
|
ImportResult result = bmImport.invoke(config);
|
180
|
|
181
|
createFeatureTree(config, bmImport);
|
182
|
|
183
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
184
|
return result;
|
185
|
}
|
186
|
|
187
|
//create feature tree
|
188
|
private void createFeatureTree(BerlinModelImportConfigurator config,
|
189
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport){
|
190
|
if (config.isDoFacts() && (config.getCheck().isImport() ) ){
|
191
|
try {
|
192
|
ICdmRepository app = bmImport.getCdmAppController();
|
193
|
TransactionStatus tx = app.startTransaction(false);
|
194
|
|
195
|
//make feature tree
|
196
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
197
|
|
198
|
// FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
199
|
// tree.getRoot().addChild(distributionNode, 1);
|
200
|
// FeatureNode commonNameNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
201
|
// tree.getRoot().addChild(commonNameNode, 2);
|
202
|
//
|
203
|
// FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
204
|
// tree.getRoot().addChild(imageNode);
|
205
|
|
206
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
207
|
|
208
|
app.commitTransaction(tx);
|
209
|
} catch (Exception e) {
|
210
|
e.printStackTrace();
|
211
|
logger.error("Exception in createFeatureTree: " + e.getMessage());
|
212
|
}
|
213
|
}
|
214
|
}
|
215
|
|
216
|
|
217
|
/**
|
218
|
* @param args
|
219
|
*/
|
220
|
public static void main(String[] args) {
|
221
|
SalvadorActivator activator = new SalvadorActivator();
|
222
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
223
|
|
224
|
activator.doImport(destination);
|
225
|
if (doExport == true){
|
226
|
SalvadorExport export = new SalvadorExport();
|
227
|
export.doExport(destination);
|
228
|
}
|
229
|
System.exit(0);
|
230
|
}
|
231
|
|
232
|
|
233
|
private Method getHandleNameRelationshipTypeMethod(){
|
234
|
String methodName = "handleNameRelationshipType";
|
235
|
try {
|
236
|
Method method = this.getClass().getDeclaredMethod(methodName, Integer.class, NonViralName.class, NonViralName.class);
|
237
|
method.setAccessible(true);
|
238
|
return method;
|
239
|
} catch (Exception e) {
|
240
|
logger.error("Problem creating Method: " + methodName);
|
241
|
return null;
|
242
|
}
|
243
|
}
|
244
|
|
245
|
|
246
|
//used by BerlinModelImportConfigurator
|
247
|
@SuppressWarnings("unused")
|
248
|
private static boolean handleNameRelationshipType(Integer relQualifierFk, INonViralName nameTo, NonViralName nameFrom){
|
249
|
if (relQualifierFk == 72){
|
250
|
nameTo.getHomotypicalGroup().merge(nameFrom.getHomotypicalGroup());
|
251
|
return true;
|
252
|
}
|
253
|
return false;
|
254
|
}
|
255
|
|
256
|
private Method getTransformUsernameMethod(){
|
257
|
String methodName = "transformUsername";
|
258
|
try {
|
259
|
Method method = this.getClass().getDeclaredMethod(methodName, String.class);
|
260
|
method.setAccessible(true);
|
261
|
return method;
|
262
|
} catch (Exception e) {
|
263
|
logger.error("Problem creating Method: " + methodName);
|
264
|
return null;
|
265
|
}
|
266
|
}
|
267
|
|
268
|
//used by BerlinModelImportConfigurator
|
269
|
@SuppressWarnings("unused")
|
270
|
private static String transformUsername(String nameToBeTransformed){
|
271
|
if (nameToBeTransformed == null){
|
272
|
return null;
|
273
|
}else if ("W.G.Berendsohn".equals(nameToBeTransformed)){
|
274
|
return "wgb";
|
275
|
}else if(nameToBeTransformed.startsWith("fs") || nameToBeTransformed.equals("BGBM\\fs")){
|
276
|
return "Frank Specht";
|
277
|
}
|
278
|
return nameToBeTransformed;
|
279
|
}
|
280
|
|
281
|
}
|