Project

General

Profile

Download (16.4 KB) Statistics
| Branch: | Revision:
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
package eu.etaxonomy.cdm.app.eflora;
10

    
11
import java.util.List;
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15
import org.springframework.transaction.TransactionStatus;
16

    
17
import eu.etaxonomy.cdm.api.service.ITermService;
18
import eu.etaxonomy.cdm.common.URI;
19
import eu.etaxonomy.cdm.database.DbSchemaValidation;
20
import eu.etaxonomy.cdm.database.ICdmDataSource;
21
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
22
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
23
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
24
import eu.etaxonomy.cdm.io.markup.MarkupTransformer;
25
import eu.etaxonomy.cdm.model.description.Feature;
26
import eu.etaxonomy.cdm.model.description.PolytomousKey;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.model.term.TermNode;
30
import eu.etaxonomy.cdm.model.term.TermTree;
31

    
32
/**
33
 * @author a.mueller
34
 * @since 20.06.2008
35
 */
36
public class FloreGabonActivator extends EfloraActivatorBase {
37
	private static final Logger logger = Logger.getLogger(FloreGabonActivator.class);
38

    
39
	//database validation status (create, update, validate ...)
40
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41
//	static final URI source = EfloraSources.fdg_sample();
42
	static final URI fdg1 = EfloraSources.fdg_1();
43
	static final URI fdg2 = EfloraSources.fdg_2();
44
	static final URI fdg3 = EfloraSources.fdg_3();
45
	static final URI fdg4 = EfloraSources.fdg_4();
46
	static final URI fdg5 = EfloraSources.fdg_5();
47
	static final URI fdg5bis = EfloraSources.fdg_5bis();
48
	static final URI fdg6 = EfloraSources.fdg_6();
49
	static final URI fdg7 = EfloraSources.fdg_7();
50
	static final URI fdg8 = EfloraSources.fdg_8();
51
	static final URI fdg9 = EfloraSources.fdg_9();
52
	static final URI fdg10 = EfloraSources.fdg_10();
53
	static final URI fdg11 = EfloraSources.fdg_11();
54
	static final URI fdg12_17 = EfloraSources.fdg_12_17();
55
	static final URI fdg13 = EfloraSources.fdg_13();
56
	static final URI fdg14 = EfloraSources.fdg_14();
57
	static final URI fdg15 = EfloraSources.fdg_15();
58
	static final URI fdg16 = EfloraSources.fdg_16();
59
	static final URI fdg18 = EfloraSources.fdg_18();
60
	static final URI fdg19 = EfloraSources.fdg_19();
61
	static final URI fdg20 = EfloraSources.fdg_20();
62
	static final URI fdg21 = EfloraSources.fdg_21();
63
	static final URI fdg22 = EfloraSources.fdg_22();
64
	static final URI fdg23 = EfloraSources.fdg_23();
65
	static final URI fdg24 = EfloraSources.fdg_24();
66
	static final URI fdg25 = EfloraSources.fdg_25();
67
	static final URI fdg26 = EfloraSources.fdg_26();
68
	static final URI fdg27 = EfloraSources.fdg_27();
69
	static final URI fdg28 = EfloraSources.fdg_28();
70
	static final URI fdg29 = EfloraSources.fdg_29();
71
	static final URI fdg30 = EfloraSources.fdg_30();
72
	static final URI fdg31 = EfloraSources.fdg_31();
73
	static final URI fdg32 = EfloraSources.fdg_32();
74
	static final URI fdg33 = EfloraSources.fdg_33();
75
	static final URI fdg34 = EfloraSources.fdg_34();
76
	static final URI fdg35 = EfloraSources.fdg_35();
77

    
78
//	static final URI fdg36 = EfloraSources.fdg_36();
79
//	static final URI fdg37 = EfloraSources.fdg_37();
80
	static final URI fdg36_37 = EfloraSources.fdg_36_37();
81

    
82
	static final URI fdg38 = EfloraSources.fdg_38();
83
	static final URI fdg39 = EfloraSources.fdg_39();
84
	static final URI fdg40 = EfloraSources.fdg_40();
85
	static final URI fdg41 = EfloraSources.fdg_41();
86
	static final URI fdg42 = EfloraSources.fdg_42();
87
	static final URI fdg43 = EfloraSources.fdg_43();
88
	static final URI fdg44 = EfloraSources.fdg_44();
89
	static final URI fdg45 = EfloraSources.fdg_45();
90

    
91
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_preview();
92
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_production();
93
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
94
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
95

    
96
	//feature tree uuid
97
	public static final UUID featureTreeUuid = UUID.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
98
	private static final String featureTreeTitle = "Flore Gabon Presentation Feature Tree";
99

    
100
	//classification
101
	static final UUID classificationUuid = UUID.fromString("2f892452-ff49-48cf-834f-52ca29600719");
102
	static final String classificationTitle = "Flore du Gabon";
103

    
104
	//check - import
105
	private boolean h2ForCheck = false;
106
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
107

    
108
	static boolean doPrintKeys = false;
109

    
110
	private boolean replaceStandardKeyTitles = true;
111

    
112
	//taxa
113
	static final boolean doTaxa = true;
114

    
115
	static final boolean reuseState = true;
116

    
117
	//if true, use inverse include information
118
	private boolean inverseInclude = true;
119

    
120
	private boolean includeFdg1 = true;
121
	private boolean includeFdg2 = true;
122
	private boolean includeFdg3 = true;
123
	private boolean includeFdg4 = true;
124
	private boolean includeFdg5 = true;
125
	private boolean includeFdg5bis = true;
126
	private boolean includeFdg6 = true;
127
	private boolean includeFdg7 = true;
128
	private boolean includeFdg8 = true;
129
	private boolean includeFdg9 = true;
130
	private boolean includeFdg10 = true;
131
	private boolean includeFdg11 = true;
132
	private boolean includeFdg12_17 = true;
133
	private boolean includeFdg13 = true;
134
	private boolean includeFdg14 = true;
135
	private boolean includeFdg15 = true;
136
	private boolean includeFdg16 = true;
137
	private boolean includeFdg18 = true;
138
	private boolean includeFdg19 = true;
139
	private boolean includeFdg20 = true;
140
	private boolean includeFdg21 = true;
141
	private boolean includeFdg22 = true;
142

    
143
	private boolean includeFdg23 = false;
144
	private boolean includeFdg24 = true;
145
	private boolean includeFdg25 = true;
146
	private boolean includeFdg26 = true;
147

    
148
	private boolean includeFdg27 = true;
149
	private boolean includeFdg28 = true;
150

    
151
	private boolean includeFdg29 = true;
152

    
153
	private boolean includeFdg30 = true;
154

    
155
	private boolean includeFdg31 = true;
156
	private boolean includeFdg32 = true;
157
	private boolean includeFdg33 = true;
158

    
159
	private boolean includeFdg34 = true;
160
	private boolean includeFdg35 = true;
161

    
162
//	private boolean includeFdg36 = true;
163
//	private boolean includeFdg37 = true;
164
	private boolean includeFdg36_37 = true;
165
	private boolean includeFdg38 = true;
166
	private boolean includeFdg39 = true;
167
	private boolean includeFdg40 = true;
168
	private boolean includeFdg41 = true;
169
	private boolean includeFdg42 = true;
170
	private boolean includeFdg43 = true;
171
	private boolean includeFdg44 = true;
172
	private boolean includeFdg45 = true;
173

    
174
// **************** NO CHANGE **********************************************/
175

    
176
	private void doImport(ICdmDataSource cdmDestination){
177
		super.doImport(fdg1, cdmDestination,check, h2ForCheck);
178

    
179
		//make config
180
		config.setClassificationUuid(classificationUuid);
181
		config.setDoTaxa(doTaxa);
182
		config.setDoPrintKeys(doPrintKeys);
183
		config.setDbSchemaValidation(hbm2dll);
184
		config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
185
		config.setSourceReference(getSourceReference("Flore du Gabon"));
186
		config.setClassificationName(classificationTitle);
187
		config.setReuseExistingState(reuseState);
188

    
189
		//Vol1
190
		executeVolume( fdg1, includeFdg1 ^ inverseInclude);
191

    
192
		//Vol2
193
		executeVolume(fdg2, includeFdg2 ^ inverseInclude);
194

    
195
		//Vol3
196
		executeVolume(fdg3, includeFdg3 ^ inverseInclude);
197

    
198
		//Vol4
199
		executeVolume(fdg4, includeFdg4 ^ inverseInclude);
200

    
201
		//Vol5
202
		executeVolume(fdg5, includeFdg5 ^ inverseInclude);
203

    
204
		//Vol5bis
205
		executeVolume(fdg5bis, includeFdg5bis ^ inverseInclude);
206

    
207
		//Vol6
208
		executeVolume(fdg6, includeFdg6 ^ inverseInclude);
209

    
210
		//Vol7
211
		executeVolume(fdg7, includeFdg7 ^ inverseInclude);
212

    
213
		//Vol8
214
		executeVolume(fdg8, includeFdg8 ^ inverseInclude);
215

    
216
		//Vol9
217
		executeVolume(fdg9, includeFdg9 ^ inverseInclude);
218

    
219
		//Vol10
220
		executeVolume(fdg10, includeFdg10 ^ inverseInclude);
221

    
222
		//Vol11
223
		executeVolume(fdg11, includeFdg11 ^ inverseInclude);
224

    
225
		//Vol12
226
		executeVolume(fdg12_17, includeFdg12_17 ^ inverseInclude);
227

    
228
		//Vol13
229
		executeVolume(fdg13, includeFdg13 ^ inverseInclude);
230

    
231
		//Vol14
232
		executeVolume(fdg14, includeFdg14 ^ inverseInclude);
233

    
234
		//Vol15
235
		executeVolume(fdg15, includeFdg15 ^ inverseInclude);
236

    
237
		//Vol16
238
		executeVolume(fdg16, includeFdg16 ^ inverseInclude);
239

    
240
		//Vol18
241
		executeVolume(fdg18, includeFdg18 ^ inverseInclude);
242

    
243
		//Vol19
244
		executeVolume(fdg19, includeFdg19 ^ inverseInclude);
245

    
246
		//Vol20
247
		executeVolume(fdg20, includeFdg20 ^ inverseInclude);
248

    
249
		//Vol21
250
		executeVolume(fdg21, includeFdg21 ^ inverseInclude);
251
		//Vol22
252
		executeVolume(fdg22, includeFdg22 ^ inverseInclude);
253
		//Vol23
254
		executeVolume(fdg23, includeFdg23 ^ inverseInclude);
255
		//Vol24
256
		executeVolume(fdg24, includeFdg24 ^ inverseInclude);
257
		//Vol25
258
		executeVolume(fdg25, includeFdg25 ^ inverseInclude);
259
		//Vol26
260
		executeVolume(fdg26, includeFdg26 ^ inverseInclude);
261
		//Vol27
262
		executeVolume(fdg27, includeFdg27 ^ inverseInclude);
263
		//Vol28
264
		executeVolume(fdg28, includeFdg28 ^ inverseInclude);
265
		//Vol29
266
		executeVolume(fdg29, includeFdg29 ^ inverseInclude);
267
		//Vol30
268
		executeVolume(fdg30, includeFdg30 ^ inverseInclude);
269
		//Vol31
270
		executeVolume(fdg31, includeFdg31 ^ inverseInclude);
271
		//Vol32
272
		executeVolume(fdg32, includeFdg32 ^ inverseInclude);
273
		//Vol33
274
		executeVolume(fdg33, includeFdg33 ^ inverseInclude);
275
		//Vol34
276
		executeVolume(fdg34, includeFdg34 ^ inverseInclude);
277
		//Vol35
278
		executeVolume(fdg35, includeFdg35 ^ inverseInclude);
279

    
280
//		//Vol36
281
//		executeVolume(fdg36, includeFdg36 ^ inverseInclude);
282
//
283
//		//Vol37
284
//		executeVolume(fdg37, includeFdg37 ^ inverseInclude);
285

    
286
		//Vol 36_37
287
		executeVolume(fdg36_37, includeFdg36_37 ^ inverseInclude);
288

    
289
		//Vol38
290
		executeVolume(fdg38, includeFdg38 ^ inverseInclude);
291

    
292
		//Vol39
293
		executeVolume(fdg39, includeFdg39 ^ inverseInclude);
294

    
295
		//Vol40
296
		executeVolume(fdg40, includeFdg40 ^ inverseInclude);
297

    
298
		//Vol41
299
		executeVolume(fdg41, includeFdg41 ^ inverseInclude);
300

    
301
		//Vol42
302
		executeVolume(fdg42, includeFdg42 ^ inverseInclude);
303

    
304
		//Vol43
305
		executeVolume(fdg43, includeFdg43 ^ inverseInclude);
306

    
307
		//Vol44
308
		executeVolume(fdg44, includeFdg44 ^ inverseInclude);
309

    
310
		//Vol45
311
		executeVolume(fdg45, includeFdg45 ^ inverseInclude);
312

    
313
		TermTree<Feature> tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
314
		myImport.getCdmAppController().getTermTreeService().saveOrUpdate(tree);
315

    
316
		makeAutomatedFeatureTree(myImport.getCdmAppController(), config.getState(),
317
				featureTreeUuid, featureTreeTitle);
318

    
319
		//check keys
320
		if (doPrintKeys){
321
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
322
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
323
			for(PolytomousKey key : keys){
324
				key.print(System.out);
325
				System.out.println();
326
			}
327
			myImport.getCdmAppController().commitTransaction(tx);
328
		}
329

    
330
	}
331

    
332
	private Reference getSourceReference(String string) {
333
		Reference result = ReferenceFactory.newGeneric();
334
		result.setTitleCache(string, true);
335
		return result;
336
	}
337

    
338
	private TermTree<Feature> makeFeatureNode(ITermService service){
339
		MarkupTransformer transformer = new MarkupTransformer();
340

    
341
		TermTree<Feature> result = TermTree.NewFeatureInstance();
342
		result.setTitleCache("Old feature tree", true);
343
		TermNode<Feature> root = result.getRoot();
344

    
345
		TermNode<Feature> newNode = root.addChild(Feature.DESCRIPTION());
346

    
347
		addFeatureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
348

    
349
		addFeatureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
350
		newNode = root.addChild(Feature.ANATOMY());  //not sure if this is correct, but it looked like the node was orphaned before
351
        addFeatureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
352

    
353
		newNode = addFeatureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
354
		addFeatureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
355

    
356
		newNode = addFeatureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
357

    
358
		newNode = root.addChild(Feature.COMMON_NAME());
359

    
360
		newNode = root.addChild(Feature.DISTRIBUTION());
361

    
362
		newNode = root.addChild(Feature.ECOLOGY());
363
		addFeatureNodesByStringList(habitatEcologyList, root, transformer, service);
364

    
365
		newNode = root.addChild(Feature.USES());
366

    
367
		addFeatureNodesByStringList(chomosomesList, root, transformer, service);
368

    
369
		newNode = root.addChild(Feature.CITATION());
370

    
371
		return result;
372
	}
373

    
374
	private static String [] chomosomesList = new String[]{
375
		"Chromosomes",
376
	};
377

    
378

    
379
	private static String [] habitatEcologyList = new String[]{
380
		"Habitat",
381
		"Habitat & Ecology"
382
	};
383

    
384

    
385
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
386
		"Fossils",
387
		"Morphology and anatomy",
388
		"Morphology",
389
		"Vegetative morphology and anatomy",
390
	};
391

    
392

    
393
	private static String [] anatomySubfeatureList = new String[]{
394
		"Leaf anatomy",
395
		"Wood anatomy"
396
	};
397

    
398
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
399
		"Flower morphology",
400
		"Palynology",
401
		"Pollination",
402
		"Pollen morphology",
403
		"embryology",
404
		"cytology",
405
		"Life cycle",
406
		"Fruits and embryology",
407
		"Dispersal",
408
		"Chromosome numbers",
409
		"Phytochemistry and Chemotaxonomy",
410
	};
411

    
412

    
413
	private static String [] phytoChemoSubFeaturesList = new String[]{
414
		"Alkaloids",
415
		"Iridoid glucosides",
416
		"Leaf phenolics",
417
		"Storage products of seeds",
418
		"Aluminium",
419
		"Chemotaxonomy",
420
	};
421

    
422

    
423
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
424
		"Phytochemistry",
425
		"Taxonomy",
426
		"history",
427
		"cultivation",
428
		"Notes"
429
	};
430

    
431

    
432
	private static String [] descriptionFeatureList = new String[]{
433
		"lifeform",
434
		"Juvenile parts",
435
		"Bark",
436
		//new
437
		"wood",
438
		"Indumentum",
439
		"endophytic body",
440
		"apical buds",
441
		"flowering buds",
442
		"Branchlets",
443
		"Branches",
444
		"Branch",
445
		"Flowering branchlets",
446
		"Trees",
447
		"Twigs",
448
		"stem",
449
		"Stems",
450
		"stem leaves",
451
		"Leaves",
452
		"extraxylary sclerenchyma",
453
		"flower-bearing stems",
454
		"Petiole",
455
		"Petiolules",
456
		"Leaflets",
457
		"Lamina",
458
		"Veins",
459
		"Lateral veins",
460
		"secondary veins",
461
		"Intersecondary veins",
462
		"veinlets",
463
		"Thyrsus",
464
		"Thyrses",
465
		"Inflorescences",
466
		"Inflorescence",
467
		"Young inflorescences",
468
		"Male inflorescences",
469
		"Female inflorescences",
470
		"rachises",
471
		"Bracts",
472
		"Pedicels",
473
		"flowering buds",
474
		"scales",
475
		"Buds",
476
		"Flowers",
477
		"Flower",
478
		"Flowering",
479
		"Stigma",
480
		"perianth",
481
		"Sepals",
482
		"Sepal",
483
		"Outer Sepals",
484
		"Axillary",
485
		"cymes",
486
		"Calyx",
487
		"Androgynophore",
488
		"Petal",
489
		"Petals",
490
		"perigone",
491
		"perigone lobes",
492
		"perigone tube",
493
		"Disc",
494
		"corolla",
495
		"Stamens",
496
		"Staminodes",
497
		"Ovary",
498
		"Anthers",
499
		"anther",
500
		"Pistil",
501
		"Pistillode",
502
		"Ovules",
503
		"androecium",
504
		"gynoecium",
505
		"Filaments",
506
		"Style",
507
		"annulus",
508
		"female flowers",
509
		"Male flowers",
510
		"Androphore",
511
		"Female",
512
		"Infructescences",    //order not consistent (sometimes before "Flowers")
513
		"Fruit",
514
		"Fruits",
515
		"fruiting axes",
516
		"drupes",
517
		"Arillode",
518
		"seed",
519
		"Seeds",
520
		"Seedling",
521
		"flower tube",
522
		"nutlets",
523
		"pollen",
524
		"secondary xylem",
525
		"chromosome number",
526

    
527
		"figure",
528
		"fig",
529
		"figs",
530
	};
531

    
532
	public TermNode<Feature> addFeatureNodesByStringList(String[] featureStringList,
533
	             TermNode<Feature> root, IInputTransformer transformer, ITermService termService){
534

    
535
	    TermNode<Feature> lastChild = null;
536
		try {
537
			for (String featureString : featureStringList){
538
				UUID featureUuid;
539
				featureUuid = transformer.getFeatureUuid(featureString);
540
				Feature feature = (Feature)termService.find(featureUuid);
541
				if (feature != null){
542
					root.addChild(feature);
543
				}
544
			}
545

    
546
		} catch (UndefinedTransformerMethodException e) {
547
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
548
		}
549
		return lastChild;
550
	}
551

    
552
	public static void main(String[] args) {
553
		FloreGabonActivator me = new FloreGabonActivator();
554
		me.doImport(cdmDestination);
555
	}
556
}
(13-13/15)