Project

General

Profile

Download (7.04 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.ICdmApplicationConfiguration;
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

    
42
	ImportSteps importSteps = ImportSteps.TaxaOnly;
43

    
44
	static final URI source = dwca_col_All();
45

    
46
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_col();
47

    
48

    
49
	static boolean isNoQuotes = true;
50

    
51

    
52
	//classification
53
	static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
54

    
55
	//default nom code is ICZN as it allows adding publication year
56
	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
57

    
58

    
59
	//check - import
60
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
61
	static int partitionSize = 1000;
62

    
63
	//config
64
	static DatasetUse datasetUse = DatasetUse.ORIGINAL_SOURCE;
65
	static boolean scientificNameIdAsOriginalSourceId = true;
66
	static boolean guessNomRef = true;
67
	private final boolean handleAllRefsAsCitation = true;
68

    
69
	//validate
70
	static boolean validateRankConsistency = false;
71

    
72

    
73
	//taxa
74
//	static final boolean doTaxa = true;
75
	static final boolean doTaxonRelationships = false;
76
//	static final boolean doDistributionD = false;
77
	//deduplicate
78
	static final boolean doDeduplicate = false;
79

    
80

    
81
	//mapping type
82
	static final MappingType mappingType = MappingType.DatabaseMapping;
83

    
84
	private void doImport(ICdmDataSource cdmDestination){
85

    
86
		//make Source
87
		DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
88
		config.addObserver(new LoggingIoObserver());
89
		config.setClassificationUuid(classificationUuid);
90
		config.setCheck(check);
91
		config.setDbSchemaValidation(importSteps.validation());
92
		config.setDoTaxonRelationships(importSteps.doTaxonRelations());
93
		config.setDoTaxa(importSteps.doTaxa());
94
		config.setDoExtensions(importSteps.doExtensions());
95
		config.setDoHigherRankRelationships(importSteps.doHigherTaxonRelations());
96
		config.setDoSplitRelationshipImport(importSteps.doSplitRelations());
97
		config.setDoLowerRankRelationships(importSteps.doLowerTaxonRelations());
98
		config.setDoSynonymRelationships(importSteps.doSynonymRelations());
99

    
100
		config.setMappingType(mappingType);
101

    
102
		config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
103
		config.setValidateRankConsistency(validateRankConsistency);
104
		config.setDefaultPartitionSize(partitionSize);
105
		config.setNomenclaturalCode(defaultNomCode);
106
		config.setDatasetUse(datasetUse);
107
		config.setGuessNomenclaturalReferences(guessNomRef);
108
		config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
109
		config.setNoQuotes(isNoQuotes);
110

    
111
		CdmDefaultImport<DwcaImportConfigurator> myImport = new CdmDefaultImport<DwcaImportConfigurator>();
112

    
113

    
114
		//...
115
		if (true){
116
			System.out.println("Start import from ("+ source.toString() + ") ...");
117
			config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
118
			myImport.invoke(config);
119
			System.out.println("End import from ("+ source.toString() + ")...");
120
		}
121

    
122

    
123

    
124
		//deduplicate
125
		if (doDeduplicate){
126
			ICdmApplicationConfiguration app = myImport.getCdmAppController();
127
			int count = app.getAgentService().deduplicate(Person.class, null, null);
128
			logger.warn("Deduplicated " + count + " persons.");
129
//			count = app.getAgentService().deduplicate(Team.class, null, null);
130
//			logger.warn("Deduplicated " + count + " teams.");
131
			count = app.getReferenceService().deduplicate(Reference.class, null, null);
132
			logger.warn("Deduplicated " + count + " references.");
133
		}
134

    
135
	}
136

    
137
	private Reference<?> getSourceReference(String string) {
138
		Reference<?> result = ReferenceFactory.newGeneric();
139
		result.setTitleCache(string, true);
140
		return result;
141
	}
142

    
143
	//Dwca
144
	public static URI dwca_test_in() {
145
//		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");
146
		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");
147
		return sourceUrl;
148
	}
149

    
150

    
151
	//CoL
152
	public static URI dwca_col_All() {
153
	    //http://www.catalogueoflife.org/DCA_Export/
154
	    URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02.zip");
155
//	    URI sourceUrl = URI.create("file:////Pesiimport3/col/col_20Nov2012.zip");
156
        return sourceUrl;
157
	}
158

    
159
	private enum ImportSteps{
160
	    ALL,
161
	    TaxaOnly,
162
	    ExtensionsOnly,
163
	    TaxaAndExtensions,
164
	    TaxonRelationsOnly,
165
	    SynonymsOnly,
166
	    HigherTaxaOnly,
167
	    LowerTaxaOnly
168
	    ;
169

    
170
	    private DbSchemaValidation validation(){
171
	        if (this == ALL || this == TaxaOnly || this == TaxaAndExtensions){
172
	            return DbSchemaValidation.CREATE;
173
	        }else{
174
	            return DbSchemaValidation.VALIDATE;
175
	        }
176
	    }
177

    
178
        private boolean doTaxa(){
179
            return (this == ALL || this == TaxaOnly || this == TaxaAndExtensions);
180
        }
181

    
182
        private boolean doExtensions(){
183
            return (this == ALL || this == ExtensionsOnly || this == TaxaAndExtensions);
184
        }
185

    
186
        private boolean doTaxonRelations(){
187
            return (this == ALL || this == TaxonRelationsOnly || doSplitRelations());
188
        }
189

    
190
        private boolean doSplitRelations(){
191
            return (this == SynonymsOnly || this == HigherTaxaOnly || this == LowerTaxaOnly);
192
        }
193

    
194
        private boolean doSynonymRelations(){
195
            return (this == SynonymsOnly);
196
        }
197

    
198
        private boolean doHigherTaxonRelations(){
199
            return (this == HigherTaxaOnly);
200
        }
201

    
202
        private boolean doLowerTaxonRelations(){
203
            return (this == LowerTaxaOnly);
204
        }
205

    
206
	}
207

    
208
	/**
209
	 * @param args
210
	 */
211
	public static void main(String[] args) {
212
		ColDwcaImportActivator me = new ColDwcaImportActivator();
213
		me.doImport(cdmDestination);
214
	}
215

    
216
}
(2-2/2)