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