1 |
acdc7437
|
Andreas Müller
|
/**
|
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 |
9638d8f7
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator.DatasetUse;
|
26 |
8d477b8a
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.dwca.in.IImportMapping.MappingType;
|
27 |
acdc7437
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.agent.Person;
|
28 |
9638d8f7
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
29 |
acdc7437
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30 |
|
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
* @author a.mueller
|
34 |
7e96b3c1
|
Andreas Müller
|
* @created 10.11.2011
|
35 |
acdc7437
|
Andreas Müller
|
*/
|
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 |
ba37ba74
|
Andreas Müller
|
// static final URI source = dwca_test_in();
|
42 |
b6050fc2
|
Andreas Müller
|
// static final URI source = dwca_test_cich_len();
|
43 |
7e96b3c1
|
Andreas Müller
|
static final URI source = dwca_test_col_sapindaceae();
|
44 |
|
|
// static final URI source = dwca_test_col_cichorium();
|
45 |
898b2185
|
Andreas Müller
|
// static final URI source = dwca_test_scratch_test();
|
46 |
|
|
// static final URI source = dwca_test_col_All_Pesi2();
|
47 |
8d477b8a
|
Andreas Müller
|
// static final URI source = dwca_test_col_All();
|
48 |
0d21320d
|
Andreas Müller
|
// static final URI source = dwca_test_col_All_Pesi2();
|
49 |
ba37ba74
|
Andreas Müller
|
|
50 |
acdc7437
|
Andreas Müller
|
|
51 |
898b2185
|
Andreas Müller
|
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 |
acdc7437
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
55 |
0d21320d
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_pesi_test();
|
56 |
7e96b3c1
|
Andreas Müller
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
57 |
acdc7437
|
Andreas Müller
|
|
58 |
|
|
|
59 |
|
|
//classification
|
60 |
c9978a69
|
Andreas Müller
|
static final UUID classificationUuid = UUID.fromString("29d4011f-a6dd-4081-beb8-559ba6b84a6b");
|
61 |
acdc7437
|
Andreas Müller
|
|
62 |
9638d8f7
|
Andreas Müller
|
//default nom code is ICZN as it allows adding publication year
|
63 |
|
|
static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICZN;
|
64 |
|
|
|
65 |
|
|
|
66 |
acdc7437
|
Andreas Müller
|
//check - import
|
67 |
|
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
68 |
7e96b3c1
|
Andreas Müller
|
static int partitionSize = 5;
|
69 |
acdc7437
|
Andreas Müller
|
|
70 |
c9978a69
|
Andreas Müller
|
//config
|
71 |
9638d8f7
|
Andreas Müller
|
static DatasetUse datasetUse = DatasetUse.SECUNDUM;
|
72 |
c9978a69
|
Andreas Müller
|
static boolean scientificNameIdAsOriginalSourceId = true;
|
73 |
0d21320d
|
Andreas Müller
|
static boolean guessNomRef = true;
|
74 |
|
|
private boolean handleAllRefsAsCitation = true;
|
75 |
c9978a69
|
Andreas Müller
|
|
76 |
|
|
//validate
|
77 |
|
|
static boolean validateRankConsistency = false;
|
78 |
|
|
|
79 |
|
|
|
80 |
acdc7437
|
Andreas Müller
|
//taxa
|
81 |
|
|
static final boolean doTaxa = true;
|
82 |
|
|
static final boolean doDistribution = false;
|
83 |
c9978a69
|
Andreas Müller
|
//deduplicate
|
84 |
|
|
static final boolean doDeduplicate = false;
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
8d477b8a
|
Andreas Müller
|
static final MappingType mappingType = MappingType.InMemoryMapping;
|
89 |
acdc7437
|
Andreas Müller
|
|
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.setCheck(check);
|
97 |
|
|
config.setDbSchemaValidation(hbm2dll);
|
98 |
8d477b8a
|
Andreas Müller
|
config.setMappingType(mappingType);
|
99 |
0d21320d
|
Andreas Müller
|
|
100 |
c9978a69
|
Andreas Müller
|
config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
|
101 |
|
|
config.setValidateRankConsistency(validateRankConsistency);
|
102 |
7e96b3c1
|
Andreas Müller
|
config.setDefaultPartitionSize(partitionSize);
|
103 |
9638d8f7
|
Andreas Müller
|
config.setNomenclaturalCode(defaultNomCode);
|
104 |
0d21320d
|
Andreas Müller
|
config.setDatasetUse(datasetUse);
|
105 |
|
|
config.setGuessNomenclaturalReferences(guessNomRef);
|
106 |
|
|
config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
|
107 |
acdc7437
|
Andreas Müller
|
|
108 |
|
|
CdmDefaultImport myImport = new CdmDefaultImport();
|
109 |
|
|
|
110 |
|
|
|
111 |
|
|
//...
|
112 |
|
|
if (true){
|
113 |
|
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
114 |
|
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
115 |
|
|
myImport.invoke(config);
|
116 |
|
|
System.out.println("End import from ("+ source.toString() + ")...");
|
117 |
|
|
}
|
118 |
|
|
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
//deduplicate
|
122 |
|
|
if (doDeduplicate){
|
123 |
|
|
ICdmApplicationConfiguration app = myImport.getCdmAppController();
|
124 |
|
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
125 |
|
|
logger.warn("Deduplicated " + count + " persons.");
|
126 |
|
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
127 |
|
|
// logger.warn("Deduplicated " + count + " teams.");
|
128 |
|
|
count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
129 |
|
|
logger.warn("Deduplicated " + count + " references.");
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
}
|
133 |
|
|
|
134 |
9638d8f7
|
Andreas Müller
|
private Reference<?> getSourceReference(String string) {
|
135 |
|
|
Reference<?> result = ReferenceFactory.newGeneric();
|
136 |
acdc7437
|
Andreas Müller
|
result.setTitleCache(string);
|
137 |
|
|
return result;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
//Dwca
|
141 |
|
|
public static URI dwca_test_in() {
|
142 |
|
|
// 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");
|
143 |
|
|
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");
|
144 |
|
|
return sourceUrl;
|
145 |
|
|
}
|
146 |
ba37ba74
|
Andreas Müller
|
|
147 |
|
|
|
148 |
|
|
//Dwca
|
149 |
|
|
public static URI dwca_test_cich() {
|
150 |
|
|
URI sourceUrl = URI.create("file:///E:/opt/data/dwca/20110621_1400_cichorieae_dwca.zip");
|
151 |
|
|
return sourceUrl;
|
152 |
|
|
}
|
153 |
80467b49
|
Andreas Müller
|
|
154 |
|
|
//Dwca
|
155 |
|
|
public static URI dwca_test_cich_len() {
|
156 |
|
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/export/20110621_1400_cichorieae_dwca.zip");
|
157 |
|
|
return sourceUrl;
|
158 |
|
|
}
|
159 |
|
|
|
160 |
b6050fc2
|
Andreas Müller
|
//Dwca
|
161 |
|
|
public static URI dwca_test_col_cichorium() {
|
162 |
|
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/Cichorium/archive-genus-Cichorium-bl3.zip");
|
163 |
|
|
return sourceUrl;
|
164 |
|
|
}
|
165 |
80467b49
|
Andreas Müller
|
|
166 |
7e96b3c1
|
Andreas Müller
|
//Dwca
|
167 |
|
|
public static URI dwca_test_col_sapindaceae() {
|
168 |
|
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/Sapindaceae/archive-family-Sapindaceae-bl3.zip");
|
169 |
|
|
return sourceUrl;
|
170 |
|
|
}
|
171 |
|
|
|
172 |
b6050fc2
|
Andreas Müller
|
//CoL
|
173 |
|
|
public static URI dwca_test_col_All() {
|
174 |
|
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/CoL/All/archive-complete.zip");
|
175 |
|
|
return sourceUrl;
|
176 |
|
|
}
|
177 |
acdc7437
|
Andreas Müller
|
|
178 |
8d477b8a
|
Andreas Müller
|
//CoL
|
179 |
|
|
public static URI dwca_test_col_All_Pesi2() {
|
180 |
|
|
URI sourceUrl = URI.create("file:///C:/opt/data/CoL/All/archive-complete.zip");
|
181 |
|
|
return sourceUrl;
|
182 |
|
|
}
|
183 |
acdc7437
|
Andreas Müller
|
|
184 |
898b2185
|
Andreas Müller
|
//Scratchpads test
|
185 |
|
|
public static URI dwca_test_scratch_test() {
|
186 |
|
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_export_scratchpads_test.zip");
|
187 |
|
|
return sourceUrl;
|
188 |
|
|
}
|
189 |
|
|
|
190 |
acdc7437
|
Andreas Müller
|
|
191 |
|
|
/**
|
192 |
|
|
* @param args
|
193 |
|
|
*/
|
194 |
|
|
public static void main(String[] args) {
|
195 |
|
|
DwcaImportActivator me = new DwcaImportActivator();
|
196 |
|
|
me.doImport(cdmDestination);
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
}
|