Project

General

Profile

Download (7.28 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("81b402d0-e2dc-462b-b1ff-2171b846fce9");
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
	//default nom code is ICZN as it allows adding publication year
57
	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
58

    
59

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

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

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

    
73

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

    
81

    
82
	//mapping type
83
	static final MappingType mappingType = MappingType.DatabaseMapping;
84
	static final String databaseMappingFile = "C:/Users/a.mueller/.cdmLibrary/log/colMapping";
85

    
86
	private void doImport(ICdmDataSource cdmDestination){
87

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

    
103
		config.setMappingType(mappingType);
104
		config.setDatabaseMappingFile(databaseMappingFile);
105
		config.setStateUuid(stateUuid);
106

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

    
116
		CdmDefaultImport<DwcaImportConfigurator> myImport = new CdmDefaultImport<DwcaImportConfigurator>();
117

    
118

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

    
127

    
128

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

    
140
	}
141

    
142
	private Reference<?> getSourceReference(String string) {
143
		Reference<?> result = ReferenceFactory.newGeneric();
144
		result.setTitleCache(string, true);
145
		return result;
146
	}
147

    
148

    
149
	//CoL
150
	public static URI dwca_col_All() {
151
	    //http://www.catalogueoflife.org/DCA_Export/
152
//	    URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02.zip");
153
//        sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02_test.zip");
154
        URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/2015-03-18-archive-complete.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
        private boolean keepMapping(){
207
            return !(this == ALL || this == TaxonRelationsOnly);
208
        }
209

    
210
	}
211

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

    
220
}
(2-2/2)