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.util.Set;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.log4j.Logger;
|
17
|
import org.springframework.transaction.TransactionStatus;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
20
|
import eu.etaxonomy.cdm.app.berlinModelImport.BerlinModelSources;
|
21
|
import eu.etaxonomy.cdm.app.common.CdmDestinations;
|
22
|
import eu.etaxonomy.cdm.database.DbSchemaValidation;
|
23
|
import eu.etaxonomy.cdm.database.ICdmDataSource;
|
24
|
import eu.etaxonomy.cdm.io.berlinModel.in.BerlinModelImportConfigurator;
|
25
|
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
|
26
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
27
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.DO_REFERENCES;
|
28
|
import eu.etaxonomy.cdm.io.common.ImportResult;
|
29
|
import eu.etaxonomy.cdm.io.common.Source;
|
30
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
31
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
32
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
33
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
34
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
35
|
|
36
|
|
37
|
/**
|
38
|
* TODO add the following to a wiki page:
|
39
|
* 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
|
40
|
* you must set the mysql system variable lower_case_table_names = 0 in order to create data base with table compatible names.
|
41
|
*
|
42
|
*
|
43
|
* @author a.mueller
|
44
|
*
|
45
|
*/
|
46
|
public class TaraxacumActivator {
|
47
|
private static final Logger logger = Logger.getLogger(TaraxacumActivator.class);
|
48
|
|
49
|
//database validation status (create, update, validate ...)
|
50
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.UPDATE;
|
51
|
static final Source berlinModelSource = BerlinModelSources.EDIT_Taraxacum();
|
52
|
static final ICdmDataSource cdmDestination = CdmDestinations.localH2Cichorieae();
|
53
|
|
54
|
static final UUID treeUuid = UUID.fromString("019c4b4d-736b-4d2e-883c-e3244167080a");
|
55
|
// static final UUID treeUuid = UUID.fromString("00db28a7-50e1-4abc-86ec-b2a8ce870de9");
|
56
|
// static final UUID treeUuid = UUID.fromString("534e190f-3339-49ba-95d9-fa27d5493e3e");
|
57
|
static final int sourceSecId = 7800000;
|
58
|
|
59
|
static final UUID featureTreeUuid = UUID.fromString("ab007336-d853-4f2f-a490-7c8232eafe7b");
|
60
|
static final Object[] featureKeyList = new Integer[]{1, 31, 4, 98, 41};
|
61
|
|
62
|
//TODO update for Taraxacum
|
63
|
static final String mediaUrlString = "http://wp5.e-taxonomy.eu/dataportal/cichorieae/media/protolog/";
|
64
|
//Mac
|
65
|
//static final File mediaPath = new File("/Volumes/protolog/protolog/");
|
66
|
//Windows
|
67
|
//static final File mediaPath = new File("\\\\media\\editwp6\\protolog");
|
68
|
// set to zero for unlimited nameFacts
|
69
|
static final int maximumNumberOfNameFacts = 0;
|
70
|
|
71
|
|
72
|
//check - import
|
73
|
//static final CHECK check = CHECK.CHECK_ONLY;
|
74
|
static final CHECK check = CHECK.CHECK_AND_IMPORT;
|
75
|
|
76
|
//NomenclaturalCode
|
77
|
static final NomenclaturalCode nomenclaturalCode = NomenclaturalCode.ICNAFP;
|
78
|
|
79
|
//ignore null
|
80
|
static final boolean ignoreNull = true;
|
81
|
|
82
|
|
83
|
// **************** ALL *********************
|
84
|
//authors
|
85
|
static final boolean doAuthors = true;
|
86
|
//references
|
87
|
static final DO_REFERENCES doReferences = DO_REFERENCES.ALL;
|
88
|
//names
|
89
|
static final boolean doTaxonNames = true;
|
90
|
static final boolean doRelNames = true;
|
91
|
static final boolean doNameStatus = true;
|
92
|
static final boolean doTypes = true;
|
93
|
static final boolean doNameFacts = true;
|
94
|
|
95
|
//taxa
|
96
|
static final boolean doTaxa = true;
|
97
|
static final boolean doRelTaxa = true;
|
98
|
static final boolean doFacts = false;
|
99
|
static final boolean doOccurences = false;
|
100
|
static final boolean doCommonNames = true;
|
101
|
|
102
|
|
103
|
// **************** SELECTED *********************
|
104
|
//
|
105
|
// //authors
|
106
|
// static final boolean doAuthors = false;
|
107
|
// //references
|
108
|
// static final DO_REFERENCES doReferences = DO_REFERENCES.NONE;
|
109
|
// //names
|
110
|
// static final boolean doTaxonNames = false;
|
111
|
// static final boolean doRelNames = false;
|
112
|
// static final boolean doNameStatus = false;
|
113
|
// static final boolean doTypes = false;
|
114
|
// static final boolean doNameFacts = false;
|
115
|
//
|
116
|
// //taxa
|
117
|
// static final boolean doTaxa = false;
|
118
|
// static final boolean doRelTaxa = false;
|
119
|
// static final boolean doFacts = false;
|
120
|
// static final boolean doOccurences = false;
|
121
|
|
122
|
/**
|
123
|
* @param args
|
124
|
*/
|
125
|
public ImportResult doImport(ICdmDataSource destination, DbSchemaValidation hbm2dll) {
|
126
|
ImportResult success;
|
127
|
logger.info("Start import from BerlinModel("+ berlinModelSource.getDatabase() + ") to " + cdmDestination.getDatabase() + " ...");
|
128
|
|
129
|
//make BerlinModel Source
|
130
|
Source source = berlinModelSource;
|
131
|
|
132
|
BerlinModelImportConfigurator bmImportConfigurator = BerlinModelImportConfigurator.NewInstance(source, destination);
|
133
|
|
134
|
bmImportConfigurator.setClassificationUuid(treeUuid);
|
135
|
// bmImportConfigurator.setSecUuid(secUuid);
|
136
|
bmImportConfigurator.setSourceSecId(sourceSecId);
|
137
|
|
138
|
bmImportConfigurator.setNomenclaturalCode(nomenclaturalCode);
|
139
|
|
140
|
bmImportConfigurator.setIgnoreNull(ignoreNull);
|
141
|
bmImportConfigurator.setDoAuthors(doAuthors);
|
142
|
bmImportConfigurator.setDoReferences(doReferences);
|
143
|
bmImportConfigurator.setDoTaxonNames(doTaxonNames);
|
144
|
bmImportConfigurator.setDoRelNames(doRelNames);
|
145
|
bmImportConfigurator.setDoNameStatus(doNameStatus);
|
146
|
bmImportConfigurator.setDoTypes(doTypes);
|
147
|
bmImportConfigurator.setDoNameFacts(doNameFacts);
|
148
|
|
149
|
bmImportConfigurator.setDoTaxa(doTaxa);
|
150
|
bmImportConfigurator.setDoRelTaxa(doRelTaxa);
|
151
|
bmImportConfigurator.setDoFacts(doFacts);
|
152
|
bmImportConfigurator.setDoOccurrence(doOccurences);
|
153
|
bmImportConfigurator.setDoCommonNames(doCommonNames);
|
154
|
|
155
|
bmImportConfigurator.setDbSchemaValidation(hbm2dll);
|
156
|
|
157
|
|
158
|
// mediaResourceLocations
|
159
|
File mediaPath = CichorieaeActivator.protologuePath;
|
160
|
if ( mediaPath.exists() && mediaPath.isDirectory()){
|
161
|
bmImportConfigurator.setMediaUrl(mediaUrlString);
|
162
|
bmImportConfigurator.setMediaPath(mediaPath);
|
163
|
}else{
|
164
|
logger.warn("Could not configure mediaResourceLocations");
|
165
|
}
|
166
|
|
167
|
// maximum number of name facts to import
|
168
|
bmImportConfigurator.setMaximumNumberOfNameFacts(maximumNumberOfNameFacts);
|
169
|
|
170
|
|
171
|
bmImportConfigurator.setCheck(check);
|
172
|
|
173
|
// invoke import
|
174
|
CdmDefaultImport<BerlinModelImportConfigurator> bmImport = new CdmDefaultImport<BerlinModelImportConfigurator>();
|
175
|
success = bmImport.invoke(bmImportConfigurator);
|
176
|
|
177
|
if (bmImportConfigurator.getCheck().equals(CHECK.CHECK_AND_IMPORT) || bmImportConfigurator.getCheck().equals(CHECK.IMPORT_WITHOUT_CHECK) ){
|
178
|
ICdmRepository app = bmImport.getCdmAppController();
|
179
|
TransactionStatus tx = app.startTransaction();
|
180
|
//make feature tree
|
181
|
// FeatureTree tree = TreeCreator.flatTree(featureTreeUuid, bmImportConfigurator.getFeatureMap(), featureKeyList);
|
182
|
// FeatureNode imageNode = FeatureNode.NewInstance(Feature.IMAGE());
|
183
|
// tree.getRoot().addChild(imageNode);
|
184
|
// FeatureNode distributionNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
185
|
// FeatureNode featureNode = tree.getRoot();
|
186
|
// tree.getRoot().addChild(distributionNode, featureNode.getChildCount() + 1);
|
187
|
// app.getTermTreeService().saveOrUpdate(tree);
|
188
|
mergeIntoCichorieae(app);
|
189
|
app.commitTransaction(tx);
|
190
|
}
|
191
|
|
192
|
logger.info("End import from BerlinModel ("+ source.getDatabase() + ")...");
|
193
|
return success;
|
194
|
}
|
195
|
|
196
|
|
197
|
public boolean mergeIntoCichorieae(ICdmRepository app){
|
198
|
boolean success = true;
|
199
|
// String taraxTaraxacumUuidStr = "9a7bced0-fa1a-432e-9cca-57b62219cde6";
|
200
|
String taraxTaraxacumUuidStr = "b86f1156-091c-494d-a9c9-c84d71058f98";
|
201
|
UUID taraxTaraxacumUUID = UUID.fromString(taraxTaraxacumUuidStr);
|
202
|
|
203
|
String cichTaraxacumUuidStr = "c946ac62-b6c6-493b-8ed9-278fa38b931a";
|
204
|
UUID cichTaraxacumUUID = UUID.fromString(cichTaraxacumUuidStr);
|
205
|
|
206
|
Taxon taraxacumInCichTaxon = (Taxon)app.getTaxonService().find(cichTaraxacumUUID);
|
207
|
if (taraxacumInCichTaxon != null) {
|
208
|
logger.info("Merge Taraxacum");
|
209
|
Set<TaxonNode> taxonNodesInCich = taraxacumInCichTaxon.getTaxonNodes();
|
210
|
TaxonNode taxonNodeInCich = null;
|
211
|
TaxonNode parentNodeInCich = null;
|
212
|
Taxon parentInCich = null;
|
213
|
TaxonNode taxonNodeInTarax = null;
|
214
|
|
215
|
if (taxonNodesInCich == null || taxonNodesInCich.isEmpty()) {
|
216
|
logger.error("No taxon nodes found for Taraxacum in cichorieae database");
|
217
|
success = false;
|
218
|
} else {
|
219
|
logger.info(taxonNodesInCich.size()+ " taxon node(s) found for Taraxacum in Cich DB");
|
220
|
taxonNodeInCich = taxonNodesInCich.iterator().next();
|
221
|
parentNodeInCich = taxonNodeInCich.getParent();
|
222
|
parentInCich = parentNodeInCich.getTaxon();
|
223
|
}
|
224
|
|
225
|
Taxon taraxacumInTaraxTaxon = (Taxon)app.getTaxonService().find(taraxTaraxacumUUID);
|
226
|
|
227
|
Set<TaxonNode> taxonNodesInTarax = taraxacumInTaraxTaxon.getTaxonNodes();
|
228
|
|
229
|
Classification treeInTaraxacum = null;
|
230
|
if (taxonNodesInTarax == null || taxonNodesInTarax.isEmpty()) {
|
231
|
logger.warn("No taxon nodes found for Taraxacum in taraxacum database");
|
232
|
success = false;
|
233
|
}else{
|
234
|
taxonNodeInTarax = taxonNodesInTarax.iterator().next();
|
235
|
treeInTaraxacum = taxonNodeInTarax.getClassification();
|
236
|
}
|
237
|
|
238
|
//TODO reference
|
239
|
Reference citation = null;
|
240
|
String microcitation = null;
|
241
|
|
242
|
taxonNodeInTarax = parentNodeInCich.addChildNode(taxonNodeInTarax, citation, microcitation);
|
243
|
//parentNodeInCich.getClassification().addParentChild(parentInCich, taraxacumInTaraxTaxon, null, null);
|
244
|
|
245
|
parentNodeInCich.deleteChildNode(taxonNodeInCich);
|
246
|
|
247
|
app.getTaxonService().save(parentInCich);
|
248
|
|
249
|
app.getTaxonService().delete(taraxacumInCichTaxon);
|
250
|
|
251
|
|
252
|
try {
|
253
|
// app.getClassificationService().delete(treeInTaraxacum); //throws exception
|
254
|
} catch (Exception e) {
|
255
|
e.printStackTrace();
|
256
|
return false;
|
257
|
}
|
258
|
}else{
|
259
|
logger.warn("Taraxacum in cichorieae not found");
|
260
|
success = false;
|
261
|
}
|
262
|
return success;
|
263
|
}
|
264
|
|
265
|
public static void main(String[] args) {
|
266
|
TaraxacumActivator ta = new TaraxacumActivator();
|
267
|
ICdmDataSource destination = CdmDestinations.chooseDestination(args) != null ? CdmDestinations.chooseDestination(args) : cdmDestination;
|
268
|
|
269
|
ta.doImport(destination, hbm2dll);
|
270
|
|
271
|
}
|
272
|
|
273
|
}
|