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.eflora;
|
11
|
|
12
|
import java.net.URI;
|
13
|
import java.util.List;
|
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.CdmApplicationController;
|
20
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
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.common.CdmDefaultImport;
|
25
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
|
26
|
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
|
27
|
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
|
28
|
import eu.etaxonomy.cdm.io.eflora.EfloraImportConfigurator;
|
29
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeImportConfigurator;
|
30
|
import eu.etaxonomy.cdm.io.eflora.centralAfrica.ericaceae.CentralAfricaEricaceaeTransformer;
|
31
|
import eu.etaxonomy.cdm.model.agent.Person;
|
32
|
import eu.etaxonomy.cdm.model.agent.Team;
|
33
|
import eu.etaxonomy.cdm.model.common.Language;
|
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
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
38
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
39
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
40
|
|
41
|
/**
|
42
|
* @author a.mueller
|
43
|
* @created 20.06.2008
|
44
|
* @version 1.0
|
45
|
*/
|
46
|
public class CentralAfricaEricaceaeActivator {
|
47
|
private static final Logger logger = Logger.getLogger(CentralAfricaEricaceaeActivator.class);
|
48
|
|
49
|
//database validation status (create, update, validate ...)
|
50
|
static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
|
51
|
static final URI source = EfloraSources.ericacea_local();
|
52
|
|
53
|
|
54
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM();
|
55
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_preview();
|
56
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_central_africa_production();
|
57
|
// static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
|
58
|
static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
59
|
|
60
|
// static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_postgres_CdmTest();
|
61
|
|
62
|
//feature tree uuid
|
63
|
public static final UUID featureTreeUuid = UUID.fromString("051d35ee-22f1-42d8-be07-9e9bfec5bcf7");
|
64
|
|
65
|
public static UUID defaultLanguageUuid = Language.uuidEnglish;
|
66
|
|
67
|
//classification
|
68
|
static final UUID classificationUuid = UUID.fromString("10e5efcc-6e13-4abc-ad42-e0b46e50cbe7");
|
69
|
|
70
|
//check - import
|
71
|
static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
|
72
|
|
73
|
static boolean doPrintKeys = false;
|
74
|
|
75
|
//taxa
|
76
|
static final boolean doTaxa = true;
|
77
|
static final boolean doDeduplicate = false;
|
78
|
|
79
|
private boolean includeEricaceae = true;
|
80
|
|
81
|
|
82
|
|
83
|
private void doImport(ICdmDataSource cdmDestination){
|
84
|
|
85
|
//make Source
|
86
|
CentralAfricaEricaceaeImportConfigurator config= CentralAfricaEricaceaeImportConfigurator.NewInstance(source, cdmDestination);
|
87
|
config.setTaxonomicTreeUuid(classificationUuid);
|
88
|
config.setDoTaxa(doTaxa);
|
89
|
config.setCheck(check);
|
90
|
config.setDefaultLanguageUuid(defaultLanguageUuid);
|
91
|
config.setDoPrintKeys(doPrintKeys);
|
92
|
config.setDbSchemaValidation(hbm2dll);
|
93
|
|
94
|
CdmDefaultImport<EfloraImportConfigurator> myImport = new CdmDefaultImport<EfloraImportConfigurator>();
|
95
|
|
96
|
|
97
|
//Ericaceae
|
98
|
if (includeEricaceae){
|
99
|
System.out.println("Start import from ("+ source.toString() + ") ...");
|
100
|
config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
|
101
|
myImport.invoke(config);
|
102
|
System.out.println("End import from ("+ source.toString() + ")...");
|
103
|
}
|
104
|
|
105
|
FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
|
106
|
myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
|
107
|
|
108
|
//check keys
|
109
|
if (doPrintKeys){
|
110
|
TransactionStatus tx = myImport.getCdmAppController().startTransaction();
|
111
|
List<FeatureTree> keys = myImport.getCdmAppController().getFeatureTreeService().list(PolytomousKey.class, null, null, null, null);
|
112
|
for(FeatureTree key : keys){
|
113
|
((PolytomousKey)key).print(System.out);
|
114
|
System.out.println();
|
115
|
}
|
116
|
myImport.getCdmAppController().commitTransaction(tx);
|
117
|
}
|
118
|
|
119
|
//deduplicate
|
120
|
if (doDeduplicate){
|
121
|
CdmApplicationController app = myImport.getCdmAppController();
|
122
|
int count = app.getAgentService().deduplicate(Person.class, null, null);
|
123
|
logger.warn("Deduplicated " + count + " persons.");
|
124
|
count = app.getAgentService().deduplicate(Team.class, null, null);
|
125
|
logger.warn("Deduplicated " + count + " teams.");
|
126
|
count = app.getReferenceService().deduplicate(ReferenceBase.class, null, null);
|
127
|
logger.warn("Deduplicated " + count + " references.");
|
128
|
}
|
129
|
}
|
130
|
|
131
|
private ReferenceBase getSourceReference(String string) {
|
132
|
ReferenceBase result = ReferenceFactory.newGeneric();
|
133
|
result.setTitleCache(string);
|
134
|
return result;
|
135
|
}
|
136
|
|
137
|
private FeatureTree makeFeatureNode(ITermService service){
|
138
|
CentralAfricaEricaceaeTransformer transformer = new CentralAfricaEricaceaeTransformer();
|
139
|
|
140
|
FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
|
141
|
result.setTitleCache("Central Africa Ericaceae Feature Tree");
|
142
|
FeatureNode root = result.getRoot();
|
143
|
FeatureNode newNode;
|
144
|
|
145
|
newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
|
146
|
root.addChild(newNode);
|
147
|
|
148
|
addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
|
149
|
|
150
|
addFeataureNodesByStringList(generellDescriptionsList, root, transformer, service);
|
151
|
|
152
|
|
153
|
newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
|
154
|
root.addChild(newNode);
|
155
|
|
156
|
newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
|
157
|
root.addChild(newNode);
|
158
|
addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
|
159
|
|
160
|
newNode = FeatureNode.NewInstance(Feature.USES());
|
161
|
root.addChild(newNode);
|
162
|
|
163
|
addFeataureNodesByStringList(chomosomesList, root, transformer, service);
|
164
|
|
165
|
newNode = FeatureNode.NewInstance(Feature.COMMON_NAME());
|
166
|
root.addChild(newNode);
|
167
|
|
168
|
newNode = FeatureNode.NewInstance(Feature.CITATION());
|
169
|
root.addChild(newNode);
|
170
|
|
171
|
return result;
|
172
|
}
|
173
|
|
174
|
private static String [] chomosomesList = new String[]{
|
175
|
"Chromosomes",
|
176
|
};
|
177
|
|
178
|
|
179
|
private static String [] habitatEcologyList = new String[]{
|
180
|
"Habitat",
|
181
|
"Habitat & Ecology"
|
182
|
};
|
183
|
|
184
|
|
185
|
private static String [] generellDescriptionsList = new String[]{
|
186
|
"Fossils",
|
187
|
"Morphology and anatomy",
|
188
|
"Morphology",
|
189
|
"Vegetative morphology and anatomy",
|
190
|
"Flower morphology",
|
191
|
"Palynology",
|
192
|
"Pollination",
|
193
|
"Pollen morphology",
|
194
|
"Life cycle",
|
195
|
"Fruits and embryology",
|
196
|
"Dispersal",
|
197
|
"Wood anatomy",
|
198
|
"Leaf anatomy",
|
199
|
"Chromosome numbers",
|
200
|
"Phytochemistry and Chemotaxonomy",
|
201
|
"Phytochemistry",
|
202
|
"Taxonomy",
|
203
|
};
|
204
|
|
205
|
private static String [] descriptionFeatureList = new String[]{
|
206
|
"lifeform",
|
207
|
"Bark",
|
208
|
"Indumentum",
|
209
|
"endophytic body",
|
210
|
"flowering buds",
|
211
|
"Branchlets",
|
212
|
"Branches",
|
213
|
"Branch",
|
214
|
"Flowering branchlets",
|
215
|
"Trees",
|
216
|
"Twigs",
|
217
|
"stem",
|
218
|
"Stems",
|
219
|
"stem leaves",
|
220
|
"Leaves",
|
221
|
"flower-bearing stems",
|
222
|
"Petiole",
|
223
|
"Petiolules",
|
224
|
"Leaflets",
|
225
|
"Thyrsus",
|
226
|
"Thyrses",
|
227
|
"Inflorescences",
|
228
|
"Inflorescence",
|
229
|
"Young inflorescences",
|
230
|
"Bracts",
|
231
|
"Pedicels",
|
232
|
"flowering buds",
|
233
|
"scales",
|
234
|
"Buds",
|
235
|
"Flowers",
|
236
|
"Flower",
|
237
|
"Flowering",
|
238
|
"Stigma",
|
239
|
"perianth",
|
240
|
"Sepals",
|
241
|
"Sepal",
|
242
|
"Outer Sepals",
|
243
|
"Axillary",
|
244
|
"cymes",
|
245
|
"Calyx",
|
246
|
"Petal",
|
247
|
"Petals",
|
248
|
"perigone tube",
|
249
|
"Disc",
|
250
|
"corolla",
|
251
|
"Stamens",
|
252
|
"Staminodes",
|
253
|
"Ovary",
|
254
|
"Anthers",
|
255
|
"anther",
|
256
|
"Pistil",
|
257
|
"Pistillode",
|
258
|
"Ovules",
|
259
|
"androecium",
|
260
|
"gynoecium",
|
261
|
"Filaments",
|
262
|
"Style",
|
263
|
"annulus",
|
264
|
"female flowers",
|
265
|
"Male flowers",
|
266
|
"Female",
|
267
|
"Infructescences", //order not consistent (sometimes before "Flowers")
|
268
|
"Fruit",
|
269
|
"Fruits",
|
270
|
"fruiting axes",
|
271
|
"drupes",
|
272
|
"Arillode",
|
273
|
"seed",
|
274
|
"Seeds",
|
275
|
"Seedling",
|
276
|
"flower tube",
|
277
|
"nutlets",
|
278
|
"pollen",
|
279
|
"secondary xylem",
|
280
|
"chromosome number",
|
281
|
|
282
|
"figure",
|
283
|
"fig",
|
284
|
"figs",
|
285
|
|
286
|
|
287
|
|
288
|
|
289
|
};
|
290
|
|
291
|
public void addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
|
292
|
try {
|
293
|
for (String featureString : featureStringList){
|
294
|
UUID featureUuid;
|
295
|
featureUuid = transformer.getFeatureUuid(featureString);
|
296
|
Feature feature = (Feature)termService.find(featureUuid);
|
297
|
if (feature != null){
|
298
|
FeatureNode child = FeatureNode.NewInstance(feature);
|
299
|
root.addChild(child);
|
300
|
}
|
301
|
}
|
302
|
} catch (UndefinedTransformerMethodException e) {
|
303
|
logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
|
304
|
}
|
305
|
}
|
306
|
|
307
|
|
308
|
|
309
|
/**
|
310
|
* @param args
|
311
|
*/
|
312
|
public static void main(String[] args) {
|
313
|
CentralAfricaEricaceaeActivator me = new CentralAfricaEricaceaeActivator();
|
314
|
me.doImport(cdmDestination);
|
315
|
}
|
316
|
|
317
|
}
|