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.cichorieae;
|
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.ICdmRepository;
|
20
|
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;
|
21
|
import eu.etaxonomy.cdm.app.berlinModelImport.TreeCreator;
|
22
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
23
|
import eu.etaxonomy.cdm.app.images.ImageImportConfigurator;
|
24
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
25
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
26
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
27
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
28
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
29
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
30
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
31
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.EDITOR;
|
32
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
33
|
import eu.etaxonomy.cdm.io.common.Source;
|
34
|
import eu.etaxonomy.cdm.io.wp6.CichorieaeImageImport;
|
35
|
import eu.etaxonomy.cdm.model.common.ISourceable;
|
36
|
import eu.etaxonomy.cdm.model.description.Feature;
|
37
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
38
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
39
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
40
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
41
|
|
42
|
|
43
|
/**
|
44
|
* TODO add the following to a wiki page:
|
45
|
* HINT: If you are about to import into a mysql data base running under windows and if you wish to dump and restore the resulting data bas under another operation systen
|
46
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
47
|
*
|
48
|
*
|
49
|
* @author a.mueller
|
50
|
*
|
51
|
*/
|
52
|
public class CichorieaeActivator {
|
53
|
private static final Logger logger = Logger.getLogger(CichorieaeActivator.class);
|
54
|
|
55
|
//database validation status (create, update, validate ...)
|
56
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
57
|
static final Source berlinModelSource = BerlinModelSources.EDIT_CICHORIEAE();
|
58
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
|
59
|
|
60
|
static final UUID secUuid = UUID.fromString("6924c75d-e0d0-4a6d-afb7-3dd8c71195ca");
|
61
|
static final UUID classificationUuid = UUID.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");
|
62
|
// static final UUID treeUuid = UUID.fromString("00db28a7-50e1-4abc-86ec-b2a8ce870de9");
|
63
|
static final int sourceSecId = 7800000;
|
64
|
|
65
|
static final UUID featureTreeUuid = UUID.fromString("ae9615b8-bc60-4ed0-ad96-897f9226d568");
|
66
|
static final Object[] featureKeyList = new Integer[]{1, 43, 31, 4, 12, 98, 41};
|
67
|
|
68
|
/* --------- MEDIA recources ------------ */
|
69
|
static final boolean stopOnMediaErrors = false;
|
70
|
static final String protologueUrlString = "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";
|
71
|
//Mac
|
72
|
//static final File protologuePath = new File("/Volumes/protolog/protolog/");
|
73
|
//Windows
|
74
|
public static final String imageFolderString = "//media/editwp6/photos";
|
75
|
static final File protologuePath = new File("//media/editwp6/protolog");
|
76
|
// public static final File imageFolder = new File("/media/photos");
|
77
|
// static final File protologuePath = new File("/media/protolog");
|
78
|
/* -------------------------------------- */
|
79
|
|
80
|
// set to zero for unlimited nameFacts
|
81
|
static final int maximumNumberOfNameFacts = 0;
|
82
|
static final int recordsPerTransaction = 2000;
|
83
|
|
84
|
//should the other imports run as well?
|
85
|
static final boolean includeTaraxacum = true;
|
86
|
static final boolean includeImages = false;
|
87
|
|
88
|
|
89
|
//check - import
|
90
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
91
|
|
92
|
//editor - import
|
93
|
static final EDITOR editor = EDITOR.EDITOR_AS_EDITOR;
|
94
|
|
95
|
//NomenclaturalCode
|
96
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
97
|
|
98
|
//ignore null
|
99
|
static final boolean ignoreNull = true;
|
100
|
|
101
|
static boolean useClassification = true;
|
102
|
|
103
|
|
104
|
// **************** ALL *********************
|
105
|
|
106
|
static final boolean doUser = true;
|
107
|
//authors
|
108
|
static final boolean doAuthors = true;
|
109
|
//references
|
110
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
111
|
//names
|
112
|
static final boolean doTaxonNames = true;
|
113
|
static final boolean doRelNames = true;
|
114
|
static final boolean doNameStatus = true;
|
115
|
static final boolean doTypes = true;
|
116
|
static final boolean doNameFacts = true;
|
117
|
|
118
|
//taxa
|
119
|
static final boolean doTaxa = true;
|
120
|
static final boolean doRelTaxa = true;
|
121
|
static final boolean doFacts = false;
|
122
|
static final boolean doOccurences = false;
|
123
|
static final boolean doCommonNames = true;
|
124
|
|
125
|
//etc.
|
126
|
static final boolean doMarker = false;
|
127
|
|
128
|
|
129
|
// **************** SELECTED *********************
|
130
|
//
|
131
|
// static final boolean doUser = false;
|
132
|
// //authors
|
133
|
// static final boolean doAuthors = false;
|
134
|
// //references
|
135
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
136
|
// //names
|
137
|
// static final boolean doTaxonNames = false;
|
138
|
// static final boolean doRelNames = false;
|
139
|
// static final boolean doNameStatus = false;
|
140
|
// static final boolean doTypes = false;
|
141
|
// static final boolean doNameFacts = false;
|
142
|
//
|
143
|
// //taxa
|
144
|
// static final boolean doTaxa = false;
|
145
|
// static final boolean doRelTaxa = false;
|
146
|
// static final boolean doCommonNames = false;
|
147
|
// static final boolean doFacts = false;
|
148
|
// static final boolean doOccurences = false;
|
149
|
//
|
150
|
// //etc.
|
151
|
// static final boolean doMarker = false;
|
152
|
|
153
|
|
154
|
private ImportResult doInvoke(ICdmDataSource destination){
|
155
|
ImportResult success = new ImportResult();
|
156
|
Source source = berlinModelSource;
|
157
|
|
158
|
BerlinModelImportConfigurator bmImportConfigurator = BerlinModelImportConfigurator.NewInstance(source, destination);
|
159
|
|
160
|
bmImportConfigurator.setClassificationUuid(classificationUuid);
|
161
|
bmImportConfigurator.setSourceSecId(sourceSecId);
|
162
|
|
163
|
bmImportConfigurator.setNomenclaturalCode(nomenclaturalCode);
|
164
|
|
165
|
bmImportConfigurator.setIgnoreNull(ignoreNull);
|
166
|
bmImportConfigurator.setDoAuthors(doAuthors);
|
167
|
bmImportConfigurator.setDoReferences(doReferences);
|
168
|
bmImportConfigurator.setDoTaxonNames(doTaxonNames);
|
169
|
bmImportConfigurator.setDoRelNames(doRelNames);
|
170
|
bmImportConfigurator.setDoNameStatus(doNameStatus);
|
171
|
bmImportConfigurator.setDoTypes(doTypes);
|
172
|
bmImportConfigurator.setDoNameFacts(doNameFacts);
|
173
|
bmImportConfigurator.setUseClassification(useClassification);
|
174
|
|
175
|
bmImportConfigurator.setDoTaxa(doTaxa);
|
176
|
bmImportConfigurator.setDoRelTaxa(doRelTaxa);
|
177
|
bmImportConfigurator.setDoFacts(doFacts);
|
178
|
bmImportConfigurator.setDoOccurrence(doOccurences);
|
179
|
bmImportConfigurator.setDoCommonNames(doCommonNames);
|
180
|
|
181
|
bmImportConfigurator.setDoMarker(doMarker);
|
182
|
bmImportConfigurator.setDoUser(doUser);
|
183
|
bmImportConfigurator.setEditor(editor);
|
184
|
bmImportConfigurator.setDbSchemaValidation(hbm2dll);
|
185
|
bmImportConfigurator.setRecordsPerTransaction(recordsPerTransaction);
|
186
|
|
187
|
|
188
|
// protologueResourceLocations
|
189
|
if ( protologuePath.exists() && protologuePath.isDirectory()){
|
190
|
bmImportConfigurator.setMediaUrl(protologueUrlString);
|
191
|
bmImportConfigurator.setMediaPath(protologuePath);
|
192
|
}else{
|
193
|
if(stopOnMediaErrors){
|
194
|
logger.error("Could not configure protologue ResourceLocations -> will quit.");
|
195
|
System.exit(-1);
|
196
|
}
|
197
|
logger.error("Could not configure protologue ResourceLocations");
|
198
|
}
|
199
|
|
200
|
File imageFolder = new File(imageFolderString);
|
201
|
// also check the image source folder
|
202
|
if ( !imageFolder.exists() || !imageFolder.isDirectory()){
|
203
|
if(stopOnMediaErrors){
|
204
|
logger.error("Could not configure imageFolder -> will quit.");
|
205
|
System.exit(-1);
|
206
|
}
|
207
|
logger.error("Could not configure imageFolder");
|
208
|
}
|
209
|
|
210
|
// maximum number of name facts to import
|
211
|
bmImportConfigurator.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
212
|
|
213
|
|
214
|
bmImportConfigurator.setCheck(check);
|
215
|
bmImportConfigurator.setEditor(editor);
|
216
|
|
217
|
// invoke import
|
218
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
219
|
success = bmImport.invoke(bmImportConfigurator);
|
220
|
|
221
|
if (doFacts && (bmImportConfigurator.getCheck().equals(CHECK.CHECK_AND_IMPORT) || bmImportConfigurator.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ) ){
|
222
|
ICdmRepository app = bmImport.getCdmAppController();
|
223
|
ISourceable obj = app.getCommonService().getSourcedObjectByIdInSource(ZoologicalName.class, "1000027", null);
|
224
|
logger.info(obj);
|
225
|
|
226
|
//make feature tree
|
227
|
FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, bmImportConfigurator.getFeatureMap(), featureKeyList);
|
228
|
FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
229
|
tree.getRoot().addChild(imageNode);
|
230
|
FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
231
|
tree.getRoot().addChild(distributionNode, 2);
|
232
|
app.getFeatureTreeService().saveOrUpdate(tree);
|
233
|
}
|
234
|
|
235
|
System.out.println("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
236
|
|
237
|
|
238
|
try {
|
239
|
if (includeTaraxacum) {
|
240
|
System.out.println("Start Taraxacum import from BerlinModel ...");
|
241
|
TaraxacumActivator taraxacumActivator = new TaraxacumActivator();
|
242
|
ImportResult successTaraxacum = taraxacumActivator.doImport(destination, DbSchemaValidation.UPDATE);
|
243
|
success.merge(successTaraxacum);
|
244
|
logger.warn("Taraxacum import still needs to be tested");
|
245
|
System.out.println("End Taraxacum import from BerlinModel ...");
|
246
|
}
|
247
|
} catch (Exception e) {
|
248
|
success.addException(e);
|
249
|
logger.error("Exception occurred during Taraxacum import.");
|
250
|
e.printStackTrace();
|
251
|
}
|
252
|
|
253
|
|
254
|
|
255
|
if (includeImages) {
|
256
|
System.out.println("Start importing images ...");
|
257
|
CdmDefaultImport<IImportConfigurator> imageImporter = new CdmDefaultImport<IImportConfigurator>();
|
258
|
URI imageFolderCichorieae;
|
259
|
try {
|
260
|
imageFolderCichorieae = new URI(CichorieaeActivator.imageFolderString);
|
261
|
ImageImportConfigurator imageConfigurator = ImageImportConfigurator.NewInstance(
|
262
|
imageFolderCichorieae, destination, CichorieaeImageImport.class);
|
263
|
imageConfigurator.setSecUuid(secUuid);
|
264
|
imageConfigurator.setClassificationUuid(classificationUuid);
|
265
|
ImportResult resultImageImport = imageImporter.invoke(imageConfigurator);
|
266
|
success.merge(resultImageImport);
|
267
|
} catch (URISyntaxException e) {
|
268
|
e.printStackTrace();
|
269
|
}
|
270
|
System.out.println("End importing images ...");
|
271
|
}
|
272
|
logger.warn("!!!! NOTE: RefDetail notes and RelPTaxon notes are not imported automatically. Please check for these notes and import them manually.");
|
273
|
|
274
|
return success;
|
275
|
|
276
|
}
|
277
|
|
278
|
/**
|
279
|
* @param args
|
280
|
*/
|
281
|
public static void main(String[] args) {
|
282
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
283
|
|
284
|
System.out.println("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + destination.getDatabase() + " ...");
|
285
|
CichorieaeActivator me = new CichorieaeActivator();
|
286
|
me.doInvoke(destination);
|
287
|
|
288
|
}
|
289
|
|
290
|
}
|