Project

General

Profile

Download (11.6 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.app.common.CdmDestinations;
23
import eu.etaxonomy.cdm.database.DbSchemaValidation;
24
import eu.etaxonomy.cdm.database.ICdmDataSource;
25
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
26
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
27
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
28
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
29
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
30
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
31
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer;
32
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
33
import eu.etaxonomy.cdm.model.description.Feature;
34
import eu.etaxonomy.cdm.model.description.FeatureNode;
35
import eu.etaxonomy.cdm.model.description.FeatureTree;
36
import eu.etaxonomy.cdm.model.description.PolytomousKey;
37
import eu.etaxonomy.cdm.model.reference.Reference;
38
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
39

    
40
/**
41
 * @author a.mueller
42
 * @created 20.06.2008
43
 * @version 1.0
44
 */
45
public class FloraMalesianaVol13Activator {
46
	private static final Logger logger = Logger.getLogger(FloraMalesianaVol13Activator.class);
47
	
48
	//database validation status (create, update, validate ...)
49
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
50
	static final URI fmSource13_small = EfloraSources.fm_13_small_families();
51
	static final URI fmSource13_large = EfloraSources.fm_13_large_families();
52
	static final URI fmSource12 = EfloraSources.fm_12();
53
	static final URI fmSource2_2 = EfloraSources.fm_2_2();
54
	
55
	
56
	
57
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
58
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
59
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
60
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
61
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
62
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
63
	
64
	private boolean includeVol13_small = false;
65
	private boolean includeVol13_large = false;
66
	private boolean includeVol12 = true;
67
	private boolean includeVol2_2 = true;
68
	
69
	private boolean h2ForCheck = true;
70
	
71

    
72
	//feature tree uuid
73
	public static final UUID featureTreeUuid = UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
74
	
75
	//classification
76
	static final UUID classificationUuid = UUID.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
77
	
78
	//check - import
79
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
80
	
81
	static boolean doPrintKeys = false;
82
	
83
	//taxa
84
	static final boolean doTaxa = true;
85

    
86
	
87
	private boolean replaceStandardKeyTitles = false;
88

    
89
	private IIoObserver observer = new LoggingIoObserver();
90
	private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
91
	
92
	
93
	private void doImport(ICdmDataSource cdmDestination){
94
		observerList.add(observer);
95
		if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
96
			check = CHECK.CHECK_ONLY;
97
		}
98
		
99
		//make Source
100
		URI source = fmSource13_small;
101
		MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
102
		markupConfig.setClassificationUuid(classificationUuid);
103
		markupConfig.setDoTaxa(doTaxa);
104
		markupConfig.setCheck(check);
105
		markupConfig.setDoPrintKeys(doPrintKeys);
106
		markupConfig.setDbSchemaValidation(hbm2dll);
107
		markupConfig.setObservers(observerList);
108
		markupConfig.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
109
		
110
		
111
		markupConfig.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
112
		
113
		CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>(); 
114
		
115
		//Vol13_2
116
		if (includeVol13_large){
117
			System.out.println("\nStart import from ("+ fmSource13_large.toString() + ") ...");
118
			source = fmSource13_large;
119
			markupConfig.setSource(source);
120
			myImport.invoke(markupConfig);
121
			System.out.println("End import from ("+ fmSource13_large.toString() + ")...");
122
		}
123
		
124
		//Vol13_1
125
		if (includeVol13_small){
126
			System.out.println("\nStart import from ("+ fmSource13_small.toString() + ") ...");
127
			source = fmSource13_small;
128
			markupConfig.setSource(source);
129
			myImport.invoke(markupConfig);
130
			System.out.println("End import from ("+ fmSource13_small.toString() + ")...");
131
		}
132

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

    
175
	private FeatureTree makeFeatureNode(ITermService service){
176
		FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
177
		
178
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
179
		result.setTitleCache("Flora Malesiana Presentation Feature Tree");
180
		FeatureNode root = result.getRoot();
181
		FeatureNode newNode;
182
		
183
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
184
		root.addChild(newNode);
185
		
186
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
187

    
188
		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
189
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
190
		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
191
		
192
		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
193
		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
194

    
195
		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
196
		
197
		
198
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
199
		root.addChild(newNode);
200

    
201
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
202
		root.addChild(newNode);
203
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
204
		
205
		newNode = FeatureNode.NewInstance(Feature.USES());
206
		root.addChild(newNode);
207
		
208
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
209

    
210
		newNode = FeatureNode.NewInstance(Feature.CITATION());
211
		root.addChild(newNode);
212
		
213
		return result;
214
	}
215
	
216
	private static String [] chomosomesList = new String[]{
217
		"Chromosomes", 
218
	};
219

    
220
	
221
	private static String [] habitatEcologyList = new String[]{
222
		"Habitat",
223
		"Habitat & Ecology"
224
	};
225
	
226
	
227
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
228
		"Fossils",
229
		"Morphology and anatomy",
230
		"Morphology", 
231
		"Vegetative morphology and anatomy",
232
	};
233

    
234
	
235
	private static String [] anatomySubfeatureList = new String[]{
236
		"Leaf anatomy",
237
		"Wood anatomy"
238
	};
239

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

    
265
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
266
		"Phytochemistry",
267
		"Taxonomy",
268
		"history",
269
		"cultivation",
270
		"Notes"
271
	};
272

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

    
361

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

    
385

    
386
	/**
387
	 * @param args
388
	 */
389
	public static void main(String[] args) {
390
		FloraMalesianaVol13Activator me = new FloraMalesianaVol13Activator();
391
		me.doImport(cdmDestination);
392
	}
393
	
394
}
(6-6/6)