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.eflora.floraMalesiana.FloraMalesianaTransformer;
|
31
|
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
|
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
|
* @version 1.0
|
43
|
*/
|
44
|
public class FloraMalesianaActivator extends EfloraActivatorBase {
|
45
|
private static final Logger logger = Logger.getLogger(FloraMalesianaActivator.class);
|
46
|
|
47
|
//database validation status (create, update, validate ...)
|
48
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
49
|
|
50
|
static final URI fmSource12 = EfloraSources.fm_12();
|
51
|
static final URI fmSource13_small = EfloraSources.fm_13_small_families();
|
52
|
static final URI fmSource13_large = EfloraSources.fm_13_large_families();
|
53
|
static final URI fmSource14 = EfloraSources.fm_14();
|
54
|
static final URI fmSource15 = EfloraSources.fm_15();
|
55
|
static final URI fmSource16 = EfloraSources.fm_16();
|
56
|
static final URI fmSource17_1 = EfloraSources.fm_17_1();
|
57
|
static final URI fmSource17_2 = EfloraSources.fm_17_2();
|
58
|
static final URI fmSource18 = EfloraSources.fm_18();
|
59
|
static final URI fmSource19 = EfloraSources.fm_19();
|
60
|
static final URI fmSource20 = EfloraSources.fm_20();
|
61
|
|
62
|
static final URI fmSource_Ser2_02 = EfloraSources.fm_ser2_2();
|
63
|
static final URI fmSource_Ser2_03 = EfloraSources.fm_ser2_3();
|
64
|
|
65
|
|
66
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
|
67
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
|
68
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
69
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
70
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
71
|
|
72
|
private boolean includeBase = true;
|
73
|
private boolean includeVol12 = includeBase;
|
74
|
private boolean includeVol13_small = includeBase;
|
75
|
private boolean includeVol13_large = includeBase;
|
76
|
private boolean includeVol14 = includeBase;
|
77
|
private boolean includeVol15 = includeBase;
|
78
|
private boolean includeVol16 = includeBase;
|
79
|
private boolean includeVol17_1 = includeBase;
|
80
|
private boolean includeVol17_2 = includeBase;
|
81
|
private boolean includeVol18 = includeBase;
|
82
|
private boolean includeVol19 = includeBase;
|
83
|
private boolean includeVol20 = includeBase;
|
84
|
private boolean includeVol2_2 = includeBase;
|
85
|
private boolean includeVol2_3 = includeBase;
|
86
|
|
87
|
private boolean h2ForCheck = false;
|
88
|
|
89
|
|
90
|
//feature tree uuid
|
91
|
public static final UUID featureTreeUuid = UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
|
92
|
private static final String featureTreeTitle = "Flora Malesiana Presentation Feature Tree";
|
93
|
|
94
|
//classification
|
95
|
static final UUID classificationUuid = UUID.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
|
96
|
|
97
|
//check - import
|
98
|
static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
99
|
|
100
|
static boolean doPrintKeys = false;
|
101
|
|
102
|
//taxa
|
103
|
static final boolean doTaxa = true;
|
104
|
|
105
|
|
106
|
private boolean replaceStandardKeyTitles = false;
|
107
|
|
108
|
private IIoObserver observer = new LoggingIoObserver();
|
109
|
private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
|
110
|
|
111
|
|
112
|
private void doImport(ICdmDataSource cdmDestination){
|
113
|
observerList.add(observer);
|
114
|
if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
|
115
|
check = CHECK.CHECK_ONLY;
|
116
|
}
|
117
|
|
118
|
//make Source
|
119
|
// URI source = fmSource13_small;
|
120
|
URI source = null;
|
121
|
|
122
|
MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
|
123
|
markupConfig.setClassificationUuid(classificationUuid);
|
124
|
markupConfig.setDoTaxa(doTaxa);
|
125
|
markupConfig.setCheck(check);
|
126
|
markupConfig.setDoPrintKeys(doPrintKeys);
|
127
|
markupConfig.setDbSchemaValidation(hbm2dll);
|
128
|
markupConfig.setObservers(observerList);
|
129
|
markupConfig.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
|
130
|
|
131
|
|
132
|
markupConfig.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
|
133
|
|
134
|
CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>();
|
135
|
|
136
|
|
137
|
//Vol12
|
138
|
doSource(includeVol12, fmSource12, "Flora Malesiana - vol. 12", markupConfig, myImport);
|
139
|
|
140
|
//Vol13_large
|
141
|
doSource(includeVol13_large, fmSource13_large, "Flora Malesiana - vol. 13", markupConfig, myImport);
|
142
|
|
143
|
//Vol13_small
|
144
|
doSource(includeVol13_small, fmSource13_small, "Flora Malesiana - vol. 13", markupConfig, myImport);
|
145
|
|
146
|
//Vol14
|
147
|
doSource(includeVol14, fmSource14, "Flora Malesiana - vol. 14", markupConfig, myImport);
|
148
|
|
149
|
//Vol15
|
150
|
doSource(includeVol15, fmSource15, "Flora Malesiana - vol. 15", markupConfig, myImport);
|
151
|
|
152
|
//Vol16
|
153
|
doSource(includeVol16, fmSource16, "Flora Malesiana - vol. 16", markupConfig, myImport);
|
154
|
|
155
|
//Vol17, part1
|
156
|
doSource(includeVol17_1, fmSource17_1, "Flora Malesiana - vol. 17, part I", markupConfig, myImport);
|
157
|
|
158
|
//Vol17, part2
|
159
|
doSource(includeVol17_2, fmSource17_2, "Flora Malesiana - vol. 17, part II", markupConfig, myImport);
|
160
|
|
161
|
//Vol18
|
162
|
doSource(includeVol18, fmSource18, "Flora Malesiana - vol. 18", markupConfig, myImport);
|
163
|
|
164
|
//Vol19
|
165
|
doSource(includeVol19, fmSource19, "Flora Malesiana - vol. 19", markupConfig, myImport);
|
166
|
|
167
|
//Vol20
|
168
|
doSource(includeVol20, fmSource20, "Flora Malesiana - vol. 20", markupConfig, myImport);
|
169
|
|
170
|
//Vol_2_2
|
171
|
doSource(includeVol2_2, fmSource_Ser2_02, "Flora Malesiana - Ser.2, vol. 2", markupConfig, myImport);
|
172
|
|
173
|
//Vol_2_3
|
174
|
doSource(includeVol2_3, fmSource_Ser2_03, "Flora Malesiana - Ser.2, vol. 3", markupConfig, myImport);
|
175
|
|
176
|
makeAutomatedFeatureTree(myImport.getCdmAppController(), markupConfig.getState(),
|
177
|
featureTreeUuid, featureTreeTitle);
|
178
|
|
179
|
// makeGeoService();
|
180
|
|
181
|
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
182
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
183
|
|
184
|
//check keys
|
185
|
if (doPrintKeys){
|
186
|
TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
187
|
List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
|
188
|
for(PolytomousKey key : keys){
|
189
|
key.print(System.out);
|
190
|
System.out.println();
|
191
|
}
|
192
|
myImport.getCdmAppController().commitTransaction(tx);
|
193
|
}
|
194
|
|
195
|
}
|
196
|
|
197
|
private void doSource(boolean doInclude, URI source, String sourceTitle, MarkupImportConfigurator markupConfig,
|
198
|
CdmDefaultImport<MarkupImportConfigurator> myImport) {
|
199
|
if (doInclude){
|
200
|
System.out.println("\nStart import from ("+ source.toString() + ") ...");
|
201
|
markupConfig.setSource(source);
|
202
|
markupConfig.setSourceReference(getSourceReference(sourceTitle));
|
203
|
myImport.invoke(markupConfig);
|
204
|
System.out.println("End import from ("+ source.toString() + ")...");
|
205
|
}
|
206
|
}
|
207
|
|
208
|
private Reference<?> getSourceReference(String string) {
|
209
|
Reference<?> result = ReferenceFactory.newGeneric();
|
210
|
result.setTitleCache(string);
|
211
|
return result;
|
212
|
}
|
213
|
|
214
|
private FeatureTree makeFeatureNode(ITermService service){
|
215
|
FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
|
216
|
|
217
|
FeatureTree result = FeatureTree.NewInstance(UUID.randomUUID());
|
218
|
result.setTitleCache("Flora Malesiana Presentation Feature Tree - Old");
|
219
|
FeatureNode root = result.getRoot();
|
220
|
FeatureNode newNode;
|
221
|
|
222
|
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
223
|
root.addChild(newNode);
|
224
|
|
225
|
addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
|
226
|
|
227
|
addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
|
228
|
newNode = FeatureNode.NewInstance(Feature.ANATOMY());
|
229
|
addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
|
230
|
|
231
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
|
232
|
addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
|
233
|
|
234
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
|
235
|
|
236
|
|
237
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
238
|
root.addChild(newNode);
|
239
|
|
240
|
newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
|
241
|
root.addChild(newNode);
|
242
|
addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
|
243
|
|
244
|
newNode = FeatureNode.NewInstance(Feature.USES());
|
245
|
root.addChild(newNode);
|
246
|
|
247
|
addFeataureNodesByStringList(chomosomesList, root, transformer, service);
|
248
|
|
249
|
newNode = FeatureNode.NewInstance(Feature.CITATION());
|
250
|
root.addChild(newNode);
|
251
|
|
252
|
return result;
|
253
|
}
|
254
|
|
255
|
private static String [] chomosomesList = new String[]{
|
256
|
"Chromosomes",
|
257
|
};
|
258
|
|
259
|
|
260
|
private static String [] habitatEcologyList = new String[]{
|
261
|
"Habitat",
|
262
|
"Habitat & Ecology"
|
263
|
};
|
264
|
|
265
|
|
266
|
private static String [] generellDescriptionsUpToAnatomyList = new String[]{
|
267
|
"Fossils",
|
268
|
"Morphology and anatomy",
|
269
|
"Morphology",
|
270
|
"Vegetative morphology and anatomy",
|
271
|
};
|
272
|
|
273
|
|
274
|
private static String [] anatomySubfeatureList = new String[]{
|
275
|
"Leaf anatomy",
|
276
|
"Wood anatomy"
|
277
|
};
|
278
|
|
279
|
private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
|
280
|
"Flower morphology",
|
281
|
"Palynology",
|
282
|
"Pollination",
|
283
|
"Pollen morphology",
|
284
|
"embryology",
|
285
|
"cytology",
|
286
|
"Life cycle",
|
287
|
"Fruits and embryology",
|
288
|
"Dispersal",
|
289
|
"Chromosome numbers",
|
290
|
"Phytochemistry and Chemotaxonomy",
|
291
|
};
|
292
|
|
293
|
|
294
|
private static String [] phytoChemoSubFeaturesList = new String[]{
|
295
|
"Alkaloids",
|
296
|
"Iridoid glucosides",
|
297
|
"Leaf phenolics",
|
298
|
"Storage products of seeds",
|
299
|
"Aluminium",
|
300
|
"Chemotaxonomy",
|
301
|
};
|
302
|
|
303
|
|
304
|
private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
|
305
|
"Phytochemistry",
|
306
|
"Taxonomy",
|
307
|
"history",
|
308
|
"cultivation",
|
309
|
"Notes"
|
310
|
};
|
311
|
|
312
|
|
313
|
private static String [] descriptionFeatureList = new String[]{
|
314
|
"lifeform",
|
315
|
"Bark",
|
316
|
//new
|
317
|
"wood",
|
318
|
"Indumentum",
|
319
|
"endophytic body",
|
320
|
"flowering buds",
|
321
|
"Branchlets",
|
322
|
"Branches",
|
323
|
"Branch",
|
324
|
"Flowering branchlets",
|
325
|
"Trees",
|
326
|
"Twigs",
|
327
|
"stem",
|
328
|
"Stems",
|
329
|
"stem leaves",
|
330
|
"Leaves",
|
331
|
"flower-bearing stems",
|
332
|
"Petiole",
|
333
|
"Petiolules",
|
334
|
"Leaflets",
|
335
|
"Thyrsus",
|
336
|
"Thyrses",
|
337
|
"Inflorescences",
|
338
|
"Inflorescence",
|
339
|
"Young inflorescences",
|
340
|
"Male inflorescences",
|
341
|
"Female inflorescences",
|
342
|
"Bracts",
|
343
|
"Pedicels",
|
344
|
"flowering buds",
|
345
|
"scales",
|
346
|
"Buds",
|
347
|
"Flowers",
|
348
|
"Flower",
|
349
|
"Flowering",
|
350
|
"Stigma",
|
351
|
"perianth",
|
352
|
"Sepals",
|
353
|
"Sepal",
|
354
|
"Outer Sepals",
|
355
|
"Axillary",
|
356
|
"cymes",
|
357
|
"Calyx",
|
358
|
"Petal",
|
359
|
"Petals",
|
360
|
"perigone",
|
361
|
"perigone lobes",
|
362
|
"perigone tube",
|
363
|
"Disc",
|
364
|
"corolla",
|
365
|
"Stamens",
|
366
|
"Staminodes",
|
367
|
"Ovary",
|
368
|
"Anthers",
|
369
|
"anther",
|
370
|
"Pistil",
|
371
|
"Pistillode",
|
372
|
"Ovules",
|
373
|
"androecium",
|
374
|
"gynoecium",
|
375
|
"Filaments",
|
376
|
"Style",
|
377
|
"annulus",
|
378
|
"female flowers",
|
379
|
"Male flowers",
|
380
|
"Female",
|
381
|
"Infructescences", //order not consistent (sometimes before "Flowers")
|
382
|
"Fruit",
|
383
|
"Fruits",
|
384
|
"fruiting axes",
|
385
|
"drupes",
|
386
|
"Arillode",
|
387
|
"seed",
|
388
|
"Seeds",
|
389
|
"Seedling",
|
390
|
"flower tube",
|
391
|
"nutlets",
|
392
|
"pollen",
|
393
|
"secondary xylem",
|
394
|
"chromosome number",
|
395
|
|
396
|
"figure",
|
397
|
"fig",
|
398
|
"figs",
|
399
|
|
400
|
|
401
|
|
402
|
};
|
403
|
|
404
|
public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
|
405
|
FeatureNode lastChild = null;
|
406
|
try {
|
407
|
for (String featureString : featureStringList){
|
408
|
UUID featureUuid;
|
409
|
featureUuid = transformer.getFeatureUuid(featureString);
|
410
|
Feature feature = (Feature)termService.find(featureUuid);
|
411
|
if (feature != null){
|
412
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
413
|
root.addChild(child);
|
414
|
}
|
415
|
}
|
416
|
|
417
|
} catch (UndefinedTransformerMethodException e) {
|
418
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
419
|
}
|
420
|
return lastChild;
|
421
|
}
|
422
|
|
423
|
|
424
|
|
425
|
/**
|
426
|
* @param args
|
427
|
*/
|
428
|
public static void main(String[] args) {
|
429
|
FloraMalesianaActivator me = new FloraMalesianaActivator();
|
430
|
me.doImport(cdmDestination);
|
431
|
}
|
432
|
|
433
|
}
|