2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.app
.eflora
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import org
.apache
.log4j
.Logger
;
19 import org
.springframework
.transaction
.TransactionStatus
;
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
;
44 public class FloreGabonActivator
{
45 private static final Logger logger
= Logger
.getLogger(FloreGabonActivator
.class);
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();
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();
63 public static final UUID featureTreeUuid
= UUID
.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
66 static final UUID classificationUuid
= UUID
.fromString("2f892452-ff49-48cf-834f-52ca29600719");
69 private boolean h2ForCheck
= false;
70 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
72 static boolean doPrintKeys
= false;
75 static final boolean doTaxa
= true;
77 private boolean includeFdg1
= true;
78 private boolean includeFdg2
= true;
79 private boolean includeFdg3
= true;
80 private boolean includeFdg4
= true;
83 private boolean replaceStandardKeyTitles
= false;
85 private IIoObserver observer
= new LoggingIoObserver();
86 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
89 private void doImport(ICdmDataSource cdmDestination
){
90 observerList
.add(observer
);
91 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
92 check
= CHECK
.CHECK_ONLY
;
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
);
107 markupConfig
.setSourceReference(getSourceReference("Flore du Gabon"));
109 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
113 System
.out
.println("\nStart import from ("+ fdg1
.toString() + ") ...");
115 markupConfig
.setSource(source
);
116 myImport
.invoke(markupConfig
);
117 System
.out
.println("End import from ("+ fdg1
.toString() + ")...");
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() + ")...");
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() + ")...");
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() + ")...");
147 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
148 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
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();
158 myImport
.getCdmAppController().commitTransaction(tx
);
163 private Reference
<?
> getSourceReference(String string
) {
164 Reference
<?
> result
= ReferenceFactory
.newGeneric();
165 result
.setTitleCache(string
);
169 private FeatureTree
makeFeatureNode(ITermService service
){
170 MarkupTransformer transformer
= new MarkupTransformer();
172 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
173 result
.setTitleCache("Flore Gabon Presentation Feature Tree");
174 FeatureNode root
= result
.getRoot();
177 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
178 root
.addChild(newNode
);
180 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
182 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
183 newNode
= FeatureNode
.NewInstance(Feature
.ANATOMY());
184 addFeataureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
186 newNode
= addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
187 addFeataureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
189 newNode
= addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
191 newNode
= FeatureNode
.NewInstance(Feature
.COMMON_NAME());
192 root
.addChild(newNode
);
194 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
195 root
.addChild(newNode
);
197 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
198 root
.addChild(newNode
);
199 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
201 newNode
= FeatureNode
.NewInstance(Feature
.USES());
202 root
.addChild(newNode
);
204 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
206 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
207 root
.addChild(newNode
);
212 private static String
[] chomosomesList
= new String
[]{
217 private static String
[] habitatEcologyList
= new String
[]{
223 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
225 "Morphology and anatomy",
227 "Vegetative morphology and anatomy",
231 private static String
[] anatomySubfeatureList
= new String
[]{
236 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
244 "Fruits and embryology",
246 "Chromosome numbers",
247 "Phytochemistry and Chemotaxonomy",
251 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
253 "Iridoid glucosides",
255 "Storage products of seeds",
261 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
270 private static String
[] descriptionFeatureList
= new String
[]{
283 "Flowering branchlets",
290 "extraxylary sclerenchyma",
291 "flower-bearing stems",
299 "Intersecondary veins",
305 "Young inflorescences",
306 "Male inflorescences",
307 "Female inflorescences",
350 "Infructescences", //order not consistent (sometimes before "Flowers")
373 public FeatureNode
addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
374 FeatureNode lastChild
= null;
376 for (String featureString
: featureStringList
){
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
);
386 } catch (UndefinedTransformerMethodException e
) {
387 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
397 public static void main(String
[] args
) {
398 FloreGabonActivator me
= new FloreGabonActivator();
399 me
.doImport(cdmDestination
);