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.TaxaOnly;
|
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_col_local();
|
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:////Pesiimport3/col/col_20Nov2012.zip");
|
155
|
return sourceUrl;
|
156
|
}
|
157
|
|
158
|
private enum ImportSteps{
|
159
|
ALL,
|
160
|
TaxaOnly,
|
161
|
ExtensionsOnly,
|
162
|
TaxaAndExtensions,
|
163
|
TaxonRelationsOnly,
|
164
|
SynonymsOnly,
|
165
|
HigherTaxaOnly,
|
166
|
LowerTaxaOnly
|
167
|
;
|
168
|
|
169
|
private DbSchemaValidation validation(){
|
170
|
if (this == ALL || this == TaxaOnly || this == TaxaAndExtensions){
|
171
|
return DbSchemaValidation.CREATE;
|
172
|
}else{
|
173
|
return DbSchemaValidation.VALIDATE;
|
174
|
}
|
175
|
}
|
176
|
|
177
|
private boolean doTaxa(){
|
178
|
return (this == ALL || this == TaxaOnly || this == TaxaAndExtensions);
|
179
|
}
|
180
|
|
181
|
private boolean doExtensions(){
|
182
|
return (this == ALL || this == ExtensionsOnly || this == TaxaAndExtensions);
|
183
|
}
|
184
|
|
185
|
private boolean doTaxonRelations(){
|
186
|
return (this == ALL || this == TaxonRelationsOnly || doSplitRelations());
|
187
|
}
|
188
|
|
189
|
private boolean doSplitRelations(){
|
190
|
return (this == SynonymsOnly || this == HigherTaxaOnly || this == LowerTaxaOnly);
|
191
|
}
|
192
|
|
193
|
private boolean doSynonymRelations(){
|
194
|
return (this == SynonymsOnly);
|
195
|
}
|
196
|
|
197
|
private boolean doHigherTaxonRelations(){
|
198
|
return (this == HigherTaxaOnly);
|
199
|
}
|
200
|
|
201
|
private boolean doLowerTaxonRelations(){
|
202
|
return (this == LowerTaxaOnly);
|
203
|
}
|
204
|
|
205
|
private boolean keepMapping(){
|
206
|
return !(this == ALL || this == TaxonRelationsOnly);
|
207
|
}
|
208
|
|
209
|
}
|
210
|
|
211
|
/**
|
212
|
* @param args
|
213
|
*/
|
214
|
public static void main(String[] args) {
|
215
|
ColDwcaImportActivator me = new ColDwcaImportActivator();
|
216
|
me.doImport(cdmDestination);
|
217
|
}
|
218
|
|
219
|
}
|