Project

General

Profile

Download (12.3 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.List;
14
import java.util.UUID;
15

    
16
import org.apache.log4j.Logger;
17
import org.springframework.transaction.TransactionStatus;
18

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

    
33
/**
34
 * Activator for Flora of the Guianas imports.
35
 * This class is meant for advanced use and is therefore not documented.
36
 * @author a.mueller
37
 */
38
public class FloraGuianasActivator extends EfloraActivatorBase {
39
	private static final Logger logger = Logger.getLogger(FloraGuianasActivator.class);
40
	
41
	//database validation status (create, update, validate ...)
42
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
43
	static final URI fgu1 = EfloraSources.fgu_1();
44
	static final URI fotg22 = EfloraSources.fotg_22();
45
	static final URI fotg23 = EfloraSources.fotg_23();
46
	static final URI fotg24 = EfloraSources.fotg_24();
47
	static final URI fotg24_plus = EfloraSources.fotg_24plus();
48
	static final URI fotg25 = EfloraSources.fotg_25();
49
	static final URI fotg25_plus = EfloraSources.fotg_25plus();
50
	static final URI fotg26 = EfloraSources.fotg_26();
51
	static final URI fotg27 = EfloraSources.fotg_27();
52
	
53
	static final URI fotg29 = EfloraSources.fotg_29();
54
	static final URI fotg30 = EfloraSources.fotg_30();
55
	
56

    
57
	private boolean inverseInclude = false;
58
	
59
	private boolean includeFotg1 = false;
60
	private boolean includeFotg22 = false;
61
	private boolean includeFotg23 = false;
62
	private boolean includeFotg24 = false;
63
	private boolean includeFotg24_plus = false;
64
	private boolean includeFotg25 = false;
65
	private boolean includeFotg25_plus = false;
66
	private boolean includeFotg26 = false;
67
	private boolean includeFotg27 = false;
68

    
69
	private boolean includeFotg29 = false;
70
	private boolean includeFotg30 = true;
71
	
72
	
73
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_guianas_preview();
74
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_guianas_production();
75
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
76
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
77
	
78

    
79
	//feature tree uuid
80
	public static final UUID featureTreeUuid = UUID.fromString("2be99595-92fc-4f80-b9c4-b48d38505f5d");
81
	
82
	//classification
83
	static final UUID classificationUuid = UUID.fromString("5e3a1b07-2609-4597-bbda-7b02dfe8c2b3");
84
	
85
	private static final String SOURCE_REFERENCE_TITLE = "Flora of the Guianas";
86
	static final String classificationTitle = "Flora of the Guianas";
87
	
88
	private static final String FEATURE_TREE_TITLE = "Flora of the Guianas Feature Tree";
89

    
90
	//check - import
91
	private boolean h2ForCheck = true;
92
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
93
	
94
	static boolean doPrintKeys = false;
95
	
96
	//taxa
97
	static final boolean doTaxa = true;
98
	
99
	static final boolean reuseState = true;
100
	
101
	
102
		
103
	private boolean replaceStandardKeyTitles = true;
104
	
105
	private boolean useFotGCollectionTypeOnly = true;
106

    
107
// ****************** NO CHANGE *******************************************/	
108
	
109
	private void doImport(ICdmDataSource cdmDestination){
110
		super.doImport(fotg22, cdmDestination,check, h2ForCheck);
111
		
112
		
113
		//make config
114
		config.setClassificationUuid(classificationUuid);
115
		config.setDoTaxa(doTaxa);
116
		config.setDoPrintKeys(doPrintKeys);
117
		config.setDbSchemaValidation(hbm2dll);
118
		config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
119
		config.setSourceReference(getSourceReference(SOURCE_REFERENCE_TITLE));
120
		config.setClassificationName(classificationTitle);
121
		config.setReuseExistingState(reuseState);
122
		config.setUseFotGSpecimenTypeCollectionAndTypeOnly(useFotGCollectionTypeOnly);
123
		
124
//		URI uri = config.getSource();
125
//		try {
126
////			InputStream is = uri.toURL().openStream();
127
//			File file = new File(uri);
128
//			System.out.println(file.exists());
129
//			InputStream is = new FileInputStream(file);
130
//			System.out.println(is);
131
//		} catch (Exception e) {
132
//			e.printStackTrace();
133
//		}
134
		
135
		//Vol1-79
136
		executeVolume( fgu1, includeFotg1 ^ inverseInclude);
137
		//Vol22
138
		executeVolume(fotg22, includeFotg22 ^ inverseInclude);
139
		//Vol23
140
		executeVolume(fotg23, includeFotg23 ^ inverseInclude);
141
		//Vol24
142
		executeVolume(fotg24, includeFotg24 ^ inverseInclude);
143
		//Vol24+
144
		executeVolume(fotg24_plus, includeFotg24_plus ^ inverseInclude);
145
		//Vol25
146
		executeVolume(fotg25, includeFotg25 ^ inverseInclude);
147
		//Vol26
148
		executeVolume(fotg25_plus, includeFotg25_plus ^ inverseInclude);
149
		//Vol26
150
		executeVolume(fotg26, includeFotg26 ^ inverseInclude);				
151
		//Vol27
152
		executeVolume(fotg27, includeFotg27 ^ inverseInclude);
153

    
154
		//Vol29
155
		executeVolume(fotg29, includeFotg29 ^ inverseInclude);
156
		//Vol30
157
		executeVolume(fotg30, includeFotg30 ^ inverseInclude);
158
		
159
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
160
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
161
		
162
		//check keys
163
		if (doPrintKeys){
164
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
165
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
166
			for(PolytomousKey key : keys){
167
				key.print(System.out);
168
				System.out.println();
169
			}
170
			myImport.getCdmAppController().commitTransaction(tx);
171
		}
172
		
173
	}
174
	
175
	private Reference<?> getSourceReference(String string) {
176
		Reference<?> result = ReferenceFactory.newGeneric();
177
		result.setTitleCache(string);
178
		return result;
179
	}
180

    
181
	private FeatureTree makeFeatureNode(ITermService service){
182
		MarkupTransformer transformer = new MarkupTransformer();
183
		
184
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
185
		result.setTitleCache(FEATURE_TREE_TITLE, true);
186
		FeatureNode root = result.getRoot();
187
		FeatureNode newNode;
188
		
189
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
190
		root.addChild(newNode);
191
		
192
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
193

    
194
		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
195
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
196
		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
197
		
198
		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
199
		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
200

    
201
		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
202
		
203
		
204
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
205
		root.addChild(newNode);
206

    
207
		newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
208
		root.addChild(newNode);
209

    
210
		newNode = FeatureNode.NewInstance(Feature.PHENOLOGY());
211
		root.addChild(newNode);
212
		
213
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
214
		root.addChild(newNode);
215
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
216
		
217
		newNode = FeatureNode.NewInstance(Feature.USES());
218
		root.addChild(newNode);
219
		
220
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
221

    
222
		newNode = FeatureNode.NewInstance(Feature.CITATION());
223
		root.addChild(newNode);
224
		
225
		String sql = "\nSELECT feature.titleCache " +
226
				" FROM DescriptionElementBase deb INNER JOIN DefinedTermBase feature ON deb.feature_id = feature.id " + 
227
				" GROUP BY feature.id " + 
228
				" HAVING feature.id NOT IN (SELECT DISTINCT fn.feature_id " +
229
				" FROM FeatureNode fn " +
230
				" WHERE fn.feature_id IS NOT NULL) ";
231
		logger.warn("Check for missing features in feature tree: " + sql);
232
		
233
		return result;
234
	}
235
	
236
	private static String [] chomosomesList = new String[]{
237
		"Chromosomes", 
238
	};
239

    
240
	
241
	private static String [] habitatEcologyList = new String[]{
242
		"Habitat",
243
		"Habitat & Ecology"
244
	};
245
	
246
	
247
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
248
		"Fossils",
249
		"Morphology and anatomy",
250
		"Morphology", 
251
		"Vegetative morphology and anatomy",
252
	};
253

    
254
	
255
	private static String [] anatomySubfeatureList = new String[]{
256
		"Leaf anatomy",
257
		"Wood anatomy"
258
	};
259

    
260
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
261
		"Flower morphology",
262
		"Palynology",  
263
		"Pollination",  
264
		"Pollen morphology",
265
		"embryology",
266
		"cytology",
267
		"Life cycle",
268
		"Fruits and embryology",
269
		"Dispersal",
270
		"Chromosome numbers", 
271
		"Phytochemistry and Chemotaxonomy",
272
	};
273
	
274
	
275
	private static String [] phytoChemoSubFeaturesList = new String[]{
276
		"Alkaloids",
277
		"Iridoid glucosides",
278
		"Leaf phenolics",
279
		"Storage products of seeds",
280
		"Aluminium",
281
		"Chemotaxonomy",
282
	};
283
	
284

    
285
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
286
		"Phytochemistry",
287
		"Taxonomy",
288
		"history",
289
		"cultivation",
290
		"Notes"
291
	};
292

    
293
	
294
	private static String [] descriptionFeatureList = new String[]{
295
		"lifeform", 
296
		"Juvenile parts",
297
		"Bark",
298
		//new
299
		"wood",
300
		"Indumentum",  
301
		"endophytic body",  
302
		"flowering buds",  
303
		"Branchlets",  
304
		"Branches",  
305
		"Branch",  
306
		"Flowering branchlets",
307
		"Trees",  
308
		"Twigs",  
309
		"stem",  
310
		"Stems",  
311
		"stem leaves", 
312
		"Leaves",
313
		"extraxylary sclerenchyma",
314
		"flower-bearing stems",  
315
		"Petiole",  
316
		"Petiolules",  
317
		"Leaflets", 
318
		"Lamina",
319
		"Veins",
320
		"Thyrsus",  
321
		"Thyrses",  
322
		"Inflorescences",  
323
		"Inflorescence",
324
		"Young inflorescences", 
325
		"Male inflorescences", 
326
		"Female inflorescences", 
327
		"rachises",
328
		"Pedicels",  
329
		"Bracts",  
330
		"flowering buds",  
331
		"scales",  
332
		"Buds",  
333
		"Flowers",  
334
		"Flower",  
335
		"Flowering",
336
		"Stigma",  
337
		"perianth",  
338
		"Sepals",  
339
		"Sepal",  
340
		"Outer Sepals",  
341
		"Axillary",  
342
		"cymes",  
343
		"Calyx",  
344
		"Petal",  
345
		"Petals",
346
		"perigone",
347
		"perigone lobes",
348
		"perigone tube",
349
		"Disc",  
350
		"corolla",  
351
		"Stamens",  
352
		"Staminodes",  
353
		"Ovary",  
354
		"Anthers",
355
		"anther",  
356
		"Pistil",  
357
		"Pistillode",  
358
		"Ovules",  
359
		"androecium",  
360
		"gynoecium",  
361
		"Filaments",  		
362
		"Style",  
363
		"annulus",  
364
		"female flowers",  
365
		"Male flowers",  
366
		"Female",  
367
		"Infructescences",    //order not consistent (sometimes before "Flowers")  
368
		"Fruit",  
369
		"Fruits",  
370
		"fruiting axes",  
371
		"drupes",  
372
		"Arillode",  
373
		"seed",  
374
		"Seeds",  
375
		"Seedling",  
376
		"flower tube", 
377
		"nutlets",  
378
		"pollen",  
379
		"secondary xylem",  
380
		"chromosome number",  
381
	
382
		"figure",  
383
		"fig",  
384
		"figs",  
385

    
386

    
387
		
388
	};
389
	
390
	public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
391
		FeatureNode lastChild = null;
392
		try {
393
			for (String featureString : featureStringList){
394
				UUID featureUuid;
395
				featureUuid = transformer.getFeatureUuid(featureString);
396
				Feature feature = (Feature)termService.find(featureUuid);
397
				if (feature != null){
398
					FeatureNode child = FeatureNode.NewInstance(feature);
399
					root.addChild(child);	
400
				}
401
			}
402
			
403
		} catch (UndefinedTransformerMethodException e) {
404
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
405
		}
406
		return lastChild;
407
	}
408

    
409
	
410

    
411
	/**
412
	 * @param args
413
	 */
414
	public static void main(String[] args) {
415
		FloraGuianasActivator me = new FloraGuianasActivator();
416
		me.doImport(cdmDestination);
417
	}
418
}
(9-9/13)