Project

General

Profile

Download (12.7 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
package eu.etaxonomy.cdm.app.eflora;
10

    
11
import java.net.URI;
12
import java.util.List;
13
import java.util.UUID;
14

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

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

    
32
/**
33
 * Activator for Flora of the Guianas imports.
34
 * This class is meant for advanced use and is therefore not documented.
35
 * @author a.mueller
36
 */
37
public class FloraGuianasActivator extends EfloraActivatorBase {
38
	private static final Logger logger = Logger.getLogger(FloraGuianasActivator.class);
39

    
40
	//database validation status (create, update, validate ...)
41
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
42
	static final URI fgu1 = EfloraSources.fgu_1();
43

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

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

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

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

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

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

    
66
	private boolean inverseInclude = false;
67

    
68
	private boolean includeFotg1 = false;
69

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

    
85
	private boolean includeFotg29 = false;
86
	private boolean includeFotg30 = false;
87

    
88

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

    
94

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

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

    
101
	private static final String SOURCE_REFERENCE_TITLE = "Flora of the Guianas";
102
	static final String classificationTitle = "Flora of the Guianas";
103

    
104
	private static final String FEATURE_TREE_TITLE = "Flora of the Guianas Feature Tree";
105

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

    
110
	static boolean doPrintKeys = false;
111

    
112
	//taxa
113
	static final boolean doTaxa = true;
114

    
115
	static final boolean reuseState = true;
116

    
117
	private boolean replaceStandardKeyTitles = true;
118

    
119
	private boolean useFotGCollectionTypeOnly = true;
120

    
121
// ****************** NO CHANGE *******************************************/
122

    
123
	private void doImport(ICdmDataSource cdmDestination){
124
		super.doImport(fotg22, cdmDestination,check, h2ForCheck);
125

    
126

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

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

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

    
180
		//Vol29
181
		executeVolume(fotg29, includeFotg29 ^ inverseInclude);
182
		//Vol30
183
		executeVolume(fotg30, includeFotg30 ^ inverseInclude);
184

    
185
		TermTree<Feature> tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
186
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
187

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

    
199
	}
200

    
201
	private Reference getSourceReference(String string) {
202
		Reference result = ReferenceFactory.newGeneric();
203
		result.setTitleCache(string);
204
		return result;
205
	}
206

    
207
	private TermTree<Feature> makeFeatureNode(ITermService service){
208
		MarkupTransformer transformer = new MarkupTransformer();
209

    
210
		TermTree<Feature> result = TermTree.NewFeatureInstance(featureTreeUuid);
211
		result.setTitleCache(FEATURE_TREE_TITLE, true);
212
		TermNode<Feature> root = result.getRoot();
213

    
214
		TermNode<Feature> newNode = root.addChild(Feature.DESCRIPTION());
215

    
216
		addFeatureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
217

    
218
		addFeatureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
219
		newNode = root.addChild(Feature.ANATOMY());  //not sure if this is correct, but it looked like the node was orphaned before
220
		addFeatureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
221

    
222
		newNode = addFeatureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
223
		addFeatureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
224

    
225
		newNode = addFeatureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
226

    
227

    
228
		newNode = root.addChild(Feature.DISTRIBUTION());
229

    
230
		newNode = root.addChild(Feature.COMMON_NAME());
231

    
232
		newNode = root.addChild(Feature.PHENOLOGY());
233

    
234
		newNode = root.addChild(Feature.ECOLOGY());
235
		addFeatureNodesByStringList(habitatEcologyList, root, transformer, service);
236

    
237
		newNode = root.addChild(Feature.USES());
238

    
239
		addFeatureNodesByStringList(chomosomesList, root, transformer, service);
240

    
241
		newNode = root.addChild(Feature.CITATION());
242

    
243
		String sql = "\nSELECT feature.titleCache " +
244
				" FROM DescriptionElementBase deb INNER JOIN DefinedTermBase feature ON deb.feature_id = feature.id " +
245
				" GROUP BY feature.id " +
246
				" HAVING feature.id NOT IN (SELECT DISTINCT fn.feature_id " +
247
				" FROM FeatureNode fn " +
248
				" WHERE fn.feature_id IS NOT NULL) ";
249
		logger.warn("Check for missing features in feature tree: " + sql);
250

    
251
		return result;
252
	}
253

    
254
	private static String [] chomosomesList = new String[]{
255
		"Chromosomes",
256
	};
257

    
258

    
259
	private static String [] habitatEcologyList = new String[]{
260
		"Habitat",
261
		"Habitat & Ecology"
262
	};
263

    
264

    
265
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
266
		"Fossils",
267
		"Morphology and anatomy",
268
		"Morphology",
269
		"Vegetative morphology and anatomy",
270
	};
271

    
272

    
273
	private static String [] anatomySubfeatureList = new String[]{
274
		"Leaf anatomy",
275
		"Wood anatomy"
276
	};
277

    
278
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
279
		"Flower morphology",
280
		"Palynology",
281
		"Pollination",
282
		"Pollen morphology",
283
		"embryology",
284
		"cytology",
285
		"Life cycle",
286
		"Fruits and embryology",
287
		"Dispersal",
288
		"Chromosome numbers",
289
		"Phytochemistry and Chemotaxonomy",
290
	};
291

    
292

    
293
	private static String [] phytoChemoSubFeaturesList = new String[]{
294
		"Alkaloids",
295
		"Iridoid glucosides",
296
		"Leaf phenolics",
297
		"Storage products of seeds",
298
		"Aluminium",
299
		"Chemotaxonomy",
300
	};
301

    
302

    
303
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
304
		"Phytochemistry",
305
		"Taxonomy",
306
		"history",
307
		"cultivation",
308
		"Notes"
309
	};
310

    
311

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

    
400
		"figure",
401
		"fig",
402
		"figs",
403

    
404

    
405

    
406
	};
407

    
408
	public TermNode<Feature> addFeatureNodesByStringList(String[] featureStringList, TermNode<Feature> root, IInputTransformer transformer, ITermService termService){
409
	    TermNode<Feature> lastChild = null;
410
		try {
411
			for (String featureString : featureStringList){
412
				UUID featureUuid;
413
				featureUuid = transformer.getFeatureUuid(featureString);
414
				Feature feature = (Feature)termService.find(featureUuid);
415
				if (feature != null){
416
				    root.addChild(feature);
417
				}
418
			}
419

    
420
		} catch (UndefinedTransformerMethodException e) {
421
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
422
		}
423
		return lastChild;
424
	}
425

    
426
	public static void main(String[] args) {
427
		FloraGuianasActivator me = new FloraGuianasActivator();
428
		me.doImport(cdmDestination);
429
	}
430
}
(9-9/15)