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.DwcaImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator.DatasetUse;
|
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 16.12.2010
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public class DwcaImportActivator {
|
38
|
private static final Logger logger = Logger.getLogger(DwcaImportActivator.class);
|
39
|
|
40
|
//database validation status (create, update, validate ...)
|
41
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
42
|
// static final URI source = dwca_test_in();
|
43
|
// static final URI source = dwca_test_cich_len();
|
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_Pesi2();
|
47
|
// static final URI source = dwca_test_col_All();
|
48
|
// static final URI source = dwca_test_col_All_Pesi2();
|
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_test();
|
57
|
|
58
|
|
59
|
//classification
|
60
|
static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
|
61
|
|
62
|
//default nom code is ICZN as it allows adding publication year
|
63
|
static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
|
64
|
|
65
|
|
66
|
//check - import
|
67
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
68
|
|
69
|
//config
|
70
|
static DatasetUse datasetUse = DatasetUse.SECUNDUM;
|
71
|
static boolean scientificNameIdAsOriginalSourceId = true;
|
72
|
static boolean guessNomRef = true;
|
73
|
private boolean handleAllRefsAsCitation = true;
|
74
|
|
75
|
//validate
|
76
|
static boolean validateRankConsistency = false;
|
77
|
|
78
|
|
79
|
//taxa
|
80
|
static final boolean doTaxa = true;
|
81
|
static final boolean doDistribution = false;
|
82
|
//deduplicate
|
83
|
static final boolean doDeduplicate = false;
|
84
|
|
85
|
|
86
|
|
87
|
static final MappingType mappingType = MappingType.InMemoryMapping;
|
88
|
|
89
|
private void doImport(ICdmDataSource cdmDestination){
|
90
|
|
91
|
//make Source
|
92
|
DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
|
93
|
config.addObserver(new LoggingIoObserver());
|
94
|
config.setClassificationUuid(classificationUuid);
|
95
|
config.setCheck(check);
|
96
|
config.setDbSchemaValidation(hbm2dll);
|
97
|
config.setMappingType(mappingType);
|
98
|
|
99
|
config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
|
100
|
config.setValidateRankConsistency(validateRankConsistency);
|
101
|
config.setNomenclaturalCode(defaultNomCode);
|
102
|
config.setDatasetUse(datasetUse);
|
103
|
config.setGuessNomenclaturalReferences(guessNomRef);
|
104
|
config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
|
105
|
|
106
|
CdmDefaultImport myImport = new CdmDefaultImport();
|
107
|
|
108
|
|
109
|
//...
|
110
|
if (true){
|
111
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
112
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
113
|
myImport.invoke(config);
|
114
|
System.out.println("End import from ("+ source.toString() + ")...");
|
115
|
}
|
116
|
|
117
|
|
118
|
|
119
|
//deduplicate
|
120
|
if (doDeduplicate){
|
121
|
ICdmApplicationConfiguration app = myImport.getCdmAppController();
|
122
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
123
|
logger.warn("Deduplicated " + count + " persons.");
|
124
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
125
|
// logger.warn("Deduplicated " + count + " teams.");
|
126
|
count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
127
|
logger.warn("Deduplicated " + count + " references.");
|
128
|
}
|
129
|
|
130
|
}
|
131
|
|
132
|
private Reference<?> getSourceReference(String string) {
|
133
|
Reference<?> result = ReferenceFactory.newGeneric();
|
134
|
result.setTitleCache(string);
|
135
|
return result;
|
136
|
}
|
137
|
|
138
|
//Dwca
|
139
|
public static URI dwca_test_in() {
|
140
|
// 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");
|
141
|
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");
|
142
|
return sourceUrl;
|
143
|
}
|
144
|
|
145
|
|
146
|
//Dwca
|
147
|
public static URI dwca_test_cich() {
|
148
|
URI sourceUrl = URI.create("file:///E:/opt/data/dwca/20110621_1400_cichorieae_dwca.zip");
|
149
|
return sourceUrl;
|
150
|
}
|
151
|
|
152
|
//Dwca
|
153
|
public static URI dwca_test_cich_len() {
|
154
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/export/20110621_1400_cichorieae_dwca.zip");
|
155
|
return sourceUrl;
|
156
|
}
|
157
|
|
158
|
//Dwca
|
159
|
public static URI dwca_test_col_cichorium() {
|
160
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/Cichorium/archive-genus-Cichorium-bl3.zip");
|
161
|
return sourceUrl;
|
162
|
}
|
163
|
|
164
|
//CoL
|
165
|
public static URI dwca_test_col_All() {
|
166
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/All/archive-complete.zip");
|
167
|
return sourceUrl;
|
168
|
}
|
169
|
|
170
|
//CoL
|
171
|
public static URI dwca_test_col_All_Pesi2() {
|
172
|
URI sourceUrl = URI.create("file:///C:/opt/data/CoL/All/archive-complete.zip");
|
173
|
return sourceUrl;
|
174
|
}
|
175
|
|
176
|
//Scratchpads test
|
177
|
public static URI dwca_test_scratch_test() {
|
178
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_export_scratchpads_test.zip");
|
179
|
return sourceUrl;
|
180
|
}
|
181
|
|
182
|
|
183
|
/**
|
184
|
* @param args
|
185
|
*/
|
186
|
public static void main(String[] args) {
|
187
|
DwcaImportActivator me = new DwcaImportActivator();
|
188
|
me.doImport(cdmDestination);
|
189
|
}
|
190
|
|
191
|
}
|