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