Project

General

Profile

Download (5.17 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.i4life.col;
11

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

    
15
import org.apache.log4j.Logger;
16

    
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationDefaultConfiguration;
18
import eu.etaxonomy.cdm.app.common.CdmDestinations;
19
import eu.etaxonomy.cdm.database.DbSchemaValidation;
20
import eu.etaxonomy.cdm.database.ICdmDataSource;
21
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
22
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
23
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
24
import eu.etaxonomy.cdm.io.dwca.in.DwcaDataImportConfiguratorBase.DatasetUse;
25
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
26
import eu.etaxonomy.cdm.io.dwca.in.IImportMapping.MappingType;
27
import eu.etaxonomy.cdm.model.agent.Person;
28
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
29
import eu.etaxonomy.cdm.model.reference.Reference;
30
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
31

    
32
/**
33
 * @author a.mueller
34
 * @created 10.11.2011
35
 */
36
public class ColDwcaImportActivator {
37
	private static final Logger logger = Logger.getLogger(ColDwcaImportActivator.class);
38
	
39
	//database validation status (create, update, validate ...)
40
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41
	static final URI source = dwca_col_All();
42

    
43
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_dwca();
44

    
45

    
46
	static boolean isNoQuotes = true;
47
	
48
	//classification
49
	static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
50
	
51
	//default nom code is ICZN as it allows adding publication year 
52
	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
53

    
54
	
55
	//check - import
56
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
57
	static int partitionSize = 5000;
58
	
59
	//config
60
	static DatasetUse datasetUse = DatasetUse.ORIGINAL_SOURCE;
61
	static boolean scientificNameIdAsOriginalSourceId = true;
62
	static boolean guessNomRef = true;
63
	private boolean handleAllRefsAsCitation = true;
64
	
65
	//validate
66
	static boolean validateRankConsistency = false;
67
	
68
	
69
	//taxa
70
	static final boolean doTaxa = true;
71
	static final boolean doDistribution = false;
72
	//deduplicate
73
	static final boolean doDeduplicate = false;
74
	
75
	
76
	
77
	static final MappingType mappingType = MappingType.InMemoryMapping;
78
	
79
	private void doImport(ICdmDataSource cdmDestination){
80
		
81
		//make Source
82
		DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
83
		config.addObserver(new LoggingIoObserver());
84
		config.setClassificationUuid(classificationUuid);
85
		config.setCheck(check);
86
		config.setDbSchemaValidation(hbm2dll);
87
		config.setMappingType(mappingType);
88
		
89
		config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
90
		config.setValidateRankConsistency(validateRankConsistency);
91
		config.setDefaultPartitionSize(partitionSize);
92
		config.setNomenclaturalCode(defaultNomCode);
93
		config.setDatasetUse(datasetUse);
94
		config.setGuessNomenclaturalReferences(guessNomRef);
95
		config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
96
		config.setNoQuotes(isNoQuotes);
97
		
98
		CdmDefaultImport myImport = new CdmDefaultImport();
99

    
100
		
101
		//...
102
		if (true){
103
			System.out.println("Start import from ("+ source.toString() + ") ...");
104
			config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
105
			myImport.invoke(config);
106
			System.out.println("End import from ("+ source.toString() + ")...");
107
		}
108
		
109
		
110
		
111
		//deduplicate
112
		if (doDeduplicate){
113
			ICdmApplicationDefaultConfiguration app = myImport.getCdmAppController();
114
			int count = app.getAgentService().deduplicate(Person.class, null, null);
115
			logger.warn("Deduplicated " + count + " persons.");
116
//			count = app.getAgentService().deduplicate(Team.class, null, null);
117
//			logger.warn("Deduplicated " + count + " teams.");
118
			count = app.getReferenceService().deduplicate(Reference.class, null, null);
119
			logger.warn("Deduplicated " + count + " references.");
120
		}
121
		
122
	}
123

    
124
	private Reference<?> getSourceReference(String string) {
125
		Reference<?> result = ReferenceFactory.newGeneric();
126
		result.setTitleCache(string);
127
		return result;
128
	}
129

    
130
	//Dwca
131
	public static URI dwca_test_in() {
132
//		URI sourceUrl = URI.create("http://dev.e-taxonomy.eu/trac/export/14463/trunk/cdmlib/cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/DwcaZipToStreamConverterTest-input.zip");
133
		URI sourceUrl = URI.create("file:///C:/Users/pesiimport/Documents/pesi_cdmlib/cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/DwcaZipToStreamConverterTest-input.zip");
134
		return sourceUrl;
135
	}
136
	
137
	
138
	//CoL
139
	public static URI dwca_col_All() {
140
		URI sourceUrl = URI.create("file:///data/dwca/xylariaceae/added.zip");
141
		return sourceUrl;
142
	}
143

    
144
	/**
145
	 * @param args
146
	 */
147
	public static void main(String[] args) {
148
		ColDwcaImportActivator me = new ColDwcaImportActivator();
149
		me.doImport(cdmDestination);
150
	}
151
	
152
}
(2-2/2)