Project

General

Profile

Download (18.1 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

    
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.markup.MarkupImportConfigurator;
31
import eu.etaxonomy.cdm.io.markup.MarkupTransformer;
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
 */
43
public class FloreGabonActivator extends EfloraActivatorBase {
44
	private static final Logger logger = Logger.getLogger(FloreGabonActivator.class);
45
	
46
	//database validation status (create, update, validate ...)
47
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
48
//	static final URI source = EfloraSources.fdg_sample();
49
	static final URI fdg1 = EfloraSources.fdg_1();
50
	static final URI fdg2 = EfloraSources.fdg_2();
51
	static final URI fdg3 = EfloraSources.fdg_3();
52
	static final URI fdg4 = EfloraSources.fdg_4();
53
	static final URI fdg5 = EfloraSources.fdg_5();
54
	static final URI fdg5bis = EfloraSources.fdg_5bis();
55
	static final URI fdg6 = EfloraSources.fdg_6();
56
	static final URI fdg7 = EfloraSources.fdg_7();
57
	static final URI fdg8 = EfloraSources.fdg_8();
58
	static final URI fdg9 = EfloraSources.fdg_9();
59
	static final URI fdg10 = EfloraSources.fdg_10();
60
	static final URI fdg11 = EfloraSources.fdg_11();
61
	static final URI fdg12_17 = EfloraSources.fdg_12_17();
62
	static final URI fdg13 = EfloraSources.fdg_13();
63
	static final URI fdg14 = EfloraSources.fdg_14();
64
	static final URI fdg15 = EfloraSources.fdg_15();
65
	static final URI fdg16 = EfloraSources.fdg_16();
66
	static final URI fdg18 = EfloraSources.fdg_18();
67
	static final URI fdg19 = EfloraSources.fdg_19();
68
	static final URI fdg20 = EfloraSources.fdg_20();
69
	static final URI fdg21 = EfloraSources.fdg_21();
70
	static final URI fdg22 = EfloraSources.fdg_22();
71
	static final URI fdg23 = EfloraSources.fdg_23();
72
	static final URI fdg24 = EfloraSources.fdg_24();
73
	static final URI fdg25 = EfloraSources.fdg_25();
74
	static final URI fdg26 = EfloraSources.fdg_26();
75
	static final URI fdg27 = EfloraSources.fdg_27();
76
	static final URI fdg28 = EfloraSources.fdg_28();
77
	static final URI fdg29 = EfloraSources.fdg_29();
78
	static final URI fdg30 = EfloraSources.fdg_30();
79
	static final URI fdg31 = EfloraSources.fdg_31();
80
	static final URI fdg32 = EfloraSources.fdg_32();
81
	static final URI fdg33 = EfloraSources.fdg_33();
82
	static final URI fdg34 = EfloraSources.fdg_34();
83
	static final URI fdg35 = EfloraSources.fdg_35();
84
	
85
//	static final URI fdg36 = EfloraSources.fdg_36();
86
//	static final URI fdg37 = EfloraSources.fdg_37();
87
	static final URI fdg36_37 = EfloraSources.fdg_36_37();
88
	
89
	static final URI fdg38 = EfloraSources.fdg_38();
90
	static final URI fdg39 = EfloraSources.fdg_39();
91
	static final URI fdg40 = EfloraSources.fdg_40();
92
	static final URI fdg41 = EfloraSources.fdg_41();
93
	static final URI fdg42 = EfloraSources.fdg_42();
94
	static final URI fdg43 = EfloraSources.fdg_43();
95
	static final URI fdg44 = EfloraSources.fdg_44();
96
	static final URI fdg45 = EfloraSources.fdg_45();
97
	
98
	
99
	
100
	
101
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_preview();
102
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_production();
103
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
104
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
105
	
106

    
107
	//feature tree uuid
108
	public static final UUID featureTreeUuid = UUID.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
109
	private static final String featureTreeTitle = "Flore Gabon Presentation Feature Tree";
110
	
111
	//classification
112
	static final UUID classificationUuid = UUID.fromString("2f892452-ff49-48cf-834f-52ca29600719");
113
	static final String classificationTitle = "Flore du Gabon";
114
	
115
	//check - import
116
	private boolean h2ForCheck = false;
117
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
118
	
119
	static boolean doPrintKeys = false;
120

    
121
	
122
	private boolean replaceStandardKeyTitles = true;
123

    
124
	//taxa
125
	static final boolean doTaxa = true;
126
	
127
	static final boolean reuseState = true;
128
	
129
	
130
	//if true, use inverse include information
131
	private boolean inverseInclude = true;
132
	
133
	private boolean includeFdg1 = true;
134
	private boolean includeFdg2 = true;
135
	private boolean includeFdg3 = true;
136
	private boolean includeFdg4 = true;
137
	private boolean includeFdg5 = true;
138
	private boolean includeFdg5bis = true;
139
	private boolean includeFdg6 = true;
140
	private boolean includeFdg7 = true;
141
	private boolean includeFdg8 = true;
142
	private boolean includeFdg9 = true;
143
	private boolean includeFdg10 = true;
144
	private boolean includeFdg11 = true;
145
	private boolean includeFdg12_17 = true;
146
	private boolean includeFdg13 = true;
147
	private boolean includeFdg14 = true;
148
	private boolean includeFdg15 = true;
149
	private boolean includeFdg16 = true;
150
	private boolean includeFdg18 = true;
151
	private boolean includeFdg19 = true;
152
	private boolean includeFdg20 = true;
153
	private boolean includeFdg21 = true;
154
	private boolean includeFdg22 = true;
155
	
156
	private boolean includeFdg23 = false;
157
	private boolean includeFdg24 = true;
158
	private boolean includeFdg25 = true;
159
	private boolean includeFdg26 = true;
160
	
161
	private boolean includeFdg27 = true;
162
	private boolean includeFdg28 = true;
163
	
164
	private boolean includeFdg29 = true;
165
	
166
	private boolean includeFdg30 = true;
167
	
168
	private boolean includeFdg31 = true;
169
	private boolean includeFdg32 = true;
170
	private boolean includeFdg33 = true;
171
	
172
	private boolean includeFdg34 = true;
173
	private boolean includeFdg35 = true;
174
	
175
//	private boolean includeFdg36 = true;
176
//	private boolean includeFdg37 = true;
177
	private boolean includeFdg36_37 = true;
178
	private boolean includeFdg38 = true;
179
	private boolean includeFdg39 = true;
180
	private boolean includeFdg40 = true;
181
	private boolean includeFdg41 = true;
182
	private boolean includeFdg42 = true;
183
	private boolean includeFdg43 = true;
184
	private boolean includeFdg44 = true;
185
	private boolean includeFdg45 = true;
186
	
187
// **************** NO CHANGE **********************************************/
188
	
189
	private IIoObserver observer = new LoggingIoObserver();
190
	private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
191
	
192
	private MarkupImportConfigurator config;
193
	private CdmDefaultImport<MarkupImportConfigurator> myImport;
194
	
195
	private void doImport(ICdmDataSource cdmDestination){
196
		observerList.add(observer);
197
		if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
198
			check = CHECK.CHECK_ONLY;
199
		}
200
		
201
		//make config
202
		URI source = fdg1;
203
		config = MarkupImportConfigurator.NewInstance(source, cdmDestination);
204
		config.setClassificationUuid(classificationUuid);
205
		config.setDoTaxa(doTaxa);
206
		config.setCheck(check);
207
		config.setDoPrintKeys(doPrintKeys);
208
		config.setDbSchemaValidation(hbm2dll);
209
		config.setObservers(observerList);
210
		config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
211
		config.setSourceReference(getSourceReference("Flore du Gabon"));
212
		config.setClassificationName(classificationTitle);
213
		config.setReuseExistingState(reuseState);
214
		
215
		myImport = new CdmDefaultImport<MarkupImportConfigurator>(); 
216
		
217
		//Vol1
218
		executeVolume( fdg1, includeFdg1 ^ inverseInclude);
219
		
220
		//Vol2
221
		executeVolume(fdg2, includeFdg2 ^ inverseInclude);
222
		
223
		//Vol3
224
		executeVolume(fdg3, includeFdg3 ^ inverseInclude);
225

    
226
		//Vol4
227
		executeVolume(fdg4, includeFdg4 ^ inverseInclude);
228

    
229
		//Vol5
230
		executeVolume(fdg5, includeFdg5 ^ inverseInclude);
231
		
232
		//Vol5bis
233
		executeVolume(fdg5bis, includeFdg5bis ^ inverseInclude);
234
		
235
		//Vol6
236
		executeVolume(fdg6, includeFdg6 ^ inverseInclude);
237
		
238
		//Vol7
239
		executeVolume(fdg7, includeFdg7 ^ inverseInclude);
240
		
241
		//Vol8
242
		executeVolume(fdg8, includeFdg8 ^ inverseInclude);
243
		
244
		//Vol9
245
		executeVolume(fdg9, includeFdg9 ^ inverseInclude);
246
		
247
		//Vol10
248
		executeVolume(fdg10, includeFdg10 ^ inverseInclude);
249

    
250
		//Vol11
251
		executeVolume(fdg11, includeFdg11 ^ inverseInclude);
252
		
253
		//Vol12
254
		executeVolume(fdg12_17, includeFdg12_17 ^ inverseInclude);
255
		
256
		//Vol13
257
		executeVolume(fdg13, includeFdg13 ^ inverseInclude);
258
		
259
		//Vol14
260
		executeVolume(fdg14, includeFdg14 ^ inverseInclude);
261
		
262
		//Vol15
263
		executeVolume(fdg15, includeFdg15 ^ inverseInclude);
264
		
265
		//Vol16
266
		executeVolume(fdg16, includeFdg16 ^ inverseInclude);
267
		
268
		//Vol18
269
		executeVolume(fdg18, includeFdg18 ^ inverseInclude);
270
		
271
		//Vol19
272
		executeVolume(fdg19, includeFdg19 ^ inverseInclude);
273
		
274
		//Vol20
275
		executeVolume(fdg20, includeFdg20 ^ inverseInclude);
276

    
277
		//Vol21
278
		executeVolume(fdg21, includeFdg21 ^ inverseInclude);
279
		//Vol22
280
		executeVolume(fdg22, includeFdg22 ^ inverseInclude);
281
		//Vol23
282
		executeVolume(fdg23, includeFdg23 ^ inverseInclude);
283
		//Vol24
284
		executeVolume(fdg24, includeFdg24 ^ inverseInclude);
285
		//Vol25
286
		executeVolume(fdg25, includeFdg25 ^ inverseInclude);
287
		//Vol26
288
		executeVolume(fdg26, includeFdg26 ^ inverseInclude);				
289
		//Vol27
290
		executeVolume(fdg27, includeFdg27 ^ inverseInclude);
291
		//Vol28
292
		executeVolume(fdg28, includeFdg28 ^ inverseInclude);
293
		//Vol29
294
		executeVolume(fdg29, includeFdg29 ^ inverseInclude);
295
		//Vol30
296
		executeVolume(fdg30, includeFdg30 ^ inverseInclude);
297
		//Vol31
298
		executeVolume(fdg31, includeFdg31 ^ inverseInclude);
299
		//Vol32
300
		executeVolume(fdg32, includeFdg32 ^ inverseInclude);
301
		//Vol33
302
		executeVolume(fdg33, includeFdg33 ^ inverseInclude);
303
		//Vol34
304
		executeVolume(fdg34, includeFdg34 ^ inverseInclude);
305
		//Vol35
306
		executeVolume(fdg35, includeFdg35 ^ inverseInclude);
307
				
308
//		//Vol36
309
//		executeVolume(fdg36, includeFdg36 ^ inverseInclude);
310
//				
311
//		//Vol37
312
//		executeVolume(fdg37, includeFdg37 ^ inverseInclude);
313
		
314
		//Vol 36_37
315
		executeVolume(fdg36_37, includeFdg36_37 ^ inverseInclude);
316

    
317
		//Vol38
318
		executeVolume(fdg38, includeFdg38 ^ inverseInclude);
319

    
320
		//Vol39
321
		executeVolume(fdg39, includeFdg39 ^ inverseInclude);
322

    
323
		//Vol40
324
		executeVolume(fdg40, includeFdg40 ^ inverseInclude);
325

    
326
		//Vol41
327
		executeVolume(fdg41, includeFdg41 ^ inverseInclude);
328

    
329
		//Vol42
330
		executeVolume(fdg42, includeFdg42 ^ inverseInclude);
331

    
332
		//Vol43
333
		executeVolume(fdg43, includeFdg43 ^ inverseInclude);
334

    
335
		//Vol44
336
		executeVolume(fdg44, includeFdg44 ^ inverseInclude);
337

    
338
		//Vol45
339
		executeVolume(fdg45, includeFdg45 ^ inverseInclude);
340

    
341
		
342
		
343
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
344
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
345
		
346
		makeAutomatedFeatureTree(myImport.getCdmAppController(), config.getState(),
347
				featureTreeUuid, featureTreeTitle);
348

    
349
		
350
		//check keys
351
		if (doPrintKeys){
352
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
353
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
354
			for(PolytomousKey key : keys){
355
				key.print(System.out);
356
				System.out.println();
357
			}
358
			myImport.getCdmAppController().commitTransaction(tx);
359
		}
360
		
361
	}
362

    
363
	/**
364
	 * @param markupConfig
365
	 * @param myImport
366
	 */
367
	private void executeVolume(URI source, boolean include) {
368
		if (include){
369
			System.out.println("\nStart import from ("+ source.toString() + ") ...");
370
			config.setSource(source);
371
			myImport.invoke(config);
372
			System.out.println("End import from ("+ source.toString() + ")...");
373
		}
374
	}
375
	
376
	private Reference<?> getSourceReference(String string) {
377
		Reference<?> result = ReferenceFactory.newGeneric();
378
		result.setTitleCache(string, true);
379
		return result;
380
	}
381
	
382
	
383

    
384

    
385
	private FeatureTree makeFeatureNode(ITermService service){
386
		MarkupTransformer transformer = new MarkupTransformer();
387
		
388
		FeatureTree result = FeatureTree.NewInstance();
389
		result.setTitleCache("Old feature tree", true);
390
		FeatureNode root = result.getRoot();
391
		FeatureNode newNode;
392
		
393
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
394
		root.addChild(newNode);
395
		
396
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
397

    
398
		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
399
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
400
		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
401
		
402
		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
403
		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
404

    
405
		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
406
		
407
		newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
408
		root.addChild(newNode);
409
		
410
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
411
		root.addChild(newNode);
412

    
413
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
414
		root.addChild(newNode);
415
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
416
		
417
		newNode = FeatureNode.NewInstance(Feature.USES());
418
		root.addChild(newNode);
419
		
420
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
421

    
422
		newNode = FeatureNode.NewInstance(Feature.CITATION());
423
		root.addChild(newNode);
424
		
425
		return result;
426
	}
427
	
428
	private static String [] chomosomesList = new String[]{
429
		"Chromosomes", 
430
	};
431

    
432
	
433
	private static String [] habitatEcologyList = new String[]{
434
		"Habitat",
435
		"Habitat & Ecology"
436
	};
437
	
438
	
439
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
440
		"Fossils",
441
		"Morphology and anatomy",
442
		"Morphology", 
443
		"Vegetative morphology and anatomy",
444
	};
445

    
446
	
447
	private static String [] anatomySubfeatureList = new String[]{
448
		"Leaf anatomy",
449
		"Wood anatomy"
450
	};
451

    
452
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
453
		"Flower morphology",
454
		"Palynology",  
455
		"Pollination",  
456
		"Pollen morphology",
457
		"embryology",
458
		"cytology",
459
		"Life cycle",
460
		"Fruits and embryology",
461
		"Dispersal",
462
		"Chromosome numbers", 
463
		"Phytochemistry and Chemotaxonomy",
464
	};
465
	
466
	
467
	private static String [] phytoChemoSubFeaturesList = new String[]{
468
		"Alkaloids",
469
		"Iridoid glucosides",
470
		"Leaf phenolics",
471
		"Storage products of seeds",
472
		"Aluminium",
473
		"Chemotaxonomy",
474
	};
475
	
476

    
477
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
478
		"Phytochemistry",
479
		"Taxonomy",
480
		"history",
481
		"cultivation",
482
		"Notes"
483
	};
484

    
485
	
486
	private static String [] descriptionFeatureList = new String[]{
487
		"lifeform", 
488
		"Juvenile parts",
489
		"Bark",
490
		//new
491
		"wood",
492
		"Indumentum",  
493
		"endophytic body",  
494
		"apical buds",
495
		"flowering buds",  
496
		"Branchlets",  
497
		"Branches",  
498
		"Branch",  
499
		"Flowering branchlets",
500
		"Trees",  
501
		"Twigs",  
502
		"stem",  
503
		"Stems",  
504
		"stem leaves", 
505
		"Leaves",
506
		"extraxylary sclerenchyma",
507
		"flower-bearing stems",  
508
		"Petiole",  
509
		"Petiolules",  
510
		"Leaflets", 
511
		"Lamina",
512
		"Veins",
513
		"Lateral veins",
514
		"secondary veins",
515
		"Intersecondary veins",
516
		"veinlets",
517
		"Thyrsus",  
518
		"Thyrses",  
519
		"Inflorescences",  
520
		"Inflorescence",
521
		"Young inflorescences", 
522
		"Male inflorescences", 
523
		"Female inflorescences", 
524
		"rachises",
525
		"Bracts",  
526
		"Pedicels",  
527
		"flowering buds",  
528
		"scales",  
529
		"Buds",  
530
		"Flowers",  
531
		"Flower",  
532
		"Flowering",
533
		"Stigma",  
534
		"perianth",  
535
		"Sepals",  
536
		"Sepal",  
537
		"Outer Sepals",  
538
		"Axillary",  
539
		"cymes",  
540
		"Calyx",  
541
		"Androgynophore",
542
		"Petal",  
543
		"Petals",
544
		"perigone",
545
		"perigone lobes",
546
		"perigone tube",
547
		"Disc",  
548
		"corolla",  
549
		"Stamens",  
550
		"Staminodes",  
551
		"Ovary",  
552
		"Anthers",
553
		"anther",  
554
		"Pistil",  
555
		"Pistillode",  
556
		"Ovules",  
557
		"androecium",  
558
		"gynoecium",  
559
		"Filaments",  		
560
		"Style",  
561
		"annulus",  
562
		"female flowers",  
563
		"Male flowers", 
564
		"Androphore",
565
		"Female",  
566
		"Infructescences",    //order not consistent (sometimes before "Flowers")  
567
		"Fruit",  
568
		"Fruits",  
569
		"fruiting axes",  
570
		"drupes",  
571
		"Arillode",  
572
		"seed",  
573
		"Seeds",  
574
		"Seedling",  
575
		"flower tube", 
576
		"nutlets",  
577
		"pollen",  
578
		"secondary xylem",  
579
		"chromosome number",  
580
	
581
		"figure",  
582
		"fig",  
583
		"figs",   
584

    
585

    
586
		
587
	};
588
	
589
	public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
590
		FeatureNode lastChild = null;
591
		try {
592
			for (String featureString : featureStringList){
593
				UUID featureUuid;
594
				featureUuid = transformer.getFeatureUuid(featureString);
595
				Feature feature = (Feature)termService.find(featureUuid);
596
				if (feature != null){
597
					FeatureNode child = FeatureNode.NewInstance(feature);
598
					root.addChild(child);	
599
				}
600
			}
601
			
602
		} catch (UndefinedTransformerMethodException e) {
603
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
604
		}
605
		return lastChild;
606
	}
607
	
608

    
609

    
610
	/**
611
	 * @param args
612
	 */
613
	public static void main(String[] args) {
614
		FloreGabonActivator me = new FloreGabonActivator();
615
		me.doImport(cdmDestination);
616
	}
617
}
(13-13/13)