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.dwca;
|
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 DwcaImportActivator {
|
37
|
private static final Logger logger = Logger.getLogger(DwcaImportActivator.class);
|
38
|
|
39
|
//database validation status (create, update, validate ...)
|
40
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
41
|
// static final URI source = dwca_test_in();
|
42
|
// static final URI source = dwca_test_cich_len();
|
43
|
// static final URI source = dwca_test_col_sapindaceae();
|
44
|
// static final URI source = dwca_test_col_cichorium();
|
45
|
// static final URI source = dwca_test_scratch_test();
|
46
|
// static final URI source = dwca_test_col_All();
|
47
|
// static final URI source = dwca_test_col_All_Pesi2();
|
48
|
static final URI source = dwca_emonocots_dioscoreaceae();
|
49
|
|
50
|
|
51
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
52
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_dwca();
|
53
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
54
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_pesi_test();
|
56
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_pesi();
|
57
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
58
|
|
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.SECUNDUM;
|
74
|
static boolean scientificNameIdAsOriginalSourceId = true;
|
75
|
static boolean guessNomRef = true;
|
76
|
static boolean handleAllRefsAsCitation = true;
|
77
|
|
78
|
//validate
|
79
|
static boolean validateRankConsistency = false;
|
80
|
|
81
|
|
82
|
//taxa
|
83
|
static final boolean doTaxa = true;
|
84
|
static final boolean doDistribution = false;
|
85
|
//deduplicate
|
86
|
static final boolean doDeduplicate = false;
|
87
|
|
88
|
|
89
|
|
90
|
static final MappingType mappingType = MappingType.InMemoryMapping;
|
91
|
|
92
|
private void doImport(ICdmDataSource cdmDestination){
|
93
|
|
94
|
//make Source
|
95
|
DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
|
96
|
config.addObserver(new LoggingIoObserver());
|
97
|
config.setClassificationUuid(classificationUuid);
|
98
|
config.setCheck(check);
|
99
|
config.setDbSchemaValidation(hbm2dll);
|
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
|
|
110
|
CdmDefaultImport<DwcaImportConfigurator> myImport = new CdmDefaultImport<DwcaImportConfigurator>();
|
111
|
|
112
|
|
113
|
//...
|
114
|
if (true){
|
115
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
116
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
117
|
myImport.invoke(config);
|
118
|
System.out.println("End import from ("+ source.toString() + ")...");
|
119
|
}
|
120
|
|
121
|
|
122
|
|
123
|
//deduplicate
|
124
|
if (doDeduplicate){
|
125
|
ICdmApplicationConfiguration app = myImport.getCdmAppController();
|
126
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
127
|
logger.warn("Deduplicated " + count + " persons.");
|
128
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
129
|
// logger.warn("Deduplicated " + count + " teams.");
|
130
|
count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
131
|
logger.warn("Deduplicated " + count + " references.");
|
132
|
}
|
133
|
|
134
|
}
|
135
|
|
136
|
private Reference getSourceReference(String string) {
|
137
|
Reference result = ReferenceFactory.newGeneric();
|
138
|
result.setTitleCache(string);
|
139
|
return result;
|
140
|
}
|
141
|
|
142
|
//Dwca
|
143
|
public static URI dwca_test_in() {
|
144
|
// 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");
|
145
|
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");
|
146
|
return sourceUrl;
|
147
|
}
|
148
|
|
149
|
|
150
|
//Dwca
|
151
|
public static URI dwca_test_cich() {
|
152
|
URI sourceUrl = URI.create("file:///E:/opt/data/dwca/20110621_1400_cichorieae_dwca.zip");
|
153
|
return sourceUrl;
|
154
|
}
|
155
|
|
156
|
//Dwca
|
157
|
public static URI dwca_test_cich_len() {
|
158
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/export/20110621_1400_cichorieae_dwca.zip");
|
159
|
return sourceUrl;
|
160
|
}
|
161
|
|
162
|
//Dwca
|
163
|
public static URI dwca_test_col_cichorium() {
|
164
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/Cichorium/archive-genus-Cichorium-bl3.zip");
|
165
|
return sourceUrl;
|
166
|
}
|
167
|
|
168
|
//Dwca
|
169
|
public static URI dwca_test_col_sapindaceae() {
|
170
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/Sapindaceae/archive-family-Sapindaceae-bl3.zip");
|
171
|
return sourceUrl;
|
172
|
}
|
173
|
|
174
|
//Dwca
|
175
|
public static URI dwca_emonocots_local() {
|
176
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/Scratchpads/dwca_dioscoreaceae_emonocots.zip");
|
177
|
return sourceUrl;
|
178
|
}
|
179
|
|
180
|
//emonocots_dioscoreaceae
|
181
|
public static URI dwca_emonocots_dioscoreaceae() {
|
182
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_dioscoreaceae.zip");
|
183
|
return sourceUrl;
|
184
|
}
|
185
|
|
186
|
//emonocots_zingiberaceae
|
187
|
public static URI dwca_emonocots_zingiberaceae() {
|
188
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_zingiberaceae.zip");
|
189
|
return sourceUrl;
|
190
|
}
|
191
|
//emonocots_cypripedioideae
|
192
|
public static URI dwca_emonocots_cypripedioideae() {
|
193
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_cypripedioideae.zip");
|
194
|
return sourceUrl;
|
195
|
}
|
196
|
|
197
|
|
198
|
//CoL
|
199
|
public static URI dwca_test_col_All() {
|
200
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/All/archive-complete.zip");
|
201
|
return sourceUrl;
|
202
|
}
|
203
|
|
204
|
//CoL
|
205
|
public static URI dwca_test_col_All_Pesi2() {
|
206
|
URI sourceUrl = URI.create("file:///C:/opt/data/CoL/All/archive-complete.zip");
|
207
|
return sourceUrl;
|
208
|
}
|
209
|
|
210
|
|
211
|
|
212
|
/**
|
213
|
* @param args
|
214
|
*/
|
215
|
public static void main(String[] args) {
|
216
|
DwcaImportActivator me = new DwcaImportActivator();
|
217
|
me.doImport(cdmDestination);
|
218
|
}
|
219
|
|
220
|
}
|