Project

General

Profile

Download (12.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.Arrays;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.UUID;
18

    
19
import org.apache.log4j.Logger;
20
import org.springframework.transaction.TransactionStatus;
21

    
22
import eu.etaxonomy.cdm.api.application.CdmApplicationController;
23
import eu.etaxonomy.cdm.api.application.ICdmRepository;
24
import eu.etaxonomy.cdm.api.service.ITermService;
25
import eu.etaxonomy.cdm.database.DbSchemaValidation;
26
import eu.etaxonomy.cdm.database.ICdmDataSource;
27
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
28
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
29
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
30
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
31
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
32
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
33
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer;
34
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
35
import eu.etaxonomy.cdm.model.agent.Person;
36
import eu.etaxonomy.cdm.model.agent.Team;
37
import eu.etaxonomy.cdm.model.description.Feature;
38
import eu.etaxonomy.cdm.model.description.FeatureNode;
39
import eu.etaxonomy.cdm.model.description.FeatureTree;
40
import eu.etaxonomy.cdm.model.description.PolytomousKey;
41
import eu.etaxonomy.cdm.model.reference.Reference;
42
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
43

    
44
/**
45
 * @author a.mueller
46
 * @created 20.06.2008
47
 */
48
public class NepenthesActivator extends EfloraActivatorBase {
49
	private static final Logger logger = Logger.getLogger(NepenthesActivator.class);
50

    
51
	//database validation status (create, update, validate ...)
52
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
53

    
54
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_nepenthes_production();
55
	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
56
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
57
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
58

    
59
	//1775   /   16415
60
	//no syso, 5 uncovered, 2 of them epiphytic
61
//	private final boolean includeVol15 = includeBase;
62

    
63
    static final URI fmSource15 = EfloraSources.fm_15();
64

    
65
	private final boolean h2ForCheck = true;
66

    
67
	static final boolean reuseState = true;  //when running multiple imports
68

    
69

    
70
	//check - import
71
	static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
72

    
73
	static boolean doPrintKeys = false;
74
	static boolean doDeduplicate = false;
75

    
76
	//taxa
77
	static final boolean doTaxa = true;
78

    
79

    
80
    //feature tree uuid
81
    public static final UUID featureTreeUuid = UUID.fromString("ef2e2978-1ea4-44d2-a819-4e79b372b9b7");
82
    private static final String featureTreeTitle = "Nepenthaceae Feature Tree";
83

    
84
    //classification
85
    static final UUID classificationUuid = UUID.fromString("a245793a-a70f-4fcf-a626-dd4aa6d2aa1c");
86
    static final String classificationTitle = "Nepenthaceae";
87

    
88
    static final UUID specimenNotSeenMarkerTypeUuid = UUID.fromString("fb8ad1dd-ac70-4453-bc33-a9eeafd5e439");
89
    static final String specimenNotSeenMarkerTypeLabel = "Not seen for Flora Malesiana";
90

    
91
	private final boolean replaceStandardKeyTitles = false;
92
	private boolean ignoreLocalityClass = true;
93
	private boolean handleWriterManually = true;
94
	private boolean doExtensionForTaxonTitle = false;
95

    
96

    
97
	private final IIoObserver observer = new LoggingIoObserver();
98
	private final Set<IIoObserver> observerList = new HashSet<>();
99

    
100

    
101
	private void doImport(ICdmDataSource cdmDestination){
102
		observerList.add(observer);
103
		if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
104
			check = CHECK.CHECK_ONLY;
105
		}
106

    
107
		//make Source
108
        URI source = null;
109

    
110
		MarkupImportConfigurator config= MarkupImportConfigurator.NewInstance(source, cdmDestination);
111
		config.setClassificationUuid(classificationUuid);
112
		config.setClassificationName(classificationTitle);
113
		config.setDoTaxa(doTaxa);
114
		config.setCheck(check);
115
		config.setDoPrintKeys(doPrintKeys);
116
		config.setDbSchemaValidation(hbm2dll);
117
		config.setObservers(observerList);
118
		config.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
119
		config.setReuseExistingState(reuseState);
120
		config.setIgnoreLocalityClass(ignoreLocalityClass);
121
		config.setHandleWriterManually(handleWriterManually);
122
		config.setKnownCollections(getKnownCollections());
123
		config.setSpecimenNotSeenMarkerTypeUuid(specimenNotSeenMarkerTypeUuid);
124
		config.setSpecimenNotSeenMarkerTypeLabel(specimenNotSeenMarkerTypeLabel);
125
		config.setDoExtensionForTaxonTitle(doExtensionForTaxonTitle);
126

    
127
		config.setSourceReference(getSourceReference("Flora Malesiana - Vol. 15"));
128

    
129
		CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<>();
130

    
131

    
132
		//Vol15
133
		doSource(true, fmSource15, "Flora Malesiana - vol. 15", config, myImport);
134

    
135

    
136
		makeAutomatedFeatureTree(myImport.getCdmAppController(), config.getState(),
137
				featureTreeUuid, featureTreeTitle);
138

    
139
//		makeGeoService();
140

    
141
		FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
142
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
143

    
144
		//check keys
145
		if (doPrintKeys){
146
			TransactionStatus tx = myImport.getCdmAppController().startTransaction();
147
			List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
148
			for(PolytomousKey key : keys){
149
				key.print(System.out);
150
				System.out.println();
151
			}
152
			myImport.getCdmAppController().commitTransaction(tx);
153
		}
154

    
155
	      //deduplicate
156
        if (doDeduplicate){
157
            ICdmRepository app = myImport.getCdmAppController();
158
            if (app == null){
159
                app = CdmApplicationController.NewInstance(cdmDestination, hbm2dll, false);
160
            }
161
//            app.getAgentService().updateTitleCache(Team.class, null, null, null);
162
//            return;
163
          int count = app.getAgentService().deduplicate(Person.class, null, null);
164
          logger.warn("Deduplicated " + count + " persons.");
165
          count = app.getAgentService().deduplicate(Team.class, null, null);
166
//            logger.warn("Deduplicated " + count + " teams.");
167
          count = app.getReferenceService().deduplicate(Reference.class, null, null);
168
          logger.warn("Deduplicated " + count + " references.");
169
        }
170

    
171
	}
172

    
173
	/**
174
     * @return
175
     */
176
    private List<String> getKnownCollections() {
177
        List<String> result = Arrays.asList(new String[]
178
                {"Nippon Dental College","Nagoya","Sabah National Parks Herbarium","K-Wall"}) ;
179
        return result;
180
    }
181

    
182
    private void doSource(boolean doInclude, URI source, String sourceTitle, MarkupImportConfigurator markupConfig,
183
			CdmDefaultImport<MarkupImportConfigurator> myImport) {
184
		if (doInclude){
185
			System.out.println("\nStart import from ("+ source.toString() + ") ...");
186
			markupConfig.setSource(source);
187
			markupConfig.setSourceReference(getSourceReference(sourceTitle));
188
			myImport.invoke(markupConfig);
189
			System.out.println("End import from ("+ source.toString() + ")...");
190
		}
191
	}
192

    
193
	private Reference getSourceReference(String string) {
194
		Reference result = ReferenceFactory.newGeneric();
195
		result.setTitleCache(string, true);
196
		return result;
197
	}
198

    
199
	private FeatureTree makeFeatureNode(ITermService service){
200
		FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
201

    
202
		FeatureTree result = FeatureTree.NewInstance(UUID.randomUUID());
203
		result.setTitleCache("Flora Malesiana Nepenthaceae Simple Feature Tree", true);
204
		FeatureNode root = result.getRoot();
205
		FeatureNode newNode;
206

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

    
210

    
211
		newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
212
		root.addChild(newNode);
213

    
214
	    newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
215
	    root.addChild(newNode);
216

    
217
        newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
218
        root.addChild(newNode);
219

    
220
        newNode = FeatureNode.NewInstance(Feature.SPECIMEN());
221
        root.addChild(newNode);
222

    
223
        newNode = FeatureNode.NewInstance(Feature.NOTES());
224
        root.addChild(newNode);
225

    
226
//		addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
227

    
228
//		addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
229
//		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
230
//		addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
231
//
232
//		newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
233
//		addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
234
//
235
//		newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
236
//
237
//
238

    
239
//
240
//		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
241
//		root.addChild(newNode);
242
//		addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
243
//
244
//		newNode = FeatureNode.NewInstance(Feature.USES());
245
//		root.addChild(newNode);
246
//
247
//		addFeataureNodesByStringList(chomosomesList, root, transformer, service);
248

    
249

    
250
		return result;
251
	}
252

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

    
257

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

    
263

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

    
271

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

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

    
291

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

    
301

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

    
310

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

    
394
		"figure",
395
		"fig",
396
		"figs",
397

    
398

    
399

    
400
	};
401

    
402
	public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
403
		FeatureNode lastChild = null;
404
		try {
405
			for (String featureString : featureStringList){
406
				UUID featureUuid;
407
				featureUuid = transformer.getFeatureUuid(featureString);
408
				Feature feature = (Feature)termService.find(featureUuid);
409
				if (feature != null){
410
					FeatureNode child = FeatureNode.NewInstance(feature);
411
					root.addChild(child);
412
				}
413
			}
414

    
415
		} catch (UndefinedTransformerMethodException e) {
416
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
417
		}
418
		return lastChild;
419
	}
420

    
421

    
422

    
423
	/**
424
	 * @param args
425
	 */
426
	public static void main(String[] args) {
427
		NepenthesActivator me = new NepenthesActivator();
428
		me.doImport(cdmDestination);
429
		System.exit(0);
430
	}
431

    
432
}
(14-14/14)