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.vibrant;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
|
17
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
18
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
19
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
20
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
21
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
22
|
import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
|
23
|
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.io.dwca.in.DwcaImportConfigurator.DatasetUse;
|
25
|
import eu.etaxonomy.cdm.io.dwca.in.IImportMapping.MappingType;
|
26
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
27
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
28
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
29
|
|
30
|
/**
|
31
|
* @author a.mueller
|
32
|
* @created 03.04.2012
|
33
|
* @version 1.0
|
34
|
*/
|
35
|
public class DwcaScratchpadImportActivator {
|
36
|
@SuppressWarnings("unused")
|
37
|
private static final Logger logger = Logger.getLogger(DwcaScratchpadImportActivator.class);
|
38
|
|
39
|
//database validation status (create, update, validate ...)
|
40
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
41
|
|
42
|
// static final URI source = dwca_emonocots_dioscoreaceae();
|
43
|
static final URI source = dwca_emonocots_zingiberaceae();
|
44
|
// static final URI source = dwca_emonocots_cypripedioideae();
|
45
|
|
46
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
47
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
|
48
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
49
|
|
50
|
//default nom code is ICZN as it allows adding publication year
|
51
|
static final NomenclaturalCode defaultNomCode = NomenclaturalCode.ICBN;
|
52
|
|
53
|
//title
|
54
|
static final String title = "Scratchpad test import";
|
55
|
|
56
|
//check - import
|
57
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
58
|
static int partitionSize = 1000;
|
59
|
|
60
|
//config
|
61
|
static DatasetUse datasetUse = DatasetUse.CLASSIFICATION;
|
62
|
|
63
|
//validate
|
64
|
static boolean validateRankConsistency = false;
|
65
|
|
66
|
|
67
|
//taxa
|
68
|
static final boolean doTaxa = true;
|
69
|
static final boolean doDistribution = true;
|
70
|
|
71
|
|
72
|
|
73
|
static final MappingType mappingType = MappingType.InMemoryMapping;
|
74
|
|
75
|
//classification
|
76
|
static final UUID classificationUuid = UUID.fromString("d9d199b6-eaf4-47c8-a732-0639bc445c56");
|
77
|
|
78
|
|
79
|
//config
|
80
|
static boolean scientificNameIdAsOriginalSourceId = true;
|
81
|
static boolean guessNomRef = false;
|
82
|
private boolean handleAllRefsAsCitation = false;
|
83
|
private static final boolean useSourceReferenceAsSec = true;
|
84
|
|
85
|
|
86
|
//deduplicate
|
87
|
static final boolean doDeduplicate = false;
|
88
|
|
89
|
|
90
|
|
91
|
protected void doImport(URI source, ICdmDataSource cdmDestination, UUID classificationUuid, String title, DbSchemaValidation hbm2dll){
|
92
|
|
93
|
//make Source
|
94
|
DwcaImportConfigurator config= DwcaImportConfigurator.NewInstance(source, cdmDestination);
|
95
|
config.addObserver(new LoggingIoObserver());
|
96
|
config.setClassificationUuid(classificationUuid);
|
97
|
config.setCheck(check);
|
98
|
config.setDbSchemaValidation(hbm2dll);
|
99
|
config.setMappingType(mappingType);
|
100
|
|
101
|
config.setScientificNameIdAsOriginalSourceId(scientificNameIdAsOriginalSourceId);
|
102
|
config.setValidateRankConsistency(validateRankConsistency);
|
103
|
config.setDefaultPartitionSize(partitionSize);
|
104
|
config.setNomenclaturalCode(defaultNomCode);
|
105
|
config.setDatasetUse(datasetUse);
|
106
|
config.setGuessNomenclaturalReferences(guessNomRef);
|
107
|
config.setHandleAllRefsAsCitation(handleAllRefsAsCitation);
|
108
|
config.setUseSourceReferenceAsSec(useSourceReferenceAsSec);
|
109
|
config.setSourceReferenceTitle(title);
|
110
|
|
111
|
CdmDefaultImport myImport = new CdmDefaultImport();
|
112
|
|
113
|
|
114
|
//...
|
115
|
if (true){
|
116
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
117
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
118
|
myImport.invoke(config);
|
119
|
System.out.println("End import from ("+ source.toString() + ")...");
|
120
|
}
|
121
|
|
122
|
|
123
|
}
|
124
|
|
125
|
private Reference<?> getSourceReference(String string) {
|
126
|
Reference<?> result = ReferenceFactory.newGeneric();
|
127
|
result.setTitleCache(string);
|
128
|
return result;
|
129
|
}
|
130
|
|
131
|
//Dwca
|
132
|
public static URI dwca_emonocots_local() {
|
133
|
URI sourceUrl = URI.create("file:///C:/localCopy/Data/dwca/import/Scratchpads/dwca_dioscoreaceae_emonocots.zip");
|
134
|
return sourceUrl;
|
135
|
}
|
136
|
|
137
|
//emonocots_dioscoreaceae
|
138
|
public static URI dwca_emonocots_dioscoreaceae() {
|
139
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_dioscoreaceae.zip");
|
140
|
return sourceUrl;
|
141
|
}
|
142
|
|
143
|
//emonocots_zingiberaceae
|
144
|
public static URI dwca_emonocots_zingiberaceae() {
|
145
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_zingiberaceae.zip");
|
146
|
return sourceUrl;
|
147
|
}
|
148
|
//emonocots_cypripedioideae
|
149
|
public static URI dwca_emonocots_cypripedioideae() {
|
150
|
URI sourceUrl = URI.create("file:////PESIIMPORT3/vibrant/dwca/dwca_emonocots_cypripedioideae.zip");
|
151
|
return sourceUrl;
|
152
|
}
|
153
|
|
154
|
|
155
|
/**
|
156
|
* @param args
|
157
|
*/
|
158
|
public static void main(String[] args) {
|
159
|
DwcaScratchpadImportActivator me = new DwcaScratchpadImportActivator();
|
160
|
me.doImport(source, cdmDestination, classificationUuid, title, hbm2dll);
|
161
|
}
|
162
|
|
163
|
}
|