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