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.ICdmRepository;
|
17
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
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.algaterra.AlgaTerraImportConfigurator;
|
22
|
import eu.etaxonomy.cdm.io.algaterra.AlgaTerraImportTransformer;
|
23
|
import eu.etaxonomy.cdm.io.algaterra.AlgaTerraSpecimenImportBase;
|
24
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
28
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
29
|
import eu.etaxonomy.cdm.io.common.Source;
|
30
|
import eu.etaxonomy.cdm.model.description.Feature;
|
31
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
32
|
import eu.etaxonomy.cdm.model.term.FeatureNode;
|
33
|
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
34
|
|
35
|
|
36
|
/**
|
37
|
* TODO add the following to a wiki page:
|
38
|
* 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
|
39
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
40
|
*
|
41
|
*
|
42
|
* @author a.mueller
|
43
|
*
|
44
|
*/
|
45
|
public class AlgaTerraActivator {
|
46
|
private static final Logger logger = Logger.getLogger(AlgaTerraActivator.class);
|
47
|
|
48
|
//database validation status (create, update, validate ...)
|
49
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
50
|
static final Source berlinModelSource = BerlinModelSources.AlgaTerra();
|
51
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
52
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
53
|
|
54
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_algaterra_preview();
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_algaterra_production();
|
56
|
|
57
|
|
58
|
static final UUID treeUuid = UUID.fromString("1f617402-78dc-4bf1-ac77-d260600a8879");
|
59
|
static final int sourceSecId = 7331;
|
60
|
static final UUID sourceRefUuid = UUID.fromString("7e1a2500-93a5-40c2-ba34-0213d7822379");
|
61
|
|
62
|
static final UUID featureTreeUuid = UUID.fromString("a970168a-36fd-4c7c-931e-87214a965c14");
|
63
|
static final Object[] featureKeyList = new Integer[]{7,201,203,204,206,207};
|
64
|
static final UUID specimenFeatureTreeUuid = UUID.fromString("ba86246e-d4d0-419f-832e-86d70b1e4bd7");
|
65
|
|
66
|
static final boolean loginAsDefaultAdmin = true;
|
67
|
//TODO set to false for final import
|
68
|
static final boolean removeRestricted = true;
|
69
|
|
70
|
static final boolean importOriginalSizeMedia = false;
|
71
|
|
72
|
//check - import
|
73
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
74
|
|
75
|
private boolean ignoreNull = true;
|
76
|
|
77
|
private boolean includeFlatClassifications = true;
|
78
|
private boolean includeAllNonMisappliedRelatedClassifications = true;
|
79
|
|
80
|
private EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
81
|
|
82
|
//NomenclaturalCode
|
83
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
84
|
|
85
|
static String factFilter = " factCategoryFk NOT IN (7, 201, 202, 203, 204, 205, 206, 207, 208, 1000 ) ";
|
86
|
|
87
|
|
88
|
// ****************** ALL *****************************************
|
89
|
|
90
|
//authors
|
91
|
static final boolean doAuthors = true;
|
92
|
//references
|
93
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
94
|
//names
|
95
|
static final boolean doTaxonNames = true;
|
96
|
static final boolean doRelNames = true;
|
97
|
static final boolean doNameStatus = true;
|
98
|
static final boolean doTypes = true;
|
99
|
|
100
|
//taxa
|
101
|
static final boolean doTaxa = true;
|
102
|
static final boolean doRelTaxa = true;
|
103
|
static final boolean doFacts = true;
|
104
|
|
105
|
//alga terra specific
|
106
|
static final boolean ecoFacts = true;
|
107
|
static final boolean doFactEcology = true;
|
108
|
static final boolean doImages = false;
|
109
|
static final boolean doDna = true;
|
110
|
static final boolean doMorphology = true;
|
111
|
|
112
|
// ************************ NONE **************************************** //
|
113
|
|
114
|
// //authors
|
115
|
// static final boolean doAuthors = false;
|
116
|
// //references
|
117
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
118
|
// //names
|
119
|
// static final boolean doTaxonNames = false;
|
120
|
// static final boolean doRelNames = false;
|
121
|
// static final boolean doNameStatus = false;
|
122
|
// static final boolean doTypes = true;
|
123
|
// static final boolean doNameFacts = false;
|
124
|
//
|
125
|
// //taxa
|
126
|
// static final boolean doTaxa = false;
|
127
|
// static final boolean doRelTaxa = false;
|
128
|
// static final boolean doFacts = false;
|
129
|
//
|
130
|
// //alga terra specific
|
131
|
// static final boolean ecoFacts = false;
|
132
|
// static final boolean doFactEcology = false;
|
133
|
// static final boolean doImages = false;
|
134
|
// static final boolean doDna = false;
|
135
|
// static final boolean doMorphology = false;
|
136
|
|
137
|
|
138
|
public void invoke(String[] args){
|
139
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") ...");
|
140
|
logger.debug("Start");
|
141
|
//make BerlinModel Source
|
142
|
Source source = berlinModelSource;
|
143
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
144
|
|
145
|
AlgaTerraImportConfigurator config = AlgaTerraImportConfigurator.NewInstance(source, destination);
|
146
|
|
147
|
config.setClassificationUuid(treeUuid);
|
148
|
config.setSourceSecId(sourceSecId);
|
149
|
config.setNomenclaturalCode(nomenclaturalCode);
|
150
|
|
151
|
config.setDoAuthors(doAuthors);
|
152
|
config.setDoReferences(doReferences);
|
153
|
config.setDoTaxonNames(doTaxonNames);
|
154
|
config.setDoRelNames(doRelNames);
|
155
|
config.setDoNameStatus(doNameStatus);
|
156
|
config.setDoTypes(doTypes);
|
157
|
|
158
|
config.setDoTaxa(doTaxa);
|
159
|
config.setDoRelTaxa(doRelTaxa);
|
160
|
config.setDoFacts(doFacts);
|
161
|
config.setDoEcoFacts(ecoFacts);
|
162
|
config.setDoImages(doImages);
|
163
|
config.setDoFactEcology(doFactEcology);
|
164
|
config.setDoDna(doDna);
|
165
|
config.setDoMorphology(doMorphology);
|
166
|
|
167
|
config.setSourceRefUuid(sourceRefUuid);
|
168
|
config.setIgnoreNull(ignoreNull);
|
169
|
config.setRemoveRestricted(removeRestricted);
|
170
|
config.setImportOriginalSizeMedia(importOriginalSizeMedia);
|
171
|
|
172
|
config.setIncludeFlatClassifications(includeFlatClassifications);
|
173
|
config.setIncludeAllNonMisappliedRelatedClassifications(includeAllNonMisappliedRelatedClassifications);
|
174
|
config.setFactFilter(factFilter);
|
175
|
|
176
|
config.setDbSchemaValidation(hbm2dll);
|
177
|
|
178
|
config.setCheck(check);
|
179
|
config.setEditor(editor);
|
180
|
|
181
|
if (loginAsDefaultAdmin){
|
182
|
config.authenticateAsDefaultAdmin();
|
183
|
}
|
184
|
|
185
|
// invoke import
|
186
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
187
|
bmImport.invoke(config);
|
188
|
|
189
|
if (doFacts && (config.getCheck().equals(CHECK.CHECK_AND_IMPORT) || config.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
190
|
ICdmRepository app = bmImport.getCdmAppController();
|
191
|
|
192
|
//make feature tree
|
193
|
makeTaxonFeatureTree(config, app);
|
194
|
|
195
|
//make specimen feature tree
|
196
|
//TODO more specimen specific
|
197
|
makeSpecimenFeatureTree(config, app);
|
198
|
|
199
|
}
|
200
|
|
201
|
|
202
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
203
|
}
|
204
|
|
205
|
|
206
|
/**
|
207
|
* @param config
|
208
|
* @param app
|
209
|
*/
|
210
|
private void makeTaxonFeatureTree(AlgaTerraImportConfigurator config, ICdmRepository app) {
|
211
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, config.getFeatureMap(), featureKeyList);
|
212
|
tree.setTitleCache("AlgaTerra Taxon Feature Tree", true);
|
213
|
|
214
|
FeatureNode node = FeatureNode.NewInstance(Feature.HABITAT());
|
215
|
tree.getRoot().addChild(node);
|
216
|
|
217
|
// node = FeatureNode.NewInstance(Feature.OBSERVATION());
|
218
|
// tree.getRoot().addChild(node);
|
219
|
//
|
220
|
// node = FeatureNode.NewInstance(Feature.SPECIMEN());
|
221
|
// tree.getRoot().addChild(node);
|
222
|
//
|
223
|
// node = FeatureNode.NewInstance(Feature.INDIVIDUALS_ASSOCIATION());
|
224
|
// tree.getRoot().addChild(node);
|
225
|
|
226
|
//needed ??
|
227
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
228
|
tree.getRoot().addChild(distributionNode, 2);
|
229
|
|
230
|
// //needed ??
|
231
|
// FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
232
|
// tree.getRoot().addChild(imageNode);
|
233
|
|
234
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
235
|
}
|
236
|
|
237
|
|
238
|
/**
|
239
|
* @param config
|
240
|
* @param app
|
241
|
* @param tree
|
242
|
*/
|
243
|
private void makeSpecimenFeatureTree(AlgaTerraImportConfigurator config, ICdmRepository app) {
|
244
|
ITermService termService = app.getTermService();
|
245
|
FeatureTree specimenTree = FeatureTree.NewInstance(specimenFeatureTreeUuid);
|
246
|
// FeatureTree specimenTree = TreeCreator.flatTree(specimenFeatureTreeUuid, config.getFeatureMap(), featureKeyList);
|
247
|
specimenTree.setTitleCache("AlgaTerra Specimen Feature Tree", true);
|
248
|
FeatureNode root = specimenTree.getRoot();
|
249
|
|
250
|
|
251
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
252
|
root.addChild(imageNode);
|
253
|
|
254
|
addFeatureNodeByUuid(root, termService, AlgaTerraSpecimenImportBase.uuidFeatureAlgaTerraClimate);
|
255
|
FeatureNode node = FeatureNode.NewInstance(Feature.HABITAT());
|
256
|
root.addChild(node);
|
257
|
addFeatureNodeByUuid(root, termService, AlgaTerraSpecimenImportBase.uuidFeatureHabitatExplanation);
|
258
|
addFeatureNodeByUuid(root, termService, AlgaTerraSpecimenImportBase.uuidFeatureAlgaTerraLifeForm);
|
259
|
|
260
|
addFeatureNodeByUuid(root, termService, AlgaTerraSpecimenImportBase.uuidFeatureAdditionalData);
|
261
|
addFeatureNodeByUuid(root, termService, AlgaTerraSpecimenImportBase.uuidFeatureSpecimenCommunity);
|
262
|
|
263
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeaturePH);
|
264
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureConductivity);
|
265
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureWaterTemperature);
|
266
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureSilica);
|
267
|
FeatureNode nitrogenNode = makeNitrogenNode(root, termService);
|
268
|
addFeatureNodeByUuid(nitrogenNode, termService, AlgaTerraImportTransformer.uuidFeatureNitrate);
|
269
|
addFeatureNodeByUuid(nitrogenNode, termService, AlgaTerraImportTransformer.uuidFeatureNitrite);
|
270
|
addFeatureNodeByUuid(nitrogenNode, termService, AlgaTerraImportTransformer.uuidFeatureAmmonium);
|
271
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeaturePhosphate);
|
272
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureOrthoPhosphate);
|
273
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureNPRation);
|
274
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureDIN);
|
275
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureSRP);
|
276
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureOxygenSaturation);
|
277
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureCl);
|
278
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureSecchiDepth);
|
279
|
addFeatureNodeByUuid(root, termService, AlgaTerraImportTransformer.uuidFeatureCommunity);
|
280
|
app.getFeatureTreeService().saveOrUpdate(specimenTree);
|
281
|
}
|
282
|
|
283
|
private FeatureNode makeNitrogenNode(FeatureNode root, ITermService termService) {
|
284
|
Feature nFeature = Feature.NewInstance("Supra feature for all Nitrogen related subfeatures", "Nitrogen", "N");
|
285
|
termService.save(nFeature);
|
286
|
FeatureNode nNode = FeatureNode.NewInstance(nFeature);
|
287
|
root.addChild(nNode);
|
288
|
return nNode;
|
289
|
}
|
290
|
|
291
|
|
292
|
// private FeatureNode addFeataureNodesByUuidList(UUID[] featureUuidList, FeatureNode root, ITermService termService){
|
293
|
// FeatureNode lastChild = null;
|
294
|
// for (UUID featureUuid : featureUuidList){
|
295
|
// addFeatureNodeByUuid(root, termService, featureUuid);
|
296
|
// }
|
297
|
//
|
298
|
// return lastChild;
|
299
|
// }
|
300
|
|
301
|
|
302
|
/**
|
303
|
* @param root
|
304
|
* @param termService
|
305
|
* @param featureUuid
|
306
|
*/
|
307
|
private void addFeatureNodeByUuid(FeatureNode root, ITermService termService, UUID featureUuid) {
|
308
|
Feature feature = (Feature)termService.find(featureUuid);
|
309
|
if (feature != null){
|
310
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
311
|
root.addChild(child);
|
312
|
}
|
313
|
}
|
314
|
|
315
|
|
316
|
/**
|
317
|
* @param args
|
318
|
*/
|
319
|
public static void main(String[] args) {
|
320
|
AlgaTerraActivator activator = new AlgaTerraActivator();
|
321
|
activator.invoke(args);
|
322
|
}
|
323
|
|
324
|
}
|