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
.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
;
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 fg_sample
= EfloraSources
.fg_sample();
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();
59 public static final UUID featureTreeUuid
= UUID
.fromString("ee688973-2595-4d4d-b11e-6df71e96a5c2");
62 static final UUID classificationUuid
= UUID
.fromString("2f892452-ff49-48cf-834f-52ca29600719");
65 private boolean h2ForCheck
= true;
66 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
68 static boolean doPrintKeys
= false;
71 static final boolean doTaxa
= true;
73 private boolean includeFgSample
= true;
77 private boolean replaceStandardKeyTitles
= false;
79 private IIoObserver observer
= new LoggingIoObserver();
80 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
83 private void doImport(ICdmDataSource cdmDestination
){
84 observerList
.add(observer
);
85 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
86 check
= CHECK
.CHECK_ONLY
;
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
);
101 markupConfig
.setSourceReference(getSourceReference("Flore Gabon - Sample"));
103 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
106 if (includeFgSample
){
107 System
.out
.println("\nStart import from ("+ fg_sample
.toString() + ") ...");
109 markupConfig
.setSource(source
);
110 myImport
.invoke(markupConfig
);
111 System
.out
.println("End import from ("+ fg_sample
.toString() + ")...");
119 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
120 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
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();
130 myImport
.getCdmAppController().commitTransaction(tx
);
135 private Reference
<?
> getSourceReference(String string
) {
136 Reference
<?
> result
= ReferenceFactory
.newGeneric();
137 result
.setTitleCache(string
);
141 private FeatureTree
makeFeatureNode(ITermService service
){
142 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
144 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
145 result
.setTitleCache("Flore Gabon Presentation Feature Tree");
146 FeatureNode root
= result
.getRoot();
149 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
150 root
.addChild(newNode
);
152 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
154 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
155 newNode
= FeatureNode
.NewInstance(Feature
.ANATOMY());
156 addFeataureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
158 newNode
= addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
159 addFeataureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
161 newNode
= addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
164 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
165 root
.addChild(newNode
);
167 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
168 root
.addChild(newNode
);
169 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
171 newNode
= FeatureNode
.NewInstance(Feature
.USES());
172 root
.addChild(newNode
);
174 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
176 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
177 root
.addChild(newNode
);
182 private static String
[] chomosomesList
= new String
[]{
187 private static String
[] habitatEcologyList
= new String
[]{
193 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
195 "Morphology and anatomy",
197 "Vegetative morphology and anatomy",
201 private static String
[] anatomySubfeatureList
= new String
[]{
206 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
214 "Fruits and embryology",
216 "Chromosome numbers",
217 "Phytochemistry and Chemotaxonomy",
221 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
223 "Iridoid glucosides",
225 "Storage products of seeds",
231 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
240 private static String
[] descriptionFeatureList
= new String
[]{
251 "Flowering branchlets",
258 "flower-bearing stems",
266 "Young inflorescences",
267 "Male inflorescences",
268 "Female inflorescences",
308 "Infructescences", //order not consistent (sometimes before "Flowers")
331 public FeatureNode
addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
332 FeatureNode lastChild
= null;
334 for (String featureString
: featureStringList
){
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
);
344 } catch (UndefinedTransformerMethodException e
) {
345 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
355 public static void main(String
[] args
) {
356 FloreGabonActivator me
= new FloreGabonActivator();
357 me
.doImport(cdmDestination
);