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.util.List;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.springframework.transaction.TransactionStatus;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
|
19
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
20
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
21
|
import eu.etaxonomy.cdm.common.URI;
|
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.CdmImportBase.TermMatchMode;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
28
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
29
|
import eu.etaxonomy.cdm.io.eflora.EfloraImportConfigurator;
|
30
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeImportConfigurator;
|
31
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeTransformer;
|
32
|
import eu.etaxonomy.cdm.io.specimen.excel.in.SpecimenCdmExcelImportConfigurator;
|
33
|
import eu.etaxonomy.cdm.model.agent.Team;
|
34
|
import eu.etaxonomy.cdm.model.common.Language;
|
35
|
import eu.etaxonomy.cdm.model.description.Feature;
|
36
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
37
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
38
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
39
|
import eu.etaxonomy.cdm.model.location.NamedAreaType;
|
40
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
41
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
42
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
43
|
import eu.etaxonomy.cdm.model.term.OrderedTermVocabulary;
|
44
|
import eu.etaxonomy.cdm.model.term.TermNode;
|
45
|
import eu.etaxonomy.cdm.model.term.TermTree;
|
46
|
import eu.etaxonomy.cdm.model.term.TermType;
|
47
|
|
48
|
/**
|
49
|
* @author a.mueller
|
50
|
* @since 20.06.2008
|
51
|
*/
|
52
|
public class CentralAfricaEricaceaeActivator {
|
53
|
private static final Logger logger = Logger.getLogger(CentralAfricaEricaceaeActivator.class);
|
54
|
|
55
|
//database validation status (create, update, validate ...)
|
56
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
|
57
|
static final URI source = EfloraSources.ericacea_local();
|
58
|
|
59
|
static final URI specimenSource = EfloraSources.vittaria_specimen_pesiimport3();
|
60
|
|
61
|
|
62
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_local();
|
63
|
|
64
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview();
|
65
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
|
66
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
67
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
68
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
69
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_campanulaceae_production();
|
70
|
|
71
|
//feature tree uuid
|
72
|
public static final UUID featureTreeUuid = UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7");
|
73
|
|
74
|
public static UUID defaultLanguageUuid = Language.uuidFrench;
|
75
|
|
76
|
//classification
|
77
|
static final UUID classificationUuid = UUID.fromString("10e5efcc-6e13-4abc-ad42-e0b46e50cbe7");
|
78
|
|
79
|
NomenclaturalCode nc = NomenclaturalCode.ICNAFP;
|
80
|
|
81
|
//check - import
|
82
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
83
|
|
84
|
static boolean doPrintKeys = false;
|
85
|
|
86
|
//taxa
|
87
|
private final boolean includeEricaceae = false;
|
88
|
static final boolean doTaxa = false;
|
89
|
static final boolean doDeduplicate = false;
|
90
|
|
91
|
|
92
|
private final boolean doNewNamedAreas = false;
|
93
|
private final boolean doFeatureTree = false;
|
94
|
|
95
|
private final boolean doSpecimen = true;
|
96
|
private final TermMatchMode specimenAreaMatchMode = TermMatchMode.UUID_ABBREVLABEL;
|
97
|
|
98
|
|
99
|
private void doImport(ICdmDataSource cdmDestination){
|
100
|
|
101
|
// CdmUpdater su = CdmUpdater.NewInstance();
|
102
|
// IProgressMonitor monitor = DefaultProgressMonitor.NewInstance();
|
103
|
//
|
104
|
// try {
|
105
|
// su.updateToCurrentVersion(cdmDestination, monitor);
|
106
|
// } catch (Exception e) {
|
107
|
// e.printStackTrace();
|
108
|
// }
|
109
|
// if (true){
|
110
|
// return;
|
111
|
// }
|
112
|
|
113
|
//make Source
|
114
|
CentralAfricaEricaceaeImportConfigurator config= CentralAfricaEricaceaeImportConfigurator.NewInstance(source, cdmDestination);
|
115
|
config.setClassificationUuid(classificationUuid);
|
116
|
config.setDoTaxa(doTaxa);
|
117
|
config.setCheck(check);
|
118
|
config.setDefaultLanguageUuid(defaultLanguageUuid);
|
119
|
config.setDoPrintKeys(doPrintKeys);
|
120
|
config.setDbSchemaValidation(hbm2dll);
|
121
|
config.setNomenclaturalCode(nc);
|
122
|
|
123
|
CdmDefaultImport<EfloraImportConfigurator> myImport = new CdmDefaultImport<EfloraImportConfigurator>();
|
124
|
|
125
|
|
126
|
//Ericaceae
|
127
|
if (includeEricaceae){
|
128
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
129
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
130
|
myImport.invoke(config);
|
131
|
System.out.println("End import from ("+ source.toString() + ")...");
|
132
|
}
|
133
|
|
134
|
if (doFeatureTree){
|
135
|
TermTree<Feature> tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
136
|
myImport.getCdmAppController().getTermTreeService().saveOrUpdate(tree);
|
137
|
}
|
138
|
|
139
|
//check keys
|
140
|
if (doPrintKeys){
|
141
|
TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
142
|
List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
|
143
|
for(PolytomousKey key : keys){
|
144
|
key.print(System.out);
|
145
|
System.out.println();
|
146
|
}
|
147
|
myImport.getCdmAppController().commitTransaction(tx);
|
148
|
}
|
149
|
|
150
|
//deduplicate
|
151
|
if (doDeduplicate){
|
152
|
ICdmRepository app = myImport.getCdmAppController();
|
153
|
if (app == null){
|
154
|
app = CdmApplicationController.NewInstance(cdmDestination, hbm2dll, false);
|
155
|
}
|
156
|
app.getAgentService().updateCaches(Team.class, null, null, null);
|
157
|
return;
|
158
|
// int count = app.getAgentService().deduplicate(Person.class, null, null);
|
159
|
//
|
160
|
// logger.warn("Deduplicated " + count + " persons.");
|
161
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
162
|
//// logger.warn("Deduplicated " + count + " teams.");
|
163
|
// count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
164
|
// logger.warn("Deduplicated " + count + " references.");
|
165
|
}
|
166
|
|
167
|
if(doNewNamedAreas){
|
168
|
newNamedAreas(myImport);
|
169
|
}
|
170
|
|
171
|
if (doSpecimen){
|
172
|
logger.warn("Start specimen import");
|
173
|
ICdmRepository app = myImport.getCdmAppController();
|
174
|
SpecimenCdmExcelImportConfigurator specimenConfig= SpecimenCdmExcelImportConfigurator.NewInstance(specimenSource, cdmDestination);
|
175
|
specimenConfig.setCdmAppController(app);
|
176
|
specimenConfig.setAreaMatchMode(specimenAreaMatchMode);
|
177
|
specimenConfig.setNomenclaturalCode(nc);
|
178
|
|
179
|
config.setDbSchemaValidation(DbSchemaValidation.VALIDATE);
|
180
|
specimenConfig.setSourceReference(getSourceReference(specimenConfig.getSourceReferenceTitle()));
|
181
|
|
182
|
CdmDefaultImport<SpecimenCdmExcelImportConfigurator> specimenImport = new CdmDefaultImport<SpecimenCdmExcelImportConfigurator>();
|
183
|
specimenImport.setCdmAppController(app);
|
184
|
specimenImport.invoke(specimenConfig);
|
185
|
|
186
|
}
|
187
|
return;
|
188
|
|
189
|
|
190
|
|
191
|
}
|
192
|
|
193
|
private void newNamedAreas(CdmDefaultImport<EfloraImportConfigurator> myImport) {
|
194
|
ICdmRepository app = myImport.getCdmAppController();
|
195
|
if (app == null){
|
196
|
app = CdmApplicationController.NewInstance(cdmDestination, hbm2dll, false);
|
197
|
}
|
198
|
TransactionStatus tx = app.startTransaction();
|
199
|
|
200
|
OrderedTermVocabulary<NamedArea> areaVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea, "Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions", null);
|
201
|
app.getVocabularyService().save(areaVoc);
|
202
|
|
203
|
NamedAreaLevel level = NamedAreaLevel.NewInstance("Phytogeographic Regions of Central Africa", "Phytogeographic Regions of Central Africa", "FdAC regions");
|
204
|
ITermService termService = app.getTermService();
|
205
|
|
206
|
termService.save(level);
|
207
|
|
208
|
NamedArea area = NamedArea.NewInstance("C\u00F4tier", "C\u00F4tier", "I");
|
209
|
area.setLevel(level);
|
210
|
area.setType(NamedAreaType.NATURAL_AREA());
|
211
|
areaVoc.addTerm(area);
|
212
|
termService.save(area);
|
213
|
|
214
|
|
215
|
area = NamedArea.NewInstance("Mayumbe", "Mayumbe", "II");
|
216
|
area.setLevel(level);
|
217
|
area.setType(NamedAreaType.NATURAL_AREA());
|
218
|
areaVoc.addTerm(area);
|
219
|
termService.save(area);
|
220
|
|
221
|
area = NamedArea.NewInstance("Bas-Congo", "Bas-Congo", "III");
|
222
|
area.setLevel(level);
|
223
|
area.setType(NamedAreaType.NATURAL_AREA());
|
224
|
areaVoc.addTerm(area);
|
225
|
termService.save(area);
|
226
|
|
227
|
area = NamedArea.NewInstance("Kasai", "Kasai", "IV");
|
228
|
area.setLevel(level);
|
229
|
area.setType(NamedAreaType.NATURAL_AREA());
|
230
|
areaVoc.addTerm(area);
|
231
|
termService.save(area);
|
232
|
|
233
|
area = NamedArea.NewInstance("Bas-Katanga", "Bas-Katanga", "V");
|
234
|
area.setLevel(level);
|
235
|
area.setType(NamedAreaType.NATURAL_AREA());
|
236
|
areaVoc.addTerm(area);
|
237
|
termService.save(area);
|
238
|
|
239
|
area = NamedArea.NewInstance("Forestier Central", "Forestier Central", "VI");
|
240
|
area.setLevel(level);
|
241
|
area.setType(NamedAreaType.NATURAL_AREA());
|
242
|
areaVoc.addTerm(area);
|
243
|
termService.save(area);
|
244
|
|
245
|
area = NamedArea.NewInstance("Ubangi-Uele", "Ubangi-Uele", "VII");
|
246
|
area.setLevel(level);
|
247
|
area.setType(NamedAreaType.NATURAL_AREA());
|
248
|
areaVoc.addTerm(area);
|
249
|
termService.save(area);
|
250
|
|
251
|
area = NamedArea.NewInstance("Lac Albert", "Lac Albert", "VIII");
|
252
|
area.setLevel(level);
|
253
|
area.setType(NamedAreaType.NATURAL_AREA());
|
254
|
areaVoc.addTerm(area);
|
255
|
termService.save(area);
|
256
|
|
257
|
area = NamedArea.NewInstance("Lacs \u00C9douard et Kivu", "Lacs \u00C9douard et Kivu", "IX");
|
258
|
area.setLevel(level);
|
259
|
area.setType(NamedAreaType.NATURAL_AREA());
|
260
|
areaVoc.addTerm(area);
|
261
|
termService.save(area);
|
262
|
|
263
|
area = NamedArea.NewInstance("Rwanda-Burundi", "Rwanda-Burundi", "X");
|
264
|
area.setLevel(level);
|
265
|
area.setType(NamedAreaType.NATURAL_AREA());
|
266
|
areaVoc.addTerm(area);
|
267
|
termService.save(area);
|
268
|
|
269
|
area = NamedArea.NewInstance("Haut-Katanga", "Haut-Katanga", "XI");
|
270
|
area.setLevel(level);
|
271
|
area.setType(NamedAreaType.NATURAL_AREA());
|
272
|
areaVoc.addTerm(area);
|
273
|
termService.save(area);
|
274
|
|
275
|
app.getVocabularyService().save(areaVoc);
|
276
|
|
277
|
app.commitTransaction(tx);
|
278
|
|
279
|
}
|
280
|
|
281
|
private Reference getSourceReference(String string) {
|
282
|
Reference result = ReferenceFactory.newGeneric();
|
283
|
result.setTitleCache(string, true);
|
284
|
return result;
|
285
|
}
|
286
|
|
287
|
private TermTree<Feature> makeFeatureNode(ITermService service){
|
288
|
CentralAfricaEricaceaeTransformer transformer = new CentralAfricaEricaceaeTransformer();
|
289
|
|
290
|
TermTree<Feature> result = TermTree.NewFeatureInstance(featureTreeUuid);
|
291
|
result.setTitleCache("Central Africa Ericaceae Feature Tree", true);
|
292
|
TermNode<Feature> root = result.getRoot();
|
293
|
|
294
|
TermNode<Feature> newNode = root.addChild(Feature.DESCRIPTION());
|
295
|
|
296
|
addFeatureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
|
297
|
|
298
|
addFeatureNodesByStringList(generellDescriptionsList, root, transformer, service);
|
299
|
|
300
|
newNode = root.addChild(Feature.DISTRIBUTION());
|
301
|
|
302
|
newNode = root.addChild(Feature.ECOLOGY());
|
303
|
addFeatureNodesByStringList(habitatEcologyList, root, transformer, service);
|
304
|
|
305
|
newNode = root.addChild(Feature.USES());
|
306
|
|
307
|
addFeatureNodesByStringList(chomosomesList, root, transformer, service);
|
308
|
|
309
|
newNode = root.addChild(Feature.COMMON_NAME());
|
310
|
|
311
|
newNode = root.addChild(Feature.CITATION());
|
312
|
|
313
|
return result;
|
314
|
}
|
315
|
|
316
|
private static String [] chomosomesList = new String[]{
|
317
|
"Chromosomes",
|
318
|
};
|
319
|
|
320
|
|
321
|
private static String [] habitatEcologyList = new String[]{
|
322
|
"Habitat",
|
323
|
"Habitat & Ecology"
|
324
|
};
|
325
|
|
326
|
|
327
|
private static String [] generellDescriptionsList = new String[]{
|
328
|
"Fossils",
|
329
|
"Morphology and anatomy",
|
330
|
"Morphology",
|
331
|
"Vegetative morphology and anatomy",
|
332
|
"Flower morphology",
|
333
|
"Palynology",
|
334
|
"Pollination",
|
335
|
"Pollen morphology",
|
336
|
"Life cycle",
|
337
|
"Fruits and embryology",
|
338
|
"Dispersal",
|
339
|
"Wood anatomy",
|
340
|
"Leaf anatomy",
|
341
|
"Chromosome numbers",
|
342
|
"Phytochemistry and Chemotaxonomy",
|
343
|
"Phytochemistry",
|
344
|
"Taxonomy",
|
345
|
};
|
346
|
|
347
|
private static String [] descriptionFeatureList = new String[]{
|
348
|
"lifeform",
|
349
|
"Bark",
|
350
|
"Indumentum",
|
351
|
"endophytic body",
|
352
|
"flowering buds",
|
353
|
"Branchlets",
|
354
|
"Branches",
|
355
|
"Branch",
|
356
|
"Flowering branchlets",
|
357
|
"Trees",
|
358
|
"Twigs",
|
359
|
"stem",
|
360
|
"Stems",
|
361
|
"stem leaves",
|
362
|
"Leaves",
|
363
|
"flower-bearing stems",
|
364
|
"Petiole",
|
365
|
"Petiolules",
|
366
|
"Leaflets",
|
367
|
"Thyrsus",
|
368
|
"Thyrses",
|
369
|
"Inflorescences",
|
370
|
"Inflorescence",
|
371
|
"Young inflorescences",
|
372
|
"Bracts",
|
373
|
"Pedicels",
|
374
|
"flowering buds",
|
375
|
"scales",
|
376
|
"Buds",
|
377
|
"Flowers",
|
378
|
"Flower",
|
379
|
"Flowering",
|
380
|
"Stigma",
|
381
|
"perianth",
|
382
|
"Sepals",
|
383
|
"Sepal",
|
384
|
"Outer Sepals",
|
385
|
"Axillary",
|
386
|
"cymes",
|
387
|
"Calyx",
|
388
|
"Petal",
|
389
|
"Petals",
|
390
|
"perigone tube",
|
391
|
"Disc",
|
392
|
"corolla",
|
393
|
"Stamens",
|
394
|
"Staminodes",
|
395
|
"Ovary",
|
396
|
"Anthers",
|
397
|
"anther",
|
398
|
"Pistil",
|
399
|
"Pistillode",
|
400
|
"Ovules",
|
401
|
"androecium",
|
402
|
"gynoecium",
|
403
|
"Filaments",
|
404
|
"Style",
|
405
|
"annulus",
|
406
|
"female flowers",
|
407
|
"Male flowers",
|
408
|
"Female",
|
409
|
"Infructescences", //order not consistent (sometimes before "Flowers")
|
410
|
"Fruit",
|
411
|
"Fruits",
|
412
|
"fruiting axes",
|
413
|
"drupes",
|
414
|
"Arillode",
|
415
|
"seed",
|
416
|
"Seeds",
|
417
|
"Seedling",
|
418
|
"flower tube",
|
419
|
"nutlets",
|
420
|
"pollen",
|
421
|
"secondary xylem",
|
422
|
"chromosome number",
|
423
|
|
424
|
"figure",
|
425
|
"fig",
|
426
|
"figs",
|
427
|
|
428
|
|
429
|
|
430
|
|
431
|
};
|
432
|
|
433
|
public void addFeatureNodesByStringList(String[] featureStringList, TermNode<Feature> root, IInputTransformer transformer, ITermService termService){
|
434
|
try {
|
435
|
for (String featureString : featureStringList){
|
436
|
UUID featureUuid;
|
437
|
featureUuid = transformer.getFeatureUuid(featureString);
|
438
|
Feature feature = (Feature)termService.find(featureUuid);
|
439
|
if (feature != null){
|
440
|
TermNode<Feature> child = root.addChild(feature);
|
441
|
}
|
442
|
}
|
443
|
} catch (UndefinedTransformerMethodException e) {
|
444
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
445
|
}
|
446
|
}
|
447
|
|
448
|
|
449
|
|
450
|
/**
|
451
|
* @param args
|
452
|
*/
|
453
|
public static void main(String[] args) {
|
454
|
CentralAfricaEricaceaeActivator me = new CentralAfricaEricaceaeActivator();
|
455
|
me.doImport(cdmDestination);
|
456
|
}
|
457
|
|
458
|
}
|