Project

General

Profile

Download (9.44 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
	
53
	
54
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
55
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
56
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
57
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
58
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
59
	
60

    
61
	//feature tree uuid
62
	public static final UUID featureTreeUuid = UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
63
	
64
	//classification
65
	static final UUID classificationUuid = UUID.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
66
	
67
	//check - import
68
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
69
	
70
	static boolean doPrintKeys = false;
71
	
72
	//taxa
73
	static final boolean doTaxa = true;
74

    
75
	private boolean includeVol13_small = true;
76
	private boolean includeVol13_large = false;
77

    
78
	private IIoObserver observer = new LoggingIoObserver();
79
	private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
80
	
81
	
82
	private void doImport(ICdmDataSource cdmDestination){
83
		observerList.add(observer);
84
		if (cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
85
			check = CHECK.CHECK_ONLY;
86
		}
87
		
88
		//make Source
89
		URI source = fmSource13_small;
90
		MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
91
		markupConfig.setClassificationUuid(classificationUuid);
92
		markupConfig.setDoTaxa(doTaxa);
93
		markupConfig.setCheck(check);
94
		markupConfig.setDoPrintKeys(doPrintKeys);
95
		markupConfig.setDbSchemaValidation(hbm2dll);
96
		markupConfig.setObservers(observerList);
97
		
98
		CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>();
99

    
100

    
101
		markupConfig.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
102
		//Vol13_1
103
		if (includeVol13_small){
104
			System.out.println("\nStart import from ("+ fmSource13_small.toString() + ") ...");
105
			source = fmSource13_small;
106
			markupConfig.setSource(source);
107
			myImport.invoke(markupConfig);
108
			System.out.println("End import from ("+ fmSource13_small.toString() + ")...");
109
		}
110

    
111
		//Vol13_2
112
		if (includeVol13_large){
113
			System.out.println("\nStart import from ("+ fmSource13_large.toString() + ") ...");
114
			source = fmSource13_large;
115
			markupConfig.setSource(source);
116
			myImport.invoke(markupConfig);
117
			System.out.println("End import from ("+ fmSource13_large.toString() + ")...");
118
		}
119
		
120
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
121
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
122
		
123
		//check keys
124
		if (doPrintKeys){
125
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
126
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
127
			for(PolytomousKey key : keys){
128
				key.print(System.out);
129
				System.out.println();
130
			}
131
			myImport.getCdmAppController().commitTransaction(tx);
132
		}
133
		
134
	}
135
	
136
	private Reference getSourceReference(String string) {
137
		Reference result = ReferenceFactory.newGeneric();
138
		result.setTitleCache(string);
139
		return result;
140
	}
141

    
142
	private FeatureTree makeFeatureNode(ITermService service){
143
		FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
144
		
145
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
146
		result.setTitleCache("Flora Malesiana Presentation Feature Tree");
147
		FeatureNode root = result.getRoot();
148
		FeatureNode newNode;
149
		
150
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
151
		root.addChild(newNode);
152
		
153
		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
154

    
155
		addFeataureNodesByStringList(generellDescriptionsList, root, transformer, service);
156

    
157
		
158
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
159
		root.addChild(newNode);
160

    
161
		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
162
		root.addChild(newNode);
163
		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
164
		
165
		newNode = FeatureNode.NewInstance(Feature.USES());
166
		root.addChild(newNode);
167
		
168
		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
169

    
170
		newNode = FeatureNode.NewInstance(Feature.CITATION());
171
		root.addChild(newNode);
172
		
173
		return result;
174
	}
175
	
176
	private static String [] chomosomesList = new String[]{
177
		"Chromosomes", 
178
	};
179

    
180
	
181
	private static String [] habitatEcologyList = new String[]{
182
		"Habitat",
183
		"Habitat & Ecology"
184
	};
185
	
186
	
187
	private static String [] generellDescriptionsList = new String[]{
188
		"Fossils",
189
		"Morphology and anatomy",
190
		"Morphology", 
191
		"Vegetative morphology and anatomy",
192
		"Flower morphology",
193
		"Palynology",  
194
		"Pollination",  
195
		"Pollen morphology",
196
		"embryology",
197
		"cytology",
198
		"Life cycle",
199
		"Fruits and embryology",
200
		"Dispersal",
201
		"Wood anatomy",  
202
		"Leaf anatomy",  
203
		"Chromosome numbers", 
204
		"Phytochemistry and Chemotaxonomy",
205
		"Phytochemistry",
206
		"Taxonomy",
207
		"Notes"
208
	};
209

    
210
	private static String [] descriptionFeatureList = new String[]{
211
		"lifeform", 
212
		"Bark",
213
		//new
214
		"wood",
215
		"Indumentum",  
216
		"endophytic body",  
217
		"flowering buds",  
218
		"Branchlets",  
219
		"Branches",  
220
		"Branch",  
221
		"Flowering branchlets",
222
		"Trees",  
223
		"Twigs",  
224
		"stem",  
225
		"Stems",  
226
		"stem leaves", 
227
		"Leaves",
228
		"flower-bearing stems",  
229
		"Petiole",  
230
		"Petiolules",  
231
		"Leaflets", 
232
		"Thyrsus",  
233
		"Thyrses",  
234
		"Inflorescences",  
235
		"Inflorescence",
236
		"Young inflorescences", 
237
		"male inflorescences", 
238
		"female inflorescences", 
239
		"Bracts",  
240
		"Pedicels",  
241
		"flowering buds",  
242
		"scales",  
243
		"Buds",  
244
		"Flowers",  
245
		"Flower",  
246
		"Flowering",
247
		"Stigma",  
248
		"perianth",  
249
		"Sepals",  
250
		"Sepal",  
251
		"Outer Sepals",  
252
		"Axillary",  
253
		"cymes",  
254
		"Calyx",  
255
		"Petal",  
256
		"Petals",  
257
		"perigone tube",
258
		"Disc",  
259
		"corolla",  
260
		"Stamens",  
261
		"Staminodes",  
262
		"Ovary",  
263
		"Anthers",
264
		"anther",  
265
		"Pistil",  
266
		"Pistillode",  
267
		"Ovules",  
268
		"androecium",  
269
		"gynoecium",  
270
		"Filaments",  		
271
		"Style",  
272
		"annulus",  
273
		"female flowers",  
274
		"Male flowers",  
275
		"Female",  
276
		"Infructescences",    //order not consistent (sometimes before "Flowers")  
277
		"Fruit",  
278
		"Fruits",  
279
		"fruiting axes",  
280
		"drupes",  
281
		"Arillode",  
282
		"seed",  
283
		"Seeds",  
284
		"Seedling",  
285
		"flower tube", 
286
		"nutlets",  
287
		"pollen",  
288
		"secondary xylem",  
289
		"chromosome number",  
290
	
291
		"figure",  
292
		"fig",  
293
		"figs",  
294

    
295

    
296
		
297
	};
298
	
299
	public void addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
300
		try {
301
			for (String featureString : featureStringList){
302
			UUID featureUuid;
303
			featureUuid = transformer.getFeatureUuid(featureString);
304
			Feature feature = (Feature)termService.find(featureUuid);
305
			if (feature != null){
306
				FeatureNode child = FeatureNode.NewInstance(feature);
307
				root.addChild(child);	
308
			}
309
		}
310
		} catch (UndefinedTransformerMethodException e) {
311
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
312
		}
313
	}
314
	
315

    
316

    
317
	/**
318
	 * @param args
319
	 */
320
	public static void main(String[] args) {
321
		FloraMalesianaVol13Activator me = new FloraMalesianaVol13Activator();
322
		me.doImport(cdmDestination);
323
	}
324
	
325
}
(6-6/6)