Project

General

Profile

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

    
45
	static final URI fotg03 = EfloraSources.fotg_03();
46

    
47
	static final URI fotg11 = EfloraSources.fotg_11();
48

    
49
	static final URI fotg14 = EfloraSources.fotg_14();
50
	static final URI fotg15 = EfloraSources.fotg_15();
51
	static final URI fotg16 = EfloraSources.fotg_16();
52

    
53
	static final URI fotg20 = EfloraSources.fotg_20();
54

    
55
	static final URI fotg22 = EfloraSources.fotg_22();
56
	static final URI fotg23 = EfloraSources.fotg_23();
57
	static final URI fotg24 = EfloraSources.fotg_24();
58
	static final URI fotg24_plus = EfloraSources.fotg_24plus();
59
	static final URI fotg25 = EfloraSources.fotg_25();
60
	static final URI fotg25_plus = EfloraSources.fotg_25plus();
61
	static final URI fotg26 = EfloraSources.fotg_26();
62
	static final URI fotg27 = EfloraSources.fotg_27();
63

    
64
	static final URI fotg29 = EfloraSources.fotg_29();
65
	static final URI fotg30 = EfloraSources.fotg_30();
66

    
67

    
68
	private boolean inverseInclude = false;
69

    
70
	private boolean includeFotg1 = false;
71

    
72
	private boolean includeFotg03 = true;
73
	private boolean includeFotg11 = false;
74
	private boolean includeFotg14 = false;
75
	private boolean includeFotg15 = false;
76
	private boolean includeFotg16 = false;
77
	private boolean includeFotg20 = false;
78
	private boolean includeFotg22 = false;
79
	private boolean includeFotg23 = false;
80
	private boolean includeFotg24 = false;
81
	private boolean includeFotg24_plus = false;
82
	private boolean includeFotg25 = false;
83
	private boolean includeFotg25_plus = false;
84
	private boolean includeFotg26 = false;
85
	private boolean includeFotg27 = false;
86

    
87
	private boolean includeFotg29 = false;
88
	private boolean includeFotg30 = false;
89

    
90

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

    
96

    
97
	//feature tree uuid
98
	public static final UUID featureTreeUuid = UUID.fromString("2be99595-92fc-4f80-b9c4-b48d38505f5d");
99

    
100
	//classification
101
	static final UUID classificationUuid = UUID.fromString("5e3a1b07-2609-4597-bbda-7b02dfe8c2b3");
102

    
103
	private static final String SOURCE_REFERENCE_TITLE = "Flora of the Guianas";
104
	static final String classificationTitle = "Flora of the Guianas";
105

    
106
	private static final String FEATURE_TREE_TITLE = "Flora of the Guianas Feature Tree";
107

    
108
	//check - import
109
	private boolean h2ForCheck = true;
110
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
111

    
112
	static boolean doPrintKeys = false;
113

    
114
	//taxa
115
	static final boolean doTaxa = true;
116

    
117
	static final boolean reuseState = true;
118

    
119

    
120

    
121
	private boolean replaceStandardKeyTitles = true;
122

    
123
	private boolean useFotGCollectionTypeOnly = true;
124

    
125
// ****************** NO CHANGE *******************************************/
126

    
127
	private void doImport(ICdmDataSource cdmDestination){
128
		super.doImport(fotg22, cdmDestination,check, h2ForCheck);
129

    
130

    
131
		//make config
132
		config.setClassificationUuid(classificationUuid);
133
		config.setDoTaxa(doTaxa);
134
		config.setDoPrintKeys(doPrintKeys);
135
		config.setDbSchemaValidation(hbm2dll);
136
		config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
137
		config.setSourceReference(getSourceReference(SOURCE_REFERENCE_TITLE));
138
		config.setClassificationName(classificationTitle);
139
		config.setReuseExistingState(reuseState);
140
		config.setUseFotGSpecimenTypeCollectionAndTypeOnly(useFotGCollectionTypeOnly);
141

    
142
//		URI uri = config.getSource();
143
//		try {
144
////			InputStream is = uri.toURL().openStream();
145
//			File file = new File(uri);
146
//			System.out.println(file.exists());
147
//			InputStream is = new FileInputStream(file);
148
//			System.out.println(is);
149
//		} catch (Exception e) {
150
//			e.printStackTrace();
151
//		}
152

    
153
		//Vol1-79
154
		executeVolume( fgu1, includeFotg1 ^ inverseInclude);
155
		//Vol03
156
		executeVolume(fotg03, includeFotg03 ^ inverseInclude);
157
		//Vol11
158
		executeVolume(fotg11, includeFotg11 ^ inverseInclude);
159
		//Vol14
160
		executeVolume(fotg14, includeFotg14 ^ inverseInclude);
161
		//Vol15
162
		executeVolume(fotg15, includeFotg15 ^ inverseInclude);
163
		//Vol16
164
		executeVolume(fotg16, includeFotg16 ^ inverseInclude);
165
		//Vol20
166
		executeVolume(fotg20, includeFotg20 ^ inverseInclude);
167
		//Vol22
168
		executeVolume(fotg22, includeFotg22 ^ inverseInclude);
169
		//Vol23
170
		executeVolume(fotg23, includeFotg23 ^ inverseInclude);
171
		//Vol24
172
		executeVolume(fotg24, includeFotg24 ^ inverseInclude);
173
		//Vol24+
174
		executeVolume(fotg24_plus, includeFotg24_plus ^ inverseInclude);
175
		//Vol25
176
		executeVolume(fotg25, includeFotg25 ^ inverseInclude);
177
		//Vol26
178
		executeVolume(fotg25_plus, includeFotg25_plus ^ inverseInclude);
179
		//Vol26
180
		executeVolume(fotg26, includeFotg26 ^ inverseInclude);
181
		//Vol27
182
		executeVolume(fotg27, includeFotg27 ^ inverseInclude);
183

    
184
		//Vol29
185
		executeVolume(fotg29, includeFotg29 ^ inverseInclude);
186
		//Vol30
187
		executeVolume(fotg30, includeFotg30 ^ inverseInclude);
188

    
189
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
190
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
191

    
192
		//check keys
193
		if (doPrintKeys){
194
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
195
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
196
			for(PolytomousKey key : keys){
197
				key.print(System.out);
198
				System.out.println();
199
			}
200
			myImport.getCdmAppController().commitTransaction(tx);
201
		}
202

    
203
	}
204

    
205
	private Reference getSourceReference(String string) {
206
		Reference result = ReferenceFactory.newGeneric();
207
		result.setTitleCache(string);
208
		return result;
209
	}
210

    
211
	private FeatureTree makeFeatureNode(ITermService service){
212
		MarkupTransformer transformer = new MarkupTransformer();
213

    
214
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
215
		result.setTitleCache(FEATURE_TREE_TITLE, true);
216
		FeatureNode root = result.getRoot();
217
		FeatureNode newNode;
218

    
219
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
220
		root.addChild(newNode);
221

    
222
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
223

    
224
		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
225
		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
226
		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
227

    
228
		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
229
		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
230

    
231
		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
232

    
233

    
234
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
235
		root.addChild(newNode);
236

    
237
		newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
238
		root.addChild(newNode);
239

    
240
		newNode = FeatureNode.NewInstance(Feature.PHENOLOGY());
241
		root.addChild(newNode);
242

    
243
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
244
		root.addChild(newNode);
245
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
246

    
247
		newNode = FeatureNode.NewInstance(Feature.USES());
248
		root.addChild(newNode);
249

    
250
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
251

    
252
		newNode = FeatureNode.NewInstance(Feature.CITATION());
253
		root.addChild(newNode);
254

    
255
		String sql = "\nSELECT feature.titleCache " +
256
				" FROM DescriptionElementBase deb INNER JOIN DefinedTermBase feature ON deb.feature_id = feature.id " +
257
				" GROUP BY feature.id " +
258
				" HAVING feature.id NOT IN (SELECT DISTINCT fn.feature_id " +
259
				" FROM FeatureNode fn " +
260
				" WHERE fn.feature_id IS NOT NULL) ";
261
		logger.warn("Check for missing features in feature tree: " + sql);
262

    
263
		return result;
264
	}
265

    
266
	private static String [] chomosomesList = new String[]{
267
		"Chromosomes",
268
	};
269

    
270

    
271
	private static String [] habitatEcologyList = new String[]{
272
		"Habitat",
273
		"Habitat & Ecology"
274
	};
275

    
276

    
277
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
278
		"Fossils",
279
		"Morphology and anatomy",
280
		"Morphology",
281
		"Vegetative morphology and anatomy",
282
	};
283

    
284

    
285
	private static String [] anatomySubfeatureList = new String[]{
286
		"Leaf anatomy",
287
		"Wood anatomy"
288
	};
289

    
290
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
291
		"Flower morphology",
292
		"Palynology",
293
		"Pollination",
294
		"Pollen morphology",
295
		"embryology",
296
		"cytology",
297
		"Life cycle",
298
		"Fruits and embryology",
299
		"Dispersal",
300
		"Chromosome numbers",
301
		"Phytochemistry and Chemotaxonomy",
302
	};
303

    
304

    
305
	private static String [] phytoChemoSubFeaturesList = new String[]{
306
		"Alkaloids",
307
		"Iridoid glucosides",
308
		"Leaf phenolics",
309
		"Storage products of seeds",
310
		"Aluminium",
311
		"Chemotaxonomy",
312
	};
313

    
314

    
315
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
316
		"Phytochemistry",
317
		"Taxonomy",
318
		"history",
319
		"cultivation",
320
		"Notes"
321
	};
322

    
323

    
324
	private static String [] descriptionFeatureList = new String[]{
325
		"lifeform",
326
		"Juvenile parts",
327
		"Bark",
328
		//new
329
		"wood",
330
		"Indumentum",
331
		"endophytic body",
332
		"flowering buds",
333
		"Branchlets",
334
		"Branches",
335
		"Branch",
336
		"Flowering branchlets",
337
		"Trees",
338
		"Twigs",
339
		"stem",
340
		"Stems",
341
		"stem leaves",
342
		"Leaves",
343
		"extraxylary sclerenchyma",
344
		"flower-bearing stems",
345
		"Petiole",
346
		"Petiolules",
347
		"Leaflets",
348
		"Lamina",
349
		"Veins",
350
		"Thyrsus",
351
		"Thyrses",
352
		"Inflorescences",
353
		"Inflorescence",
354
		"Young inflorescences",
355
		"Male inflorescences",
356
		"Female inflorescences",
357
		"rachises",
358
		"Pedicels",
359
		"Bracts",
360
		"flowering buds",
361
		"scales",
362
		"Buds",
363
		"Flowers",
364
		"Flower",
365
		"Flowering",
366
		"Stigma",
367
		"perianth",
368
		"Sepals",
369
		"Sepal",
370
		"Outer Sepals",
371
		"Axillary",
372
		"cymes",
373
		"Calyx",
374
		"Petal",
375
		"Petals",
376
		"perigone",
377
		"perigone lobes",
378
		"perigone tube",
379
		"Disc",
380
		"corolla",
381
		"Stamens",
382
		"Staminodes",
383
		"Ovary",
384
		"Anthers",
385
		"anther",
386
		"Pistil",
387
		"Pistillode",
388
		"Ovules",
389
		"androecium",
390
		"gynoecium",
391
		"Filaments",
392
		"Style",
393
		"annulus",
394
		"female flowers",
395
		"Male flowers",
396
		"Female",
397
		"Infructescences",    //order not consistent (sometimes before "Flowers")
398
		"Fruit",
399
		"Fruits",
400
		"fruiting axes",
401
		"drupes",
402
		"Arillode",
403
		"seed",
404
		"Seeds",
405
		"Seedling",
406
		"flower tube",
407
		"nutlets",
408
		"pollen",
409
		"secondary xylem",
410
		"chromosome number",
411

    
412
		"figure",
413
		"fig",
414
		"figs",
415

    
416

    
417

    
418
	};
419

    
420
	public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
421
		FeatureNode lastChild = null;
422
		try {
423
			for (String featureString : featureStringList){
424
				UUID featureUuid;
425
				featureUuid = transformer.getFeatureUuid(featureString);
426
				Feature feature = (Feature)termService.find(featureUuid);
427
				if (feature != null){
428
					FeatureNode child = FeatureNode.NewInstance(feature);
429
					root.addChild(child);
430
				}
431
			}
432

    
433
		} catch (UndefinedTransformerMethodException e) {
434
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
435
		}
436
		return lastChild;
437
	}
438

    
439

    
440

    
441
	/**
442
	 * @param args
443
	 */
444
	public static void main(String[] args) {
445
		FloraGuianasActivator me = new FloraGuianasActivator();
446
		me.doImport(cdmDestination);
447
	}
448
}
(9-9/13)