Project

General

Profile

Download (7.26 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
	static final ImportSteps importSteps = ImportSteps.TaxaAndExtensions;
43
	static final UUID stateUuid = UUID.fromString("7e1da388-0039-4ba3-b0dc-b2bebbf507db");
44

    
45
	static final URI source = dwca_col_All();
46

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

    
49

    
50
	static boolean isNoQuotes = true;
51

    
52

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

    
56
	//classification name
57
	static String classificationName = "Catalogue of Life 2015";
58

    
59
	//default nom code is ICZN as it allows adding publication year
60
	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
61

    
62

    
63
	//check - import
64
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
65
	static int partitionSize = 1000;
66

    
67
	//config
68
	static DatasetUse datasetUse = DatasetUse.ORIGINAL_SOURCE;
69
	static boolean scientificNameIdAsOriginalSourceId = true;
70
	static boolean guessNomRef = true;
71
	private final boolean handleAllRefsAsCitation = true;
72

    
73
	//validate
74
	static boolean validateRankConsistency = false;
75

    
76
	//deduplicate
77
	static final boolean doDeduplicate = false;
78

    
79
	//mapping type
80
	static final MappingType mappingType = MappingType.DatabaseMapping;
81
	static final String databaseMappingFile = "C:/Users/a.mueller/.cdmLibrary/log/colMappingAnnual";
82

    
83
	private void doImport(ICdmDataSource cdmDestination){
84

    
85
		//make Source
86
		DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
87
		config.addObserver(new LoggingIoObserver());
88
		config.setClassificationUuid(classificationUuid);
89
		config.setClassificationName(classificationName);
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
		config.setKeepMappingForFurtherImports(importSteps.keepMapping());
100

    
101
		config.setMappingType(mappingType);
102
		config.setDatabaseMappingFile(databaseMappingFile);
103
		config.setStateUuid(stateUuid);
104

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

    
114
		CdmDefaultImport<DwcaImportConfigurator> myImport = new CdmDefaultImport<DwcaImportConfigurator>();
115

    
116

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

    
125

    
126

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

    
138
	}
139

    
140
	private Reference getSourceReference(String string) {
141
		Reference result = ReferenceFactory.newGeneric();
142
		result.setTitleCache(string, true);
143
		return result;
144
	}
145

    
146

    
147
	//CoL
148
	public static URI dwca_col_All() {
149
	    //http://www.catalogueoflife.org/DCA_Export/
150
//	    URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02.zip");
151
//        sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02_test.zip");
152
        URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/2015-03-18-archive-complete.zip");
153
//	    URI sourceUrl = URI.create("file:////Pesiimport3/col/col_20Nov2012.zip");
154
        return sourceUrl;
155
	}
156

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

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

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

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

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

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

    
192
        private boolean doSynonymRelations(){
193
            return (this == SynonymsOnly);
194
        }
195

    
196
        private boolean doHigherTaxonRelations(){
197
            return (this == HigherTaxaOnly);
198
        }
199

    
200
        private boolean doLowerTaxonRelations(){
201
            return (this == LowerTaxaOnly);
202
        }
203

    
204
        private boolean keepMapping(){
205
            return !(this == ALL || this == TaxonRelationsOnly);
206
        }
207

    
208
	}
209

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

    
218
}
(2-2/2)