Project

General

Profile

Download (7.67 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.ICdmRepository;
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.stream.mapping.IImportMapping.MappingType;
26
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
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
 * @since 10.11.2011
35
 */
36
public class ColDwcaImportActivator {
37
	private static final Logger logger = Logger.getLogger(ColDwcaImportActivator.class);
38

    
39
	//handled by ImportSteps now
40
    //static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41

    
42
	static final ImportSteps importSteps = ImportSteps.ExtensionsOnly;
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
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_col();
49

    
50
	 static final String databaseMappingFile = "C:/Users/a.mueller/.cdmLibrary/log/colMappingAnnual";
51
//    static final String databaseMappingFile = "C:/Users/a.mueller/.cdmLibrary/log/localCol";
52
//     static final String databaseMappingFile = "C:/Users/a.mueller/.cdmLibrary/log/colPoales";
53

    
54
    //classification name
55
    static String classificationName = "Catalogue of Life 2017";
56

    
57

    
58
	static boolean isNoQuotes = true;
59

    
60

    
61
	//classification
62
	static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
63

    
64
	//default nom code is ICZN as it allows adding publication year
65
	static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
66

    
67

    
68
	//check - import
69
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
70
	static int partitionSize = 1000;
71

    
72
	//config
73
	static DatasetUse datasetUse = DatasetUse.ORIGINAL_SOURCE;
74
	static boolean scientificNameIdAsOriginalSourceId = true;
75
	static boolean guessNomRef = true;
76
	private final boolean handleAllRefsAsCitation = true;
77

    
78
	//validate
79
	static boolean validateRankConsistency = false;
80

    
81
	//deduplicate
82
	static final boolean doDeduplicate = false;
83

    
84
	//auditing
85
	static final boolean registerAuditing = false;
86

    
87
	//mapping type
88
	static final MappingType mappingType = MappingType.DatabaseMapping;
89

    
90
	private void doImport(ICdmDataSource cdmDestination){
91

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

    
108
		config.setMappingType(mappingType);
109
		config.setDatabaseMappingFile(databaseMappingFile);
110
		config.setStateUuid(stateUuid);
111

    
112
		config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
113
		config.setValidateRankConsistency(validateRankConsistency);
114
		config.setDefaultPartitionSize(partitionSize);
115
		config.setNomenclaturalCode(defaultNomCode);
116
		config.setDatasetUse(datasetUse);
117
		config.setGuessNomenclaturalReferences(guessNomRef);
118
		config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
119
		config.setNoQuotes(isNoQuotes);
120

    
121
		config.setRegisterAuditing(registerAuditing);
122

    
123
		CdmDefaultImport<DwcaImportConfigurator> myImport = new CdmDefaultImport<>();
124

    
125

    
126
		//...
127
		if (true){
128
			System.out.println("Start import from ("+ source.toString() + ") ...");
129
			config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
130
			myImport.invoke(config);
131
			System.out.println("End import from ("+ source.toString() + ")...");
132
		}
133

    
134
		//deduplicate
135
		if (doDeduplicate){
136
			ICdmRepository app = myImport.getCdmAppController();
137
			int count = app.getAgentService().deduplicate(Person.class, null, null);
138
			logger.warn("Deduplicated " + count + " persons.");
139
//			count = app.getAgentService().deduplicate(Team.class, null, null);
140
//			logger.warn("Deduplicated " + count + " teams.");
141
			count = app.getReferenceService().deduplicate(Reference.class, null, null);
142
			logger.warn("Deduplicated " + count + " references.");
143
		}
144

    
145
	}
146

    
147
	private Reference getSourceReference(String string) {
148
		Reference result = ReferenceFactory.newGeneric();
149
		result.setTitleCache(string, true);
150
		return result;
151
	}
152

    
153

    
154
	//CoL
155
	public static URI dwca_col_All() {
156
	    //http://www.catalogueoflife.org/DCA_Export/
157
//	    URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02.zip");
158
//        sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-complete_2015_07_02_test.zip");
159
        URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/2017-annual.zip");
160
//	    URI sourceUrl = URI.create("file:////Pesiimport3/col/col_20Nov2012.zip");
161
//        URI sourceUrl = URI.create("file:////BGBM-PESIHPC/CoL/archive-genus-haitobolus-bl3.zip");
162
        return sourceUrl;
163
	}
164

    
165
	private enum ImportSteps{
166
	    ALL,
167
	    TaxaOnly,
168
	    ExtensionsOnly,
169
	    TaxaAndExtensions,
170
	    TaxonRelationsOnly,
171
	    SynonymsOnly,
172
	    HigherTaxaOnly,
173
	    LowerTaxaOnly
174
	    ;
175

    
176
	    private DbSchemaValidation validation(){
177
	        if (this == ALL || this == TaxaOnly || this == TaxaAndExtensions){
178
	            return DbSchemaValidation.CREATE;
179
	        }else{
180
	            return DbSchemaValidation.VALIDATE;
181
	        }
182
	    }
183

    
184
        private boolean doTaxa(){
185
            return (this == ALL || this == TaxaOnly || this == TaxaAndExtensions);
186
        }
187

    
188
        private boolean doExtensions(){
189
            return (this == ALL || this == ExtensionsOnly || this == TaxaAndExtensions);
190
        }
191

    
192
        private boolean doTaxonRelations(){
193
            return (this == ALL || this == TaxonRelationsOnly || doSplitRelations());
194
        }
195

    
196
        private boolean doSplitRelations(){
197
            return (this == SynonymsOnly || this == HigherTaxaOnly || this == LowerTaxaOnly);
198
        }
199

    
200
        private boolean doSynonymRelations(){
201
            return (this == SynonymsOnly);
202
        }
203

    
204
        private boolean doHigherTaxonRelations(){
205
            return (this == HigherTaxaOnly);
206
        }
207

    
208
        private boolean doLowerTaxonRelations(){
209
            return (this == LowerTaxaOnly);
210
        }
211

    
212
        private boolean keepMapping(){
213
            return !(this == ALL || this == TaxonRelationsOnly);
214
        }
215

    
216
	}
217

    
218
	/**
219
	 * @param args
220
	 */
221
	public static void main(String[] args) {
222
		ColDwcaImportActivator me = new ColDwcaImportActivator();
223
		me.doImport(cdmDestination);
224
		System.exit(0);
225
	}
226

    
227
}
(2-2/2)