FdG sources
[cdmlib-apps.git] / cdm-eflora / src / main / java / eu / etaxonomy / cdm / app / eflora / FloraMalesianaVol13Activator.java
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.HashSet;
14 import java.util.List;
15 import java.util.Set;
16 import java.util.UUID;
17
18 import org.apache.log4j.Logger;
19 import org.springframework.transaction.TransactionStatus;
20
21 import eu.etaxonomy.cdm.api.service.ITermService;
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.events.IIoObserver;
27 import eu.etaxonomy.cdm.io.common.events.LoggingIoObserver;
28 import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
29 import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
30 import eu.etaxonomy.cdm.io.eflora.floraMalesiana.FloraMalesianaTransformer;
31 import eu.etaxonomy.cdm.io.markup.MarkupImportConfigurator;
32 import eu.etaxonomy.cdm.model.description.Feature;
33 import eu.etaxonomy.cdm.model.description.FeatureNode;
34 import eu.etaxonomy.cdm.model.description.FeatureTree;
35 import eu.etaxonomy.cdm.model.description.PolytomousKey;
36 import eu.etaxonomy.cdm.model.reference.Reference;
37 import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
38
39 /**
40 * @author a.mueller
41 * @created 20.06.2008
42 * @version 1.0
43 */
44 public class FloraMalesianaVol13Activator {
45 private static final Logger logger = Logger.getLogger(FloraMalesianaVol13Activator.class);
46
47 //database validation status (create, update, validate ...)
48 static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
49 static final URI fmSource13_small = EfloraSources.fm_13_small_families();
50 static final URI fmSource13_large = EfloraSources.fm_13_large_families();
51 static final URI fmSource12 = EfloraSources.fm_12();
52 static final URI fmSource2_2 = EfloraSources.fm_2_2();
53
54
55
56 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
57 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
58 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
59 static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
60 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
61 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
62
63 private boolean includeVol13_small = false;
64 private boolean includeVol13_large = false;
65 private boolean includeVol12 = false;
66 private boolean includeVol2_2 = true;
67
68 private boolean h2ForCheck = true;
69
70
71 //feature tree uuid
72 public static final UUID featureTreeUuid = UUID.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
73
74 //classification
75 static final UUID classificationUuid = UUID.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
76
77 //check - import
78 static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
79
80 static boolean doPrintKeys = false;
81
82 //taxa
83 static final boolean doTaxa = true;
84
85
86 private boolean replaceStandardKeyTitles = false;
87
88 private IIoObserver observer = new LoggingIoObserver();
89 private Set<IIoObserver> observerList = new HashSet<IIoObserver>();
90
91
92 private void doImport(ICdmDataSource cdmDestination){
93 observerList.add(observer);
94 if (h2ForCheck && cdmDestination.getDatabaseType().equals(CdmDestinations.localH2().getDatabaseType())){
95 check = CHECK.CHECK_ONLY;
96 }
97
98 //make Source
99 URI source = fmSource13_small;
100 MarkupImportConfigurator markupConfig= MarkupImportConfigurator.NewInstance(source, cdmDestination);
101 markupConfig.setClassificationUuid(classificationUuid);
102 markupConfig.setDoTaxa(doTaxa);
103 markupConfig.setCheck(check);
104 markupConfig.setDoPrintKeys(doPrintKeys);
105 markupConfig.setDbSchemaValidation(hbm2dll);
106 markupConfig.setObservers(observerList);
107 markupConfig.setReplaceStandardKeyTitles(replaceStandardKeyTitles);
108
109
110 markupConfig.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
111
112 CdmDefaultImport<MarkupImportConfigurator> myImport = new CdmDefaultImport<MarkupImportConfigurator>();
113
114 //Vol13_2
115 if (includeVol13_large){
116 System.out.println("\nStart import from ("+ fmSource13_large.toString() + ") ...");
117 source = fmSource13_large;
118 markupConfig.setSource(source);
119 myImport.invoke(markupConfig);
120 System.out.println("End import from ("+ fmSource13_large.toString() + ")...");
121 }
122
123 //Vol13_1
124 if (includeVol13_small){
125 System.out.println("\nStart import from ("+ fmSource13_small.toString() + ") ...");
126 source = fmSource13_small;
127 markupConfig.setSource(source);
128 myImport.invoke(markupConfig);
129 System.out.println("End import from ("+ fmSource13_small.toString() + ")...");
130 }
131
132 //Vol12
133 if (includeVol12){
134 source = fmSource12;
135 System.out.println("\nStart import from ("+ source.toString() + ") ...");
136 markupConfig.setSource(source);
137 myImport.invoke(markupConfig);
138 System.out.println("End import from ("+ source.toString() + ")...");
139 }
140 //Vol_2_2
141 if (includeVol2_2){
142 source = fmSource2_2;
143 System.out.println("\nStart import from ("+ source.toString() + ") ...");
144 markupConfig.setSource(source);
145 myImport.invoke(markupConfig);
146 System.out.println("End import from ("+ source.toString() + ")...");
147 }
148
149
150 // makeGeoService();
151
152 FeatureTree tree = makeFeatureNode(myImport.getCdmAppController().getTermService());
153 myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
154
155 //check keys
156 if (doPrintKeys){
157 TransactionStatus tx = myImport.getCdmAppController().startTransaction();
158 List<PolytomousKey> keys = myImport.getCdmAppController().getPolytomousKeyService().list(PolytomousKey.class, null, null, null, null);
159 for(PolytomousKey key : keys){
160 key.print(System.out);
161 System.out.println();
162 }
163 myImport.getCdmAppController().commitTransaction(tx);
164 }
165
166 }
167
168 private Reference getSourceReference(String string) {
169 Reference result = ReferenceFactory.newGeneric();
170 result.setTitleCache(string);
171 return result;
172 }
173
174 private FeatureTree makeFeatureNode(ITermService service){
175 FloraMalesianaTransformer transformer = new FloraMalesianaTransformer();
176
177 FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
178 result.setTitleCache("Flora Malesiana Presentation Feature Tree");
179 FeatureNode root = result.getRoot();
180 FeatureNode newNode;
181
182 newNode = FeatureNode.NewInstance(Feature.DESCRIPTION());
183 root.addChild(newNode);
184
185 addFeataureNodesByStringList(descriptionFeatureList, newNode, transformer, service);
186
187 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList, root, transformer, service);
188 newNode = FeatureNode.NewInstance(Feature.ANATOMY());
189 addFeataureNodesByStringList(anatomySubfeatureList, newNode, transformer, service);
190
191 newNode = addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList, root, transformer, service);
192 addFeataureNodesByStringList(phytoChemoSubFeaturesList, newNode, transformer, service);
193
194 newNode = addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList, root, transformer, service);
195
196
197 newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
198 root.addChild(newNode);
199
200 newNode = FeatureNode.NewInstance(Feature.ECOLOGY());
201 root.addChild(newNode);
202 addFeataureNodesByStringList(habitatEcologyList, root, transformer, service);
203
204 newNode = FeatureNode.NewInstance(Feature.USES());
205 root.addChild(newNode);
206
207 addFeataureNodesByStringList(chomosomesList, root, transformer, service);
208
209 newNode = FeatureNode.NewInstance(Feature.CITATION());
210 root.addChild(newNode);
211
212 return result;
213 }
214
215 private static String [] chomosomesList = new String[]{
216 "Chromosomes",
217 };
218
219
220 private static String [] habitatEcologyList = new String[]{
221 "Habitat",
222 "Habitat & Ecology"
223 };
224
225
226 private static String [] generellDescriptionsUpToAnatomyList = new String[]{
227 "Fossils",
228 "Morphology and anatomy",
229 "Morphology",
230 "Vegetative morphology and anatomy",
231 };
232
233
234 private static String [] anatomySubfeatureList = new String[]{
235 "Leaf anatomy",
236 "Wood anatomy"
237 };
238
239 private static String [] generellDescriptionsFromAnatomyToPhytoChemoList = new String[]{
240 "Flower morphology",
241 "Palynology",
242 "Pollination",
243 "Pollen morphology",
244 "embryology",
245 "cytology",
246 "Life cycle",
247 "Fruits and embryology",
248 "Dispersal",
249 "Chromosome numbers",
250 "Phytochemistry and Chemotaxonomy",
251 };
252
253
254 private static String [] phytoChemoSubFeaturesList = new String[]{
255 "Alkaloids",
256 "Iridoid glucosides",
257 "Leaf phenolics",
258 "Storage products of seeds",
259 "Aluminium",
260 "Chemotaxonomy",
261 };
262
263
264 private static String [] generellDescriptionsFromPhytoChemoList = new String[]{
265 "Phytochemistry",
266 "Taxonomy",
267 "history",
268 "cultivation",
269 "Notes"
270 };
271
272
273 private static String [] descriptionFeatureList = new String[]{
274 "lifeform",
275 "Bark",
276 //new
277 "wood",
278 "Indumentum",
279 "endophytic body",
280 "flowering buds",
281 "Branchlets",
282 "Branches",
283 "Branch",
284 "Flowering branchlets",
285 "Trees",
286 "Twigs",
287 "stem",
288 "Stems",
289 "stem leaves",
290 "Leaves",
291 "flower-bearing stems",
292 "Petiole",
293 "Petiolules",
294 "Leaflets",
295 "Thyrsus",
296 "Thyrses",
297 "Inflorescences",
298 "Inflorescence",
299 "Young inflorescences",
300 "Male inflorescences",
301 "Female inflorescences",
302 "Bracts",
303 "Pedicels",
304 "flowering buds",
305 "scales",
306 "Buds",
307 "Flowers",
308 "Flower",
309 "Flowering",
310 "Stigma",
311 "perianth",
312 "Sepals",
313 "Sepal",
314 "Outer Sepals",
315 "Axillary",
316 "cymes",
317 "Calyx",
318 "Petal",
319 "Petals",
320 "perigone",
321 "perigone lobes",
322 "perigone tube",
323 "Disc",
324 "corolla",
325 "Stamens",
326 "Staminodes",
327 "Ovary",
328 "Anthers",
329 "anther",
330 "Pistil",
331 "Pistillode",
332 "Ovules",
333 "androecium",
334 "gynoecium",
335 "Filaments",
336 "Style",
337 "annulus",
338 "female flowers",
339 "Male flowers",
340 "Female",
341 "Infructescences", //order not consistent (sometimes before "Flowers")
342 "Fruit",
343 "Fruits",
344 "fruiting axes",
345 "drupes",
346 "Arillode",
347 "seed",
348 "Seeds",
349 "Seedling",
350 "flower tube",
351 "nutlets",
352 "pollen",
353 "secondary xylem",
354 "chromosome number",
355
356 "figure",
357 "fig",
358 "figs",
359
360
361
362 };
363
364 public FeatureNode addFeataureNodesByStringList(String[] featureStringList, FeatureNode root, IInputTransformer transformer, ITermService termService){
365 FeatureNode lastChild = null;
366 try {
367 for (String featureString : featureStringList){
368 UUID featureUuid;
369 featureUuid = transformer.getFeatureUuid(featureString);
370 Feature feature = (Feature)termService.find(featureUuid);
371 if (feature != null){
372 FeatureNode child = FeatureNode.NewInstance(feature);
373 root.addChild(child);
374 }
375 }
376
377 } catch (UndefinedTransformerMethodException e) {
378 logger.error("getFeatureUuid is not implemented in transformer. Features could not be added");
379 }
380 return lastChild;
381 }
382
383
384
385 /**
386 * @param args
387 */
388 public static void main(String[] args) {
389 FloraMalesianaVol13Activator me = new FloraMalesianaVol13Activator();
390 me.doImport(cdmDestination);
391 }
392
393 }