Project

General

Profile

Download (11.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.eflora.floraMalesiana.FloraMalesianaTransformer;
31
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
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
 * @version 1.0
43
 */
44
public class FloreGabonActivator {
45
	private static final Logger logger = Logger.getLogger(FloreGabonActivator.class);
46
	
47
	//database validation status (create, update, validate ...)
48
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
49
//	static final URI source = EfloraSources.fdg_sample();
50
	static final URI fdg1 = EfloraSources.fdg_1();
51
	static final URI fdg2 = EfloraSources.fdg_2();
52
	static final URI fdg3 = EfloraSources.fdg_3();
53
	static final URI fdg4 = EfloraSources.fdg_4();
54
	
55
	
56
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_preview();
57
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flore_gabon_production();
58
//	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
59
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
60
	
61

    
62
	//feature tree uuid
63
	public static final UUID featureTreeUuid = UUID.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
64
	
65
	//classification
66
	static final UUID classificationUuid = UUID.fromString("2f892452-ff49-48cf-834f-52ca29600719");
67
	
68
	//check - import
69
	private boolean h2ForCheck = false;
70
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
71
	
72
	static boolean doPrintKeys = false;
73
	
74
	//taxa
75
	static final boolean doTaxa = true;
76
	
77
	private boolean includeFdg1 = true;
78
	private boolean includeFdg2 = true;
79
	private boolean includeFdg3 = true;
80
	private boolean includeFdg4 = true;
81
	
82
		
83
	private boolean replaceStandardKeyTitles = false;
84

    
85
	private IIoObserver observer = new LoggingIoObserver();
86
	private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
87
	
88
	
89
	private void doImport(ICdmDataSource cdmDestination){
90
		observerList.add(observer);
91
		if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
92
			check = CHECK.CHECK_ONLY;
93
		}
94
		
95
		//make config
96
		URI source = fdg1;
97
		MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
98
		markupConfig.setClassificationUuid(classificationUuid);
99
		markupConfig.setDoTaxa(doTaxa);
100
		markupConfig.setCheck(check);
101
		markupConfig.setDoPrintKeys(doPrintKeys);
102
		markupConfig.setDbSchemaValidation(hbm2dll);
103
		markupConfig.setObservers(observerList);
104
		markupConfig.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
105
		
106
		
107
		markupConfig.setSourceReference(getSourceReference("Flore du Gabon"));
108
		
109
		CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>(); 
110
		
111
		//Vol1
112
		if (includeFdg1){
113
			System.out.println("\nStart import from ("+ fdg1.toString() + ") ...");
114
			source = fdg1;
115
			markupConfig.setSource(source);
116
			myImport.invoke(markupConfig);
117
			System.out.println("End import from ("+ fdg1.toString() + ")...");
118
		}
119
		
120
		//Vol2
121
		if (includeFdg2){
122
			source = fdg2;
123
			System.out.println("\nStart import from ("+ source.toString() + ") ...");
124
			markupConfig.setSource(source);
125
			myImport.invoke(markupConfig);
126
			System.out.println("End import from ("+ source.toString() + ")...");
127
		}
128
		
129
		//Vol3
130
		if (includeFdg3){
131
			source = fdg3;
132
			System.out.println("\nStart import from ("+ source.toString() + ") ...");
133
			markupConfig.setSource(source);
134
			myImport.invoke(markupConfig);
135
			System.out.println("End import from ("+ source.toString() + ")...");
136
		}
137

    
138
		//Vol4
139
		if (includeFdg4){
140
			source = fdg4;
141
			System.out.println("\nStart import from ("+ source.toString() + ") ...");
142
			markupConfig.setSource(source);
143
			myImport.invoke(markupConfig);
144
			System.out.println("End import from ("+ source.toString() + ")...");
145
		}
146
		
147
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
148
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
149
		
150
		//check keys
151
		if (doPrintKeys){
152
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
153
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
154
			for(PolytomousKey key : keys){
155
				key.print(System.out);
156
				System.out.println();
157
			}
158
			myImport.getCdmAppController().commitTransaction(tx);
159
		}
160
		
161
	}
162
	
163
	private Reference<?> getSourceReference(String string) {
164
		Reference<?> result = ReferenceFactory.newGeneric();
165
		result.setTitleCache(string);
166
		return result;
167
	}
168

    
169
	private FeatureTree makeFeatureNode(ITermService service){
170
		FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
171
		
172
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
173
		result.setTitleCache("Flore Gabon Presentation Feature Tree");
174
		FeatureNode root = result.getRoot();
175
		FeatureNode newNode;
176
		
177
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
178
		root.addChild(newNode);
179
		
180
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
181

    
182
		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
183
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
184
		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
185
		
186
		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
187
		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
188

    
189
		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
190
		
191
		
192
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
193
		root.addChild(newNode);
194

    
195
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
196
		root.addChild(newNode);
197
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
198
		
199
		newNode = FeatureNode.NewInstance(Feature.USES());
200
		root.addChild(newNode);
201
		
202
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
203

    
204
		newNode = FeatureNode.NewInstance(Feature.CITATION());
205
		root.addChild(newNode);
206
		
207
		return result;
208
	}
209
	
210
	private static String [] chomosomesList = new String[]{
211
		"Chromosomes", 
212
	};
213

    
214
	
215
	private static String [] habitatEcologyList = new String[]{
216
		"Habitat",
217
		"Habitat & Ecology"
218
	};
219
	
220
	
221
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
222
		"Fossils",
223
		"Morphology and anatomy",
224
		"Morphology", 
225
		"Vegetative morphology and anatomy",
226
	};
227

    
228
	
229
	private static String [] anatomySubfeatureList = new String[]{
230
		"Leaf anatomy",
231
		"Wood anatomy"
232
	};
233

    
234
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
235
		"Flower morphology",
236
		"Palynology",  
237
		"Pollination",  
238
		"Pollen morphology",
239
		"embryology",
240
		"cytology",
241
		"Life cycle",
242
		"Fruits and embryology",
243
		"Dispersal",
244
		"Chromosome numbers", 
245
		"Phytochemistry and Chemotaxonomy",
246
	};
247
	
248
	
249
	private static String [] phytoChemoSubFeaturesList = new String[]{
250
		"Alkaloids",
251
		"Iridoid glucosides",
252
		"Leaf phenolics",
253
		"Storage products of seeds",
254
		"Aluminium",
255
		"Chemotaxonomy",
256
	};
257
	
258

    
259
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
260
		"Phytochemistry",
261
		"Taxonomy",
262
		"history",
263
		"cultivation",
264
		"Notes"
265
	};
266

    
267
	
268
	private static String [] descriptionFeatureList = new String[]{
269
		"lifeform", 
270
		"Bark",
271
		//new
272
		"wood",
273
		"Indumentum",  
274
		"endophytic body",  
275
		"flowering buds",  
276
		"Branchlets",  
277
		"Branches",  
278
		"Branch",  
279
		"Flowering branchlets",
280
		"Trees",  
281
		"Twigs",  
282
		"stem",  
283
		"Stems",  
284
		"stem leaves", 
285
		"Leaves",
286
		"flower-bearing stems",  
287
		"Petiole",  
288
		"Petiolules",  
289
		"Leaflets", 
290
		"Thyrsus",  
291
		"Thyrses",  
292
		"Inflorescences",  
293
		"Inflorescence",
294
		"Young inflorescences", 
295
		"Male inflorescences", 
296
		"Female inflorescences", 
297
		"Bracts",  
298
		"Pedicels",  
299
		"flowering buds",  
300
		"scales",  
301
		"Buds",  
302
		"Flowers",  
303
		"Flower",  
304
		"Flowering",
305
		"Stigma",  
306
		"perianth",  
307
		"Sepals",  
308
		"Sepal",  
309
		"Outer Sepals",  
310
		"Axillary",  
311
		"cymes",  
312
		"Calyx",  
313
		"Petal",  
314
		"Petals",
315
		"perigone",
316
		"perigone lobes",
317
		"perigone tube",
318
		"Disc",  
319
		"corolla",  
320
		"Stamens",  
321
		"Staminodes",  
322
		"Ovary",  
323
		"Anthers",
324
		"anther",  
325
		"Pistil",  
326
		"Pistillode",  
327
		"Ovules",  
328
		"androecium",  
329
		"gynoecium",  
330
		"Filaments",  		
331
		"Style",  
332
		"annulus",  
333
		"female flowers",  
334
		"Male flowers",  
335
		"Female",  
336
		"Infructescences",    //order not consistent (sometimes before "Flowers")  
337
		"Fruit",  
338
		"Fruits",  
339
		"fruiting axes",  
340
		"drupes",  
341
		"Arillode",  
342
		"seed",  
343
		"Seeds",  
344
		"Seedling",  
345
		"flower tube", 
346
		"nutlets",  
347
		"pollen",  
348
		"secondary xylem",  
349
		"chromosome number",  
350
	
351
		"figure",  
352
		"fig",  
353
		"figs",  
354

    
355

    
356
		
357
	};
358
	
359
	public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
360
		FeatureNode lastChild = null;
361
		try {
362
			for (String featureString : featureStringList){
363
				UUID featureUuid;
364
				featureUuid = transformer.getFeatureUuid(featureString);
365
				Feature feature = (Feature)termService.find(featureUuid);
366
				if (feature != null){
367
					FeatureNode child = FeatureNode.NewInstance(feature);
368
					root.addChild(child);	
369
				}
370
			}
371
			
372
		} catch (UndefinedTransformerMethodException e) {
373
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
374
		}
375
		return lastChild;
376
	}
377
	
378

    
379

    
380
	/**
381
	 * @param args
382
	 */
383
	public static void main(String[] args) {
384
		FloreGabonActivator me = new FloreGabonActivator();
385
		me.doImport(cdmDestination);
386
	}
387
}
(10-10/10)