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