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