Project

General

Profile

Download (12.4 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.Arrays;
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.application.CdmApplicationController;
22
import eu.etaxonomy.cdm.api.application.ICdmRepository;
23
import eu.etaxonomy.cdm.api.service.ITermService;
24
import eu.etaxonomy.cdm.database.DbSchemaValidation;
25
import eu.etaxonomy.cdm.database.ICdmDataSource;
26
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
27
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
28
import eu.etaxonomy.cdm.io.common.events.IIoObserver;
29
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
30
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
31
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
32
import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer;
33
import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
34
import eu.etaxonomy.cdm.model.agent.Person;
35
import eu.etaxonomy.cdm.model.agent.Team;
36
import eu.etaxonomy.cdm.model.description.Feature;
37
import eu.etaxonomy.cdm.model.description.PolytomousKey;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
40
import eu.etaxonomy.cdm.model.term.TermNode;
41
import eu.etaxonomy.cdm.model.term.TermTree;
42

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

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

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

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

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

    
64
	private final boolean h2ForCheck = true;
65

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

    
68

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

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

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

    
78

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

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

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

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

    
95

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

    
99

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

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

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

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

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

    
130

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

    
134

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

    
138
//		makeGeoService();
139

    
140
		TermTree<Feature> tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
141
		myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
142

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

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

    
170
	}
171

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

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

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

    
198
	private TermTree<Feature> makeFeatureNode(ITermService service){
199
		FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
200

    
201
		TermTree<Feature> result = TermTree.NewFeatureInstance(UUID.randomUUID());
202
		result.setTitleCache("Flora Malesiana Nepenthaceae Simple Feature Tree", true);
203
		TermNode<Feature> root = result.getRoot();
204

    
205
		TermNode<Feature> newNode = root.addChild(Feature.CITATION());
206

    
207
		newNode = root.addChild(Feature.DESCRIPTION());
208

    
209
	    newNode = root.addChild(Feature.DISTRIBUTION());
210

    
211
        newNode = root.addChild(Feature.ECOLOGY());
212

    
213
        newNode = root.addChild(Feature.SPECIMEN());
214

    
215
        newNode = root.addChild(Feature.NOTES());
216

    
217
//		addFeatureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
218

    
219
//		addFeatureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
220
//		newNode = FeatureNode.NewInstance(Feature.ANATOMY());
221
//		addFeatureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
222
//
223
//		newNode = addFeatureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
224
//		addFeatureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
225
//
226
//		newNode = addFeatureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
227
//
228
//
229

    
230
//
231
//		newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
232
//		root.addChild(newNode);
233
//		addFeatureNodesByStringList(habitatEcologyList, root, transformer, service);
234
//
235
//		newNode = FeatureNode.NewInstance(Feature.USES());
236
//		root.addChild(newNode);
237
//
238
//		addFeatureNodesByStringList(chomosomesList, root, transformer, service);
239

    
240

    
241
		return result;
242
	}
243

    
244
	private static String [] chomosomesList = new String[]{
245
		"Chromosomes",
246
	};
247

    
248

    
249
	private static String [] habitatEcologyList = new String[]{
250
		"Habitat",
251
		"Habitat & Ecology"
252
	};
253

    
254

    
255
	private static String [] generellDescriptionsUpToAnatomyList = new String[]{
256
		"Fossils",
257
		"Morphology and anatomy",
258
		"Morphology",
259
		"Vegetative morphology and anatomy",
260
	};
261

    
262

    
263
	private static String [] anatomySubfeatureList = new String[]{
264
		"Leaf anatomy",
265
		"Wood anatomy"
266
	};
267

    
268
	private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
269
		"Flower morphology",
270
		"Palynology",
271
		"Pollination",
272
		"Pollen morphology",
273
		"embryology",
274
		"cytology",
275
		"Life cycle",
276
		"Fruits and embryology",
277
		"Dispersal",
278
		"Chromosome numbers",
279
		"Phytochemistry and Chemotaxonomy",
280
	};
281

    
282

    
283
	private static String [] phytoChemoSubFeaturesList = new String[]{
284
		"Alkaloids",
285
		"Iridoid glucosides",
286
		"Leaf phenolics",
287
		"Storage products of seeds",
288
		"Aluminium",
289
		"Chemotaxonomy",
290
	};
291

    
292

    
293
	private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
294
		"Phytochemistry",
295
		"Taxonomy",
296
		"history",
297
		"cultivation",
298
		"Notes"
299
	};
300

    
301

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

    
385
		"figure",
386
		"fig",
387
		"figs",
388

    
389

    
390

    
391
	};
392

    
393
	public TermNode<Feature> addFeatureNodesByStringList(String[] featureStringList,
394
	            TermNode<Feature> root, IInputTransformer transformer, ITermService termService){
395

    
396
	    TermNode<Feature> lastChild = null;
397
		try {
398
			for (String featureString : featureStringList){
399
				UUID featureUuid;
400
				featureUuid = transformer.getFeatureUuid(featureString);
401
				Feature feature = (Feature)termService.find(featureUuid);
402
				if (feature != null){
403
					root.addChild(feature);
404
				}
405
			}
406

    
407
		} catch (UndefinedTransformerMethodException e) {
408
			logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
409
		}
410
		return lastChild;
411
	}
412

    
413

    
414

    
415
	/**
416
	 * @param args
417
	 */
418
	public static void main(String[] args) {
419
		NepenthesActivator me = new NepenthesActivator();
420
		me.doImport(cdmDestination);
421
		System.exit(0);
422
	}
423

    
424
}
(15-15/15)