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.wp6.palmae;
|
11
|
|
12
|
import java.io.File;
|
13
|
import java.net.URI;
|
14
|
import java.net.URISyntaxException;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
20
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
21
|
import eu.etaxonomy.cdm.app.images.ImageImportConfigurator;
|
22
|
import eu.etaxonomy.cdm.app.tcs.TcsSources;
|
23
|
import eu.etaxonomy.cdm.app.wp6.palmae.config.PalmaeProtologueImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
25
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
26
|
import eu.etaxonomy.cdm.io.PalmaeImageImport;
|
27
|
import eu.etaxonomy.cdm.io.PalmaeProtologueImport;
|
28
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
29
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
30
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
31
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
32
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
33
|
import eu.etaxonomy.cdm.io.tcsrdf.TcsRdfImportConfigurator;
|
34
|
import eu.etaxonomy.cdm.model.description.Feature;
|
35
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
36
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
37
|
|
38
|
/**
|
39
|
* @author a.mueller
|
40
|
* @created 20.06.2008
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class PalmaeActivator {
|
44
|
private static final Logger logger = Logger.getLogger(PalmaeActivator.class);
|
45
|
|
46
|
//database validation status (create, update, validate ...)
|
47
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
48
|
static final String tcsSource = TcsSources.arecaceae_local();
|
49
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Palmae();
|
50
|
|
51
|
// set the webserver path to the images
|
52
|
private static final String imageUrlString = "http://wp5.e-taxonomy.eu/media/palmae/photos/";
|
53
|
// set the webserver path to the protologues
|
54
|
public static final String protologueUrlString = "http://wp5.e-taxonomy.eu/media/palmae/protologe/";
|
55
|
|
56
|
public static final UUID featureTreeUuid = UUID.fromString("72ccce05-7cc8-4dab-8e47-bf3f5fd848a0");
|
57
|
|
58
|
static final UUID treeUuid = UUID.fromString("1adb71d4-cce6-45e1-b578-e668778d9ec6");
|
59
|
static final UUID secUuid = UUID.fromString("5f32b8af-0c97-48ac-8d33-6099ed68c625");
|
60
|
static final String sourceSecId = "palm_pub_ed_999999";
|
61
|
static final boolean pubishReferencesInBibliography = false;
|
62
|
|
63
|
//should the other imports run as well?
|
64
|
static final boolean includeTaxonX = true;
|
65
|
static final boolean includeImages = true;
|
66
|
static final boolean includeExcelProtologue = true;
|
67
|
static final boolean includeMediaProtologue = true;
|
68
|
static final boolean updateFeatureTree = true;
|
69
|
static final boolean updateNameUsage = true;
|
70
|
|
71
|
//check - import
|
72
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
73
|
|
74
|
static boolean useClassification = true;
|
75
|
|
76
|
//authors
|
77
|
static final boolean doAuthors = true;
|
78
|
//references
|
79
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
80
|
//names
|
81
|
static final boolean doTaxonNames = true;
|
82
|
static final boolean doRelNames = true;
|
83
|
|
84
|
//taxa
|
85
|
static final boolean doTaxa = true;
|
86
|
static final boolean doRelTaxa = true;
|
87
|
static final boolean doFacts = true;
|
88
|
|
89
|
|
90
|
private ImportResult doImport(ICdmDataSource destination){
|
91
|
ImportResult success;
|
92
|
System.out.println("Start import from Tcs("+ tcsSource.toString() + ") ...");
|
93
|
|
94
|
//make Source
|
95
|
URI source;
|
96
|
try {
|
97
|
source = new URI(tcsSource);
|
98
|
|
99
|
TcsRdfImportConfigurator tcsImportConfigurator = TcsRdfImportConfigurator.NewInstance(source, destination);
|
100
|
|
101
|
tcsImportConfigurator.setClassificationUuid(treeUuid);
|
102
|
tcsImportConfigurator.setSecUuid(secUuid);
|
103
|
tcsImportConfigurator.setSourceSecId(sourceSecId);
|
104
|
|
105
|
tcsImportConfigurator.setDoReferences(doReferences);
|
106
|
tcsImportConfigurator.setDoTaxonNames(doTaxonNames);
|
107
|
tcsImportConfigurator.setDoRelNames(doRelNames);
|
108
|
|
109
|
tcsImportConfigurator.setDoTaxa(doTaxa);
|
110
|
tcsImportConfigurator.setDoRelTaxa(doRelTaxa);
|
111
|
tcsImportConfigurator.setDoFacts(doFacts);
|
112
|
tcsImportConfigurator.setUseClassification(useClassification);
|
113
|
tcsImportConfigurator.setPublishReferences(pubishReferencesInBibliography);
|
114
|
|
115
|
tcsImportConfigurator.setCheck(check);
|
116
|
tcsImportConfigurator.setDbSchemaValidation(hbm2dll);
|
117
|
|
118
|
// invoke import
|
119
|
CdmDefaultImport<TcsRdfImportConfigurator> tcsImport = new CdmDefaultImport<TcsRdfImportConfigurator>();
|
120
|
success = tcsImport.invoke(tcsImportConfigurator);
|
121
|
|
122
|
//make feature tree
|
123
|
logger.info("Make feature tree");
|
124
|
ICdmApplicationConfiguration app = tcsImport.getCdmAppController();
|
125
|
|
126
|
FeatureTree tree = getFeatureTree();
|
127
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
128
|
System.out.println("End import from TCS ("+ source.toString() + ")...");
|
129
|
|
130
|
return success;
|
131
|
} catch (URISyntaxException e) {
|
132
|
e.printStackTrace();
|
133
|
success = new ImportResult();
|
134
|
success.setSuccess(false);
|
135
|
success.addReport(e.getMessage().getBytes());
|
136
|
return success;
|
137
|
}
|
138
|
|
139
|
}
|
140
|
|
141
|
|
142
|
private FeatureTree getFeatureTree(){
|
143
|
|
144
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
145
|
FeatureNode root = result.getRoot();
|
146
|
|
147
|
FeatureNode newNode;
|
148
|
newNode = FeatureNode.NewInstance(Feature.INTRODUCTION());
|
149
|
root.addChild(newNode);
|
150
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
151
|
root.addChild(newNode);
|
152
|
newNode = FeatureNode.NewInstance(Feature.BIOLOGY_ECOLOGY());
|
153
|
root.addChild(newNode);
|
154
|
newNode = FeatureNode.NewInstance(Feature.CONSERVATION());
|
155
|
root.addChild(newNode);
|
156
|
newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
157
|
root.addChild(newNode);
|
158
|
newNode = FeatureNode.NewInstance(Feature.ETYMOLOGY());
|
159
|
root.addChild(newNode);
|
160
|
newNode = FeatureNode.NewInstance(Feature.USES());
|
161
|
root.addChild(newNode);
|
162
|
newNode = FeatureNode.NewInstance(Feature.CULTIVATION());
|
163
|
root.addChild(newNode);
|
164
|
newNode = FeatureNode.NewInstance(Feature.DISCUSSION());
|
165
|
root.addChild(newNode);
|
166
|
newNode = FeatureNode.NewInstance(Feature.DIAGNOSIS());
|
167
|
root.addChild(newNode);
|
168
|
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
169
|
root.addChild(newNode);
|
170
|
newNode = FeatureNode.NewInstance(Feature.MATERIALS_EXAMINED());
|
171
|
root.addChild(newNode);
|
172
|
newNode = FeatureNode.NewInstance(Feature.ANATOMY());
|
173
|
root.addChild(newNode);
|
174
|
|
175
|
return result;
|
176
|
|
177
|
|
178
|
}
|
179
|
|
180
|
/**
|
181
|
* @param args
|
182
|
*/
|
183
|
public static void main(String[] args) {
|
184
|
ImportResult success;
|
185
|
|
186
|
logger.debug("start");
|
187
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
188
|
|
189
|
PalmaeActivator me = new PalmaeActivator();
|
190
|
me.doImport(destination);
|
191
|
|
192
|
if (includeImages){
|
193
|
System.out.println("Start importing images ...");
|
194
|
CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();
|
195
|
URI folderUri;
|
196
|
try {
|
197
|
folderUri = new URI(PalmaeImageActivator.sourceFolderString);
|
198
|
ImageImportConfigurator imageConfigurator = ImageImportConfigurator.NewInstance(
|
199
|
folderUri, destination, imageUrlString, PalmaeImageImport.class);
|
200
|
imageConfigurator.setSecUuid(secUuid);
|
201
|
success = imageImporter.invoke(imageConfigurator);
|
202
|
System.out.println("End importing images ...");
|
203
|
} catch (URISyntaxException e) {
|
204
|
e.printStackTrace();
|
205
|
}
|
206
|
}
|
207
|
|
208
|
if (includeExcelProtologue){
|
209
|
System.out.println("Start importing protologues ...");
|
210
|
URI fileUri;
|
211
|
try {
|
212
|
fileUri = new URI(PalmaeExcelProtologueActivator.sourceFileString);
|
213
|
ImageImportConfigurator imageConfigurator = ImageImportConfigurator.NewInstance(
|
214
|
fileUri, destination, protologueUrlString, PalmaeProtologueImport.class);
|
215
|
imageConfigurator.setSecUuid(secUuid);
|
216
|
|
217
|
CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();
|
218
|
imageImporter.invoke(imageConfigurator);
|
219
|
System.out.println("End importing protologues ...");
|
220
|
} catch (URISyntaxException e) {
|
221
|
e.printStackTrace();
|
222
|
}
|
223
|
|
224
|
}
|
225
|
if (includeMediaProtologue){
|
226
|
System.out.println("Start importing protologues from \\\\media...");
|
227
|
String protologueSource = PalmaeProtologueImportActivator.protologueSource;
|
228
|
String urlString = protologueUrlString;
|
229
|
|
230
|
File source = new File (protologueSource);
|
231
|
PalmaeProtologueImportConfigurator protologConfig = PalmaeProtologueImportConfigurator.NewInstance(source, destination, urlString);
|
232
|
CdmDefaultImport<IImportConfigurator> cdmImport = new CdmDefaultImport<IImportConfigurator>();
|
233
|
|
234
|
//protologConfig.setDoFacts(doDescriptions);
|
235
|
protologConfig.setCheck(check);
|
236
|
protologConfig.setDbSchemaValidation(DbSchemaValidation.UPDATE);
|
237
|
|
238
|
success = cdmImport.invoke(protologConfig);
|
239
|
|
240
|
System.out.println("End importing protologues ...");
|
241
|
}
|
242
|
|
243
|
if (includeTaxonX){
|
244
|
System.out.println("Start importing taxonX ...");
|
245
|
PalmaeTaxonXImportActivator taxonXimporter = new PalmaeTaxonXImportActivator();
|
246
|
PalmaeTaxonXImportActivator.cdmDestination = destination;
|
247
|
success = taxonXimporter.runImport();
|
248
|
System.out.println("End importing taxonX ...");
|
249
|
}
|
250
|
|
251
|
PalmaePostImportUpdater updater = new PalmaePostImportUpdater();
|
252
|
if (updateFeatureTree){
|
253
|
updater.updateMissingFeatures(destination);
|
254
|
}
|
255
|
|
256
|
if (updateNameUsage){
|
257
|
updater.updateNameUsage(destination);
|
258
|
}
|
259
|
|
260
|
|
261
|
String strSuccess = "";
|
262
|
if (success.isSuccess() == false){
|
263
|
strSuccess = "not ";
|
264
|
}
|
265
|
System.out.println("Import " + strSuccess + "successful");
|
266
|
|
267
|
}
|
268
|
|
269
|
}
|