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.app.common.CdmDestinations;
|
23
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
24
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
|
28
|
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
|
29
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
30
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
31
|
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer;
|
32
|
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
|
33
|
import eu.etaxonomy.cdm.model.description.Feature;
|
34
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
35
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
36
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
37
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
39
|
|
40
|
/**
|
41
|
* @author a.mueller
|
42
|
* @created 20.06.2008
|
43
|
* @version 1.0
|
44
|
*/
|
45
|
public class FloraMalesianaVol13Activator {
|
46
|
private static final Logger logger = Logger.getLogger(FloraMalesianaVol13Activator.class);
|
47
|
|
48
|
//database validation status (create, update, validate ...)
|
49
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
50
|
static final URI fmSource13_small = EfloraSources.fm_13_small_families();
|
51
|
static final URI fmSource13_large = EfloraSources.fm_13_large_families();
|
52
|
|
53
|
|
54
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
|
56
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
|
57
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
58
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
59
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
60
|
|
61
|
private boolean includeVol13_small = true;
|
62
|
private boolean includeVol13_large = true;
|
63
|
|
64
|
private boolean h2ForCheck = true;
|
65
|
|
66
|
|
67
|
//feature tree uuid
|
68
|
public static final UUID featureTreeUuid = UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
|
69
|
|
70
|
//classification
|
71
|
static final UUID classificationUuid = UUID.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
|
72
|
|
73
|
//check - import
|
74
|
static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
75
|
|
76
|
static boolean doPrintKeys = false;
|
77
|
|
78
|
//taxa
|
79
|
static final boolean doTaxa = true;
|
80
|
|
81
|
|
82
|
private boolean replaceStandardKeyTitles = false;
|
83
|
|
84
|
private IIoObserver observer = new LoggingIoObserver();
|
85
|
private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
|
86
|
|
87
|
|
88
|
private void doImport(ICdmDataSource cdmDestination){
|
89
|
observerList.add(observer);
|
90
|
if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
|
91
|
check = CHECK.CHECK_ONLY;
|
92
|
}
|
93
|
|
94
|
//make Source
|
95
|
URI source = fmSource13_small;
|
96
|
MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
|
97
|
markupConfig.setClassificationUuid(classificationUuid);
|
98
|
markupConfig.setDoTaxa(doTaxa);
|
99
|
markupConfig.setCheck(check);
|
100
|
markupConfig.setDoPrintKeys(doPrintKeys);
|
101
|
markupConfig.setDbSchemaValidation(hbm2dll);
|
102
|
markupConfig.setObservers(observerList);
|
103
|
markupConfig.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
|
104
|
|
105
|
|
106
|
markupConfig.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
|
107
|
|
108
|
CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>();
|
109
|
|
110
|
//Vol13_2
|
111
|
if (includeVol13_large){
|
112
|
System.out.println("\nStart import from ("+ fmSource13_large.toString() + ") ...");
|
113
|
source = fmSource13_large;
|
114
|
markupConfig.setSource(source);
|
115
|
myImport.invoke(markupConfig);
|
116
|
System.out.println("End import from ("+ fmSource13_large.toString() + ")...");
|
117
|
}
|
118
|
|
119
|
//Vol13_1
|
120
|
if (includeVol13_small){
|
121
|
System.out.println("\nStart import from ("+ fmSource13_small.toString() + ") ...");
|
122
|
source = fmSource13_small;
|
123
|
markupConfig.setSource(source);
|
124
|
myImport.invoke(markupConfig);
|
125
|
System.out.println("End import from ("+ fmSource13_small.toString() + ")...");
|
126
|
}
|
127
|
|
128
|
|
129
|
// makeGeoService();
|
130
|
|
131
|
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
132
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
133
|
|
134
|
//check keys
|
135
|
if (doPrintKeys){
|
136
|
TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
137
|
List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
|
138
|
for(PolytomousKey key : keys){
|
139
|
key.print(System.out);
|
140
|
System.out.println();
|
141
|
}
|
142
|
myImport.getCdmAppController().commitTransaction(tx);
|
143
|
}
|
144
|
|
145
|
}
|
146
|
|
147
|
private Reference getSourceReference(String string) {
|
148
|
Reference result = ReferenceFactory.newGeneric();
|
149
|
result.setTitleCache(string);
|
150
|
return result;
|
151
|
}
|
152
|
|
153
|
private FeatureTree makeFeatureNode(ITermService service){
|
154
|
FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
|
155
|
|
156
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
157
|
result.setTitleCache("Flora Malesiana Presentation Feature Tree");
|
158
|
FeatureNode root = result.getRoot();
|
159
|
FeatureNode newNode;
|
160
|
|
161
|
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
162
|
root.addChild(newNode);
|
163
|
|
164
|
addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
|
165
|
|
166
|
addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
|
167
|
newNode = FeatureNode.NewInstance(Feature.ANATOMY());
|
168
|
addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
|
169
|
|
170
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
|
171
|
addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
|
172
|
|
173
|
newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
|
174
|
|
175
|
|
176
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
177
|
root.addChild(newNode);
|
178
|
|
179
|
newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
|
180
|
root.addChild(newNode);
|
181
|
addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
|
182
|
|
183
|
newNode = FeatureNode.NewInstance(Feature.USES());
|
184
|
root.addChild(newNode);
|
185
|
|
186
|
addFeataureNodesByStringList(chomosomesList, root, transformer, service);
|
187
|
|
188
|
newNode = FeatureNode.NewInstance(Feature.CITATION());
|
189
|
root.addChild(newNode);
|
190
|
|
191
|
return result;
|
192
|
}
|
193
|
|
194
|
private static String [] chomosomesList = new String[]{
|
195
|
"Chromosomes",
|
196
|
};
|
197
|
|
198
|
|
199
|
private static String [] habitatEcologyList = new String[]{
|
200
|
"Habitat",
|
201
|
"Habitat & Ecology"
|
202
|
};
|
203
|
|
204
|
|
205
|
private static String [] generellDescriptionsUpToAnatomyList = new String[]{
|
206
|
"Fossils",
|
207
|
"Morphology and anatomy",
|
208
|
"Morphology",
|
209
|
"Vegetative morphology and anatomy",
|
210
|
};
|
211
|
|
212
|
|
213
|
private static String [] anatomySubfeatureList = new String[]{
|
214
|
"Leaf anatomy",
|
215
|
"Wood anatomy"
|
216
|
};
|
217
|
|
218
|
private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
|
219
|
"Flower morphology",
|
220
|
"Palynology",
|
221
|
"Pollination",
|
222
|
"Pollen morphology",
|
223
|
"embryology",
|
224
|
"cytology",
|
225
|
"Life cycle",
|
226
|
"Fruits and embryology",
|
227
|
"Dispersal",
|
228
|
"Chromosome numbers",
|
229
|
"Phytochemistry and Chemotaxonomy",
|
230
|
};
|
231
|
|
232
|
|
233
|
private static String [] phytoChemoSubFeaturesList = new String[]{
|
234
|
"Alkaloids",
|
235
|
"Iridoid glucosides",
|
236
|
"Leaf phenolics",
|
237
|
"Storage products of seeds",
|
238
|
"Aluminium",
|
239
|
"Chemotaxonomy",
|
240
|
};
|
241
|
|
242
|
|
243
|
private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
|
244
|
"Phytochemistry",
|
245
|
"Taxonomy",
|
246
|
"history",
|
247
|
"cultivation",
|
248
|
"Notes"
|
249
|
};
|
250
|
|
251
|
|
252
|
private static String [] descriptionFeatureList = new String[]{
|
253
|
"lifeform",
|
254
|
"Bark",
|
255
|
//new
|
256
|
"wood",
|
257
|
"Indumentum",
|
258
|
"endophytic body",
|
259
|
"flowering buds",
|
260
|
"Branchlets",
|
261
|
"Branches",
|
262
|
"Branch",
|
263
|
"Flowering branchlets",
|
264
|
"Trees",
|
265
|
"Twigs",
|
266
|
"stem",
|
267
|
"Stems",
|
268
|
"stem leaves",
|
269
|
"Leaves",
|
270
|
"flower-bearing stems",
|
271
|
"Petiole",
|
272
|
"Petiolules",
|
273
|
"Leaflets",
|
274
|
"Thyrsus",
|
275
|
"Thyrses",
|
276
|
"Inflorescences",
|
277
|
"Inflorescence",
|
278
|
"Young inflorescences",
|
279
|
"Male inflorescences",
|
280
|
"Female inflorescences",
|
281
|
"Bracts",
|
282
|
"Pedicels",
|
283
|
"flowering buds",
|
284
|
"scales",
|
285
|
"Buds",
|
286
|
"Flowers",
|
287
|
"Flower",
|
288
|
"Flowering",
|
289
|
"Stigma",
|
290
|
"perianth",
|
291
|
"Sepals",
|
292
|
"Sepal",
|
293
|
"Outer Sepals",
|
294
|
"Axillary",
|
295
|
"cymes",
|
296
|
"Calyx",
|
297
|
"Petal",
|
298
|
"Petals",
|
299
|
"perigone",
|
300
|
"perigone lobes",
|
301
|
"perigone tube",
|
302
|
"Disc",
|
303
|
"corolla",
|
304
|
"Stamens",
|
305
|
"Staminodes",
|
306
|
"Ovary",
|
307
|
"Anthers",
|
308
|
"anther",
|
309
|
"Pistil",
|
310
|
"Pistillode",
|
311
|
"Ovules",
|
312
|
"androecium",
|
313
|
"gynoecium",
|
314
|
"Filaments",
|
315
|
"Style",
|
316
|
"annulus",
|
317
|
"female flowers",
|
318
|
"Male flowers",
|
319
|
"Female",
|
320
|
"Infructescences", //order not consistent (sometimes before "Flowers")
|
321
|
"Fruit",
|
322
|
"Fruits",
|
323
|
"fruiting axes",
|
324
|
"drupes",
|
325
|
"Arillode",
|
326
|
"seed",
|
327
|
"Seeds",
|
328
|
"Seedling",
|
329
|
"flower tube",
|
330
|
"nutlets",
|
331
|
"pollen",
|
332
|
"secondary xylem",
|
333
|
"chromosome number",
|
334
|
|
335
|
"figure",
|
336
|
"fig",
|
337
|
"figs",
|
338
|
|
339
|
|
340
|
|
341
|
};
|
342
|
|
343
|
public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
|
344
|
FeatureNode lastChild = null;
|
345
|
try {
|
346
|
for (String featureString : featureStringList){
|
347
|
UUID featureUuid;
|
348
|
featureUuid = transformer.getFeatureUuid(featureString);
|
349
|
Feature feature = (Feature)termService.find(featureUuid);
|
350
|
if (feature != null){
|
351
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
352
|
root.addChild(child);
|
353
|
}
|
354
|
}
|
355
|
|
356
|
} catch (UndefinedTransformerMethodException e) {
|
357
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
358
|
}
|
359
|
return lastChild;
|
360
|
}
|
361
|
|
362
|
|
363
|
|
364
|
/**
|
365
|
* @param args
|
366
|
*/
|
367
|
public static void main(String[] args) {
|
368
|
FloraMalesianaVol13Activator me = new FloraMalesianaVol13Activator();
|
369
|
me.doImport(cdmDestination);
|
370
|
}
|
371
|
|
372
|
}
|