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.eflora;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.log4j.Logger;
|
19
|
import org.springframework.transaction.TransactionStatus;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
22
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
26
|
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
|
27
|
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
|
28
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
29
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
30
|
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.io.markup.MarkupTransformer;
|
32
|
import eu.etaxonomy.cdm.model.description.Feature;
|
33
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
34
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
35
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
36
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
37
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
38
|
|
39
|
/**
|
40
|
* @author a.mueller
|
41
|
* @created 20.06.2008
|
42
|
*/
|
43
|
public class FloreGabonActivator extends EfloraActivatorBase {
|
44
|
private static final Logger logger = Logger.getLogger(FloreGabonActivator.class);
|
45
|
|
46
|
//database validation status (create, update, validate ...)
|
47
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
48
|
// static final URI source = EfloraSources.fdg_sample();
|
49
|
static final URI fdg1 = EfloraSources.fdg_1();
|
50
|
static final URI fdg2 = EfloraSources.fdg_2();
|
51
|
static final URI fdg3 = EfloraSources.fdg_3();
|
52
|
static final URI fdg4 = EfloraSources.fdg_4();
|
53
|
static final URI fdg5 = EfloraSources.fdg_5();
|
54
|
static final URI fdg5bis = EfloraSources.fdg_5bis();
|
55
|
static final URI fdg6 = EfloraSources.fdg_6();
|
56
|
static final URI fdg7 = EfloraSources.fdg_7();
|
57
|
static final URI fdg8 = EfloraSources.fdg_8();
|
58
|
static final URI fdg9 = EfloraSources.fdg_9();
|
59
|
static final URI fdg10 = EfloraSources.fdg_10();
|
60
|
static final URI fdg11 = EfloraSources.fdg_11();
|
61
|
static final URI fdg21 = EfloraSources.fdg_21();
|
62
|
static final URI fdg22 = EfloraSources.fdg_22();
|
63
|
static final URI fdg27 = EfloraSources.fdg_27();
|
64
|
static final URI fdg28 = EfloraSources.fdg_28();
|
65
|
static final URI fdg30 = EfloraSources.fdg_30();
|
66
|
static final URI fdg34 = EfloraSources.fdg_34();
|
67
|
static final URI fdg35 = EfloraSources.fdg_35();
|
68
|
|
69
|
|
70
|
|
71
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_preview();
|
72
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_production();
|
73
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
74
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
75
|
|
76
|
|
77
|
//feature tree uuid
|
78
|
public static final UUID featureTreeUuid = UUID.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
|
79
|
private static final String featureTreeTitle = "Flore Gabon Presentation Feature Tree";
|
80
|
|
81
|
//classification
|
82
|
static final UUID classificationUuid = UUID.fromString("2f892452-ff49-48cf-834f-52ca29600719");
|
83
|
static final String classificationTitle = "Flore du Gabon";
|
84
|
|
85
|
|
86
|
//check - import
|
87
|
private boolean h2ForCheck = false;
|
88
|
static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
89
|
|
90
|
static boolean doPrintKeys = false;
|
91
|
|
92
|
|
93
|
private boolean replaceStandardKeyTitles = true;
|
94
|
|
95
|
//taxa
|
96
|
static final boolean doTaxa = true;
|
97
|
|
98
|
static final boolean reuseState = true;
|
99
|
|
100
|
|
101
|
//if true, use inverse include information
|
102
|
private boolean inverseInclude = false;
|
103
|
|
104
|
private boolean includeFdg1 = true;
|
105
|
private boolean includeFdg2 = true;
|
106
|
private boolean includeFdg3 = true;
|
107
|
private boolean includeFdg4 = true;
|
108
|
private boolean includeFdg5 = true;
|
109
|
private boolean includeFdg5bis = true;
|
110
|
private boolean includeFdg6 = true;
|
111
|
private boolean includeFdg7 = true;
|
112
|
private boolean includeFdg8 = true;
|
113
|
private boolean includeFdg9 = true;
|
114
|
private boolean includeFdg10 = true;
|
115
|
private boolean includeFdg11 = true;
|
116
|
private boolean includeFdg21 = true;
|
117
|
private boolean includeFdg22 = true;
|
118
|
private boolean includeFdg27 = true;
|
119
|
private boolean includeFdg28 = true;
|
120
|
private boolean includeFdg30 = true;
|
121
|
private boolean includeFdg34 = true;
|
122
|
private boolean includeFdg35 = true;
|
123
|
|
124
|
// **************** NO CHANGE **********************************************/
|
125
|
|
126
|
private IIoObserver observer = new LoggingIoObserver();
|
127
|
private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
|
128
|
|
129
|
private MarkupImportConfigurator config;
|
130
|
private CdmDefaultImport<MarkupImportConfigurator> myImport;
|
131
|
|
132
|
private void doImport(ICdmDataSource cdmDestination){
|
133
|
observerList.add(observer);
|
134
|
if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
|
135
|
check = CHECK.CHECK_ONLY;
|
136
|
}
|
137
|
|
138
|
//make config
|
139
|
URI source = fdg1;
|
140
|
config = MarkupImportConfigurator.NewInstance(source, cdmDestination);
|
141
|
config.setClassificationUuid(classificationUuid);
|
142
|
config.setDoTaxa(doTaxa);
|
143
|
config.setCheck(check);
|
144
|
config.setDoPrintKeys(doPrintKeys);
|
145
|
config.setDbSchemaValidation(hbm2dll);
|
146
|
config.setObservers(observerList);
|
147
|
config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
|
148
|
config.setSourceReference(getSourceReference("Flore du Gabon"));
|
149
|
config.setClassificationName(classificationTitle);
|
150
|
config.setReuseExistingState(reuseState);
|
151
|
|
152
|
myImport = new CdmDefaultImport<MarkupImportConfigurator>();
|
153
|
|
154
|
//Vol1
|
155
|
executeVolume( fdg1, includeFdg1 ^ inverseInclude);
|
156
|
|
157
|
//Vol2
|
158
|
executeVolume(fdg2, includeFdg2 ^ inverseInclude);
|
159
|
|
160
|
//Vol3
|
161
|
executeVolume(fdg3, includeFdg3 ^ inverseInclude);
|
162
|
|
163
|
//Vol4
|
164
|
executeVolume(fdg4, includeFdg4 ^ inverseInclude);
|
165
|
|
166
|
//Vol5
|
167
|
executeVolume(fdg5, includeFdg5 ^ inverseInclude);
|
168
|
|
169
|
//Vol5bis
|
170
|
executeVolume(fdg5bis, includeFdg5bis ^ inverseInclude);
|
171
|
|
172
|
//Vol6
|
173
|
executeVolume(fdg6, includeFdg6 ^ inverseInclude);
|
174
|
|
175
|
//Vol7
|
176
|
executeVolume(fdg7, includeFdg7 ^ inverseInclude);
|
177
|
|
178
|
//Vol8
|
179
|
executeVolume(fdg8, includeFdg8 ^ inverseInclude);
|
180
|
|
181
|
//Vol9
|
182
|
executeVolume(fdg9, includeFdg9 ^ inverseInclude);
|
183
|
|
184
|
//Vol10
|
185
|
executeVolume(fdg10, includeFdg10 ^ inverseInclude);
|
186
|
|
187
|
//Vol11
|
188
|
executeVolume(fdg11, includeFdg11 ^ inverseInclude);
|
189
|
|
190
|
//Vol21
|
191
|
executeVolume(fdg21, includeFdg21 ^ inverseInclude);
|
192
|
//Vol22
|
193
|
executeVolume(fdg22, includeFdg22 ^ inverseInclude);
|
194
|
//Vol27
|
195
|
executeVolume(fdg27, includeFdg27 ^ inverseInclude);
|
196
|
//Vol28
|
197
|
executeVolume(fdg28, includeFdg28 ^ inverseInclude);
|
198
|
//Vol30
|
199
|
executeVolume(fdg30, includeFdg30 ^ inverseInclude);
|
200
|
//Vol34
|
201
|
executeVolume(fdg34, includeFdg34 ^ inverseInclude);
|
202
|
//Vol35
|
203
|
executeVolume(fdg35, includeFdg35 ^ inverseInclude);
|
204
|
|
205
|
|
206
|
|
207
|
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
208
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
209
|
|
210
|
makeAutomatedFeatureTree(myImport.getCdmAppController(), config.getState(),
|
211
|
featureTreeUuid, featureTreeTitle);
|
212
|
|
213
|
|
214
|
//check keys
|
215
|
if (doPrintKeys){
|
216
|
TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
217
|
List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
|
218
|
for(PolytomousKey key : keys){
|
219
|
key.print(System.out);
|
220
|
System.out.println();
|
221
|
}
|
222
|
myImport.getCdmAppController().commitTransaction(tx);
|
223
|
}
|
224
|
|
225
|
}
|
226
|
|
227
|
/**
|
228
|
* @param markupConfig
|
229
|
* @param myImport
|
230
|
*/
|
231
|
private void executeVolume(URI source, boolean include) {
|
232
|
if (include){
|
233
|
System.out.println("\nStart import from ("+ source.toString() + ") ...");
|
234
|
config.setSource(source);
|
235
|
myImport.invoke(config);
|
236
|
System.out.println("End import from ("+ source.toString() + ")...");
|
237
|
}
|
238
|
}
|
239
|
|
240
|
private Reference<?> getSourceReference(String string) {
|
241
|
Reference<?> result = ReferenceFactory.newGeneric();
|
242
|
result.setTitleCache(string);
|
243
|
return result;
|
244
|
}
|
245
|
|
246
|
|
247
|
|
248
|
|
249
|
private FeatureTree makeFeatureNode(ITermService service){
|
250
|
MarkupTransformer transformer = new MarkupTransformer();
|
251
|
|
252
|
FeatureTree result = FeatureTree.NewInstance();
|
253
|
result.setTitleCache("Old feature tree", true);
|
254
|
FeatureNode root = result.getRoot();
|
255
|
FeatureNode newNode;
|
256
|
|
257
|
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
258
|
root.addChild(newNode);
|
259
|
|
260
|
addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
|
261
|
|
262
|
addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
|
263
|
newNode = FeatureNode.NewInstance(Feature.ANATOMY());
|
264
|
addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
|
265
|
|
266
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
|
267
|
addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
|
268
|
|
269
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
|
270
|
|
271
|
newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
272
|
root.addChild(newNode);
|
273
|
|
274
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
275
|
root.addChild(newNode);
|
276
|
|
277
|
newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
|
278
|
root.addChild(newNode);
|
279
|
addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
|
280
|
|
281
|
newNode = FeatureNode.NewInstance(Feature.USES());
|
282
|
root.addChild(newNode);
|
283
|
|
284
|
addFeataureNodesByStringList(chomosomesList, root, transformer, service);
|
285
|
|
286
|
newNode = FeatureNode.NewInstance(Feature.CITATION());
|
287
|
root.addChild(newNode);
|
288
|
|
289
|
return result;
|
290
|
}
|
291
|
|
292
|
private static String [] chomosomesList = new String[]{
|
293
|
"Chromosomes",
|
294
|
};
|
295
|
|
296
|
|
297
|
private static String [] habitatEcologyList = new String[]{
|
298
|
"Habitat",
|
299
|
"Habitat & Ecology"
|
300
|
};
|
301
|
|
302
|
|
303
|
private static String [] generellDescriptionsUpToAnatomyList = new String[]{
|
304
|
"Fossils",
|
305
|
"Morphology and anatomy",
|
306
|
"Morphology",
|
307
|
"Vegetative morphology and anatomy",
|
308
|
};
|
309
|
|
310
|
|
311
|
private static String [] anatomySubfeatureList = new String[]{
|
312
|
"Leaf anatomy",
|
313
|
"Wood anatomy"
|
314
|
};
|
315
|
|
316
|
private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
|
317
|
"Flower morphology",
|
318
|
"Palynology",
|
319
|
"Pollination",
|
320
|
"Pollen morphology",
|
321
|
"embryology",
|
322
|
"cytology",
|
323
|
"Life cycle",
|
324
|
"Fruits and embryology",
|
325
|
"Dispersal",
|
326
|
"Chromosome numbers",
|
327
|
"Phytochemistry and Chemotaxonomy",
|
328
|
};
|
329
|
|
330
|
|
331
|
private static String [] phytoChemoSubFeaturesList = new String[]{
|
332
|
"Alkaloids",
|
333
|
"Iridoid glucosides",
|
334
|
"Leaf phenolics",
|
335
|
"Storage products of seeds",
|
336
|
"Aluminium",
|
337
|
"Chemotaxonomy",
|
338
|
};
|
339
|
|
340
|
|
341
|
private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
|
342
|
"Phytochemistry",
|
343
|
"Taxonomy",
|
344
|
"history",
|
345
|
"cultivation",
|
346
|
"Notes"
|
347
|
};
|
348
|
|
349
|
|
350
|
private static String [] descriptionFeatureList = new String[]{
|
351
|
"lifeform",
|
352
|
"Juvenile parts",
|
353
|
"Bark",
|
354
|
//new
|
355
|
"wood",
|
356
|
"Indumentum",
|
357
|
"endophytic body",
|
358
|
"apical buds",
|
359
|
"flowering buds",
|
360
|
"Branchlets",
|
361
|
"Branches",
|
362
|
"Branch",
|
363
|
"Flowering branchlets",
|
364
|
"Trees",
|
365
|
"Twigs",
|
366
|
"stem",
|
367
|
"Stems",
|
368
|
"stem leaves",
|
369
|
"Leaves",
|
370
|
"extraxylary sclerenchyma",
|
371
|
"flower-bearing stems",
|
372
|
"Petiole",
|
373
|
"Petiolules",
|
374
|
"Leaflets",
|
375
|
"Lamina",
|
376
|
"Veins",
|
377
|
"Lateral veins",
|
378
|
"secondary veins",
|
379
|
"Intersecondary veins",
|
380
|
"veinlets",
|
381
|
"Thyrsus",
|
382
|
"Thyrses",
|
383
|
"Inflorescences",
|
384
|
"Inflorescence",
|
385
|
"Young inflorescences",
|
386
|
"Male inflorescences",
|
387
|
"Female inflorescences",
|
388
|
"rachises",
|
389
|
"Bracts",
|
390
|
"Pedicels",
|
391
|
"flowering buds",
|
392
|
"scales",
|
393
|
"Buds",
|
394
|
"Flowers",
|
395
|
"Flower",
|
396
|
"Flowering",
|
397
|
"Stigma",
|
398
|
"perianth",
|
399
|
"Sepals",
|
400
|
"Sepal",
|
401
|
"Outer Sepals",
|
402
|
"Axillary",
|
403
|
"cymes",
|
404
|
"Calyx",
|
405
|
"Androgynophore",
|
406
|
"Petal",
|
407
|
"Petals",
|
408
|
"perigone",
|
409
|
"perigone lobes",
|
410
|
"perigone tube",
|
411
|
"Disc",
|
412
|
"corolla",
|
413
|
"Stamens",
|
414
|
"Staminodes",
|
415
|
"Ovary",
|
416
|
"Anthers",
|
417
|
"anther",
|
418
|
"Pistil",
|
419
|
"Pistillode",
|
420
|
"Ovules",
|
421
|
"androecium",
|
422
|
"gynoecium",
|
423
|
"Filaments",
|
424
|
"Style",
|
425
|
"annulus",
|
426
|
"female flowers",
|
427
|
"Male flowers",
|
428
|
"Androphore",
|
429
|
"Female",
|
430
|
"Infructescences", //order not consistent (sometimes before "Flowers")
|
431
|
"Fruit",
|
432
|
"Fruits",
|
433
|
"fruiting axes",
|
434
|
"drupes",
|
435
|
"Arillode",
|
436
|
"seed",
|
437
|
"Seeds",
|
438
|
"Seedling",
|
439
|
"flower tube",
|
440
|
"nutlets",
|
441
|
"pollen",
|
442
|
"secondary xylem",
|
443
|
"chromosome number",
|
444
|
|
445
|
"figure",
|
446
|
"fig",
|
447
|
"figs",
|
448
|
|
449
|
|
450
|
|
451
|
};
|
452
|
|
453
|
public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
|
454
|
FeatureNode lastChild = null;
|
455
|
try {
|
456
|
for (String featureString : featureStringList){
|
457
|
UUID featureUuid;
|
458
|
featureUuid = transformer.getFeatureUuid(featureString);
|
459
|
Feature feature = (Feature)termService.find(featureUuid);
|
460
|
if (feature != null){
|
461
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
462
|
root.addChild(child);
|
463
|
}
|
464
|
}
|
465
|
|
466
|
} catch (UndefinedTransformerMethodException e) {
|
467
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
468
|
}
|
469
|
return lastChild;
|
470
|
}
|
471
|
|
472
|
|
473
|
|
474
|
/**
|
475
|
* @param args
|
476
|
*/
|
477
|
public static void main(String[] args) {
|
478
|
FloreGabonActivator me = new FloreGabonActivator();
|
479
|
me.doImport(cdmDestination);
|
480
|
}
|
481
|
}
|