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.cuba;
|
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.api.service.ITermService;
|
19
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
20
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
21
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
22
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
23
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
24
|
import eu.etaxonomy.cdm.io.cuba.CubaImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.model.agent.Person;
|
26
|
import eu.etaxonomy.cdm.model.description.Feature;
|
27
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
28
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
* @created 04.01.2016
|
35
|
*/
|
36
|
public class CubaActivator {
|
37
|
private static final Logger logger = Logger.getLogger(CubaActivator.class);
|
38
|
|
39
|
//database validation status (create, update, validate ...)
|
40
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
41
|
|
42
|
boolean invers = true;
|
43
|
boolean include = !invers;
|
44
|
|
45
|
boolean doAsteraceae = include;
|
46
|
boolean doConvolvulaceae = include;
|
47
|
boolean doCyperaceae = ! include;
|
48
|
boolean doDicotA_C = include;
|
49
|
boolean doDicotD_M = include;
|
50
|
boolean doDicotN_Z = include;
|
51
|
boolean doEuphorbiaceae = include;
|
52
|
boolean doFabaceae = ! include;
|
53
|
boolean doGymnospermae = include;
|
54
|
boolean doLamVerbenaceae = include;
|
55
|
boolean doMalpighiaceae = ! include;
|
56
|
boolean doMelastomataceae = ! include;
|
57
|
boolean doMonocots = ! include ;
|
58
|
boolean doMyrtaceae = include;
|
59
|
boolean doOrchidaceae = include;
|
60
|
boolean doRubiaceae = include;
|
61
|
boolean doUrticaceae = ! include;
|
62
|
|
63
|
|
64
|
|
65
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
66
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
67
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev();
|
68
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cuba_production();
|
69
|
|
70
|
|
71
|
//feature tree uuid
|
72
|
public static final UUID featureTreeUuid = UUID.fromString("dad6b9b5-693f-4367-a7aa-076cc9c99476");
|
73
|
|
74
|
//classification
|
75
|
static final UUID classificationUuid = UUID.fromString("5de394de-9c76-4b97-b04d-71be31c7f44b");
|
76
|
private static final String classificationName = "Flora of Cuba";
|
77
|
|
78
|
static final String sourceReferenceTitle = "Cuba import";
|
79
|
|
80
|
//check - import
|
81
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
82
|
|
83
|
boolean doVocabularies = (hbm2dll == DbSchemaValidation.CREATE);
|
84
|
static final boolean doTaxa = true;
|
85
|
static final boolean doDeduplicate = false;
|
86
|
|
87
|
|
88
|
private void doImport(ICdmDataSource cdmDestination){
|
89
|
|
90
|
URI source = monocots(); //just any
|
91
|
|
92
|
//make Source
|
93
|
CubaImportConfigurator config= CubaImportConfigurator.NewInstance(source, cdmDestination);
|
94
|
config.setClassificationUuid(classificationUuid);
|
95
|
config.setClassificationName(classificationName);
|
96
|
config.setCheck(check);
|
97
|
// config.setDoDistribution(doDistribution);
|
98
|
config.setDoTaxa(doTaxa);
|
99
|
config.setDbSchemaValidation(hbm2dll);
|
100
|
config.setSourceReferenceTitle(sourceReferenceTitle);
|
101
|
config.setDoVocabularies(doVocabularies);
|
102
|
|
103
|
CdmDefaultImport<CubaImportConfigurator> myImport = new CdmDefaultImport<CubaImportConfigurator>();
|
104
|
|
105
|
|
106
|
//...
|
107
|
if (doAsteraceae){
|
108
|
doSource(asteraceae(), config, myImport, doVocabularies);
|
109
|
}
|
110
|
if (doConvolvulaceae){
|
111
|
doSource(convolvulaceae(), config, myImport, doVocabularies);
|
112
|
}
|
113
|
if (doCyperaceae){
|
114
|
doSource(cyperaceae(), config, myImport, doVocabularies);
|
115
|
}
|
116
|
if (doDicotA_C){
|
117
|
doSource(dicotA_C(), config, myImport, doVocabularies);
|
118
|
}
|
119
|
if (doDicotD_M){
|
120
|
doSource(dicotD_M(), config, myImport, doVocabularies);
|
121
|
}
|
122
|
if (doDicotN_Z){
|
123
|
doSource(dicotN_Z(), config, myImport, doVocabularies);
|
124
|
}
|
125
|
if (doEuphorbiaceae){
|
126
|
doSource(euphorbiaceae(), config, myImport, doVocabularies);
|
127
|
}
|
128
|
if (doFabaceae){
|
129
|
doSource(fabaceae(), config, myImport, doVocabularies);
|
130
|
}
|
131
|
if (doGymnospermae){
|
132
|
doSource(gymnospermae(), config, myImport, doVocabularies);
|
133
|
}
|
134
|
if (doLamVerbenaceae){
|
135
|
doSource(lamVerbenaceae(), config, myImport, doVocabularies);
|
136
|
}
|
137
|
if (doMalpighiaceae){
|
138
|
doSource(malpighiaceae(), config, myImport, doVocabularies);
|
139
|
}
|
140
|
if (doMelastomataceae){
|
141
|
doSource(melastomataceae(), config, myImport, doVocabularies);
|
142
|
}
|
143
|
if (doMonocots){
|
144
|
doSource(monocots(), config, myImport, doVocabularies);
|
145
|
}
|
146
|
if (doMyrtaceae){
|
147
|
doSource(myrtaceae(), config, myImport, doVocabularies);
|
148
|
}
|
149
|
if (doOrchidaceae){
|
150
|
doSource(orchidaceae(), config, myImport, doVocabularies);
|
151
|
}
|
152
|
if (doRubiaceae){
|
153
|
doSource(rubiaceae(), config, myImport, doVocabularies);
|
154
|
}
|
155
|
if (doUrticaceae){
|
156
|
doSource(urticaceae(), config, myImport, doVocabularies);
|
157
|
}
|
158
|
|
159
|
|
160
|
|
161
|
//deduplicate
|
162
|
if (doDeduplicate){
|
163
|
ICdmApplicationConfiguration app = myImport.getCdmAppController();
|
164
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
165
|
logger.warn("Deduplicated " + count + " persons.");
|
166
|
// count = app.getAgentService().deduplicate(Team.class, null, null);
|
167
|
// logger.warn("Deduplicated " + count + " teams.");
|
168
|
count = app.getReferenceService().deduplicate(Reference.class, null, null);
|
169
|
logger.warn("Deduplicated " + count + " references.");
|
170
|
}
|
171
|
|
172
|
|
173
|
System.exit(0);
|
174
|
|
175
|
}
|
176
|
|
177
|
/**
|
178
|
* @param source
|
179
|
* @param config
|
180
|
* @param myImport
|
181
|
*/
|
182
|
private void doSource(URI source, CubaImportConfigurator config,
|
183
|
CdmDefaultImport<CubaImportConfigurator> myImport, boolean doVocabularies) {
|
184
|
config.setSource(source);
|
185
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
186
|
config.setSourceReference(getSourceReference(sourceReferenceTitle));
|
187
|
config.setDoVocabularies(false);
|
188
|
myImport.invoke(config);
|
189
|
|
190
|
if (doVocabularies){
|
191
|
FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
|
192
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
193
|
this.doVocabularies = false;
|
194
|
}
|
195
|
System.out.println("End import from ("+ source.toString() + ")...");
|
196
|
}
|
197
|
|
198
|
private Reference<?> getSourceReference(String string) {
|
199
|
Reference<?> result = ReferenceFactory.newGeneric();
|
200
|
result.setTitleCache(string, true);
|
201
|
return result;
|
202
|
}
|
203
|
|
204
|
private FeatureTree makeFeatureNodes(ITermService service){
|
205
|
// CyprusTransformer transformer = new CyprusTransformer();
|
206
|
|
207
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
208
|
result.setTitleCache("Cuba Feature Tree", true);
|
209
|
FeatureNode root = result.getRoot();
|
210
|
FeatureNode newNode;
|
211
|
|
212
|
// newNode = FeatureNode.NewInstance(Feature.STATUS());
|
213
|
// root.addChild(newNode);
|
214
|
|
215
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
216
|
root.addChild(newNode);
|
217
|
|
218
|
// newNode = FeatureNode.NewInstance(Feature.SYSTEMATICS());
|
219
|
// root.addChild(newNode);
|
220
|
|
221
|
//user defined features
|
222
|
// String [] featureList = new String[]{"Red Book", "Endemism"};
|
223
|
// addFeataureNodesByStringList(featureList, root, transformer, service);
|
224
|
|
225
|
return result;
|
226
|
}
|
227
|
|
228
|
|
229
|
//Monocots
|
230
|
public static URI monocots() {
|
231
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Monocot.xlsx");
|
232
|
}
|
233
|
//Cyperaceae
|
234
|
public static URI cyperaceae() {
|
235
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Cyper_Poaceae.xlsx");
|
236
|
}
|
237
|
//Fabaceae
|
238
|
public static URI fabaceae() {
|
239
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Fabaceae.xlsx");
|
240
|
}
|
241
|
//Urticaceae
|
242
|
public static URI urticaceae() {
|
243
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Urticaceae.xlsx");
|
244
|
}
|
245
|
//Asteraceae
|
246
|
public static URI asteraceae() {
|
247
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Asteraceae.xlsx");
|
248
|
}
|
249
|
//Convolvulaceae
|
250
|
public static URI convolvulaceae() {
|
251
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Convolvulaceae.xlsx");
|
252
|
}
|
253
|
//dicot A-C
|
254
|
public static URI dicotA_C() {
|
255
|
return URI.create("file:////BGBM-PESIHPC/Cuba/dicotA_C.xlsx");
|
256
|
}
|
257
|
//dicot D-M
|
258
|
public static URI dicotD_M() {
|
259
|
return URI.create("file:////BGBM-PESIHPC/Cuba/dicotD_M.xlsx");
|
260
|
}
|
261
|
//dicot N-Z
|
262
|
public static URI dicotN_Z() {
|
263
|
return URI.create("file:////BGBM-PESIHPC/Cuba/dicotN_Z.xlsx");
|
264
|
}
|
265
|
//Euphorbiaceae
|
266
|
public static URI euphorbiaceae() {
|
267
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Euphorbiaceae.xlsx");
|
268
|
}
|
269
|
//Gymnospermae
|
270
|
public static URI gymnospermae() {
|
271
|
return URI.create("file:////BGBM-PESIHPC/Cuba/gymnospermae.xlsx");
|
272
|
}
|
273
|
//Lam.Verbenaceae
|
274
|
public static URI lamVerbenaceae() {
|
275
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Lam_Verbenaceae.xlsx");
|
276
|
}
|
277
|
//Malpighiaceae
|
278
|
public static URI malpighiaceae() {
|
279
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Malpighiaceae.xlsx");
|
280
|
}
|
281
|
//Melastomataceae
|
282
|
public static URI melastomataceae() {
|
283
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Melastomataceae.xlsx");
|
284
|
}
|
285
|
//Myrtaceae
|
286
|
public static URI myrtaceae() {
|
287
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Myrtaceae.xlsx");
|
288
|
}
|
289
|
//Orchidaceae
|
290
|
public static URI orchidaceae() {
|
291
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Orchidaceae.xlsx");
|
292
|
}
|
293
|
//Rubiaceae
|
294
|
public static URI rubiaceae() {
|
295
|
return URI.create("file:////BGBM-PESIHPC/Cuba/Rubiaceae.xlsx");
|
296
|
}
|
297
|
|
298
|
/**
|
299
|
* @param args
|
300
|
*/
|
301
|
public static void main(String[] args) {
|
302
|
CubaActivator me = new CubaActivator();
|
303
|
me.doImport(cdmDestination);
|
304
|
}
|
305
|
|
306
|
}
|