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
.app
.common
.CdmDestinations
;
23 import eu
.etaxonomy
.cdm
.database
.DbSchemaValidation
;
24 import eu
.etaxonomy
.cdm
.database
.ICdmDataSource
;
25 import eu
.etaxonomy
.cdm
.io
.common
.CdmDefaultImport
;
26 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
.CHECK
;
27 import eu
.etaxonomy
.cdm
.io
.common
.events
.IIoObserver
;
28 import eu
.etaxonomy
.cdm
.io
.common
.events
.LoggingIoObserver
;
29 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
30 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.UndefinedTransformerMethodException
;
31 import eu
.etaxonomy
.cdm
.io
.eflora
.floraMalesiana
.FloraMalesianaTransformer
;
32 import eu
.etaxonomy
.cdm
.io
.markup
.MarkupImportConfigurator
;
33 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
34 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
35 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
36 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
37 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
45 public class FloraMalesianaVol13Activator
{
46 private static final Logger logger
= Logger
.getLogger(FloraMalesianaVol13Activator
.class);
48 //database validation status (create, update, validate ...)
49 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
50 static final URI fmSource13_small
= EfloraSources
.fm_13_small_families();
51 static final URI fmSource13_large
= EfloraSources
.fm_13_large_families();
54 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
55 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
56 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
57 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2();
58 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
59 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
61 private boolean includeVol13_small
= true;
62 private boolean includeVol13_large
= true;
64 private boolean h2ForCheck
= true;
68 public static final UUID featureTreeUuid
= UUID
.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
71 static final UUID classificationUuid
= UUID
.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
74 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
76 static boolean doPrintKeys
= false;
79 static final boolean doTaxa
= true;
82 private boolean replaceStandardKeyTitles
= false;
84 private IIoObserver observer
= new LoggingIoObserver();
85 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
88 private void doImport(ICdmDataSource cdmDestination
){
89 observerList
.add(observer
);
90 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
91 check
= CHECK
.CHECK_ONLY
;
95 URI source
= fmSource13_small
;
96 MarkupImportConfigurator markupConfig
= MarkupImportConfigurator
.NewInstance(source
, cdmDestination
);
97 markupConfig
.setClassificationUuid(classificationUuid
);
98 markupConfig
.setDoTaxa(doTaxa
);
99 markupConfig
.setCheck(check
);
100 markupConfig
.setDoPrintKeys(doPrintKeys
);
101 markupConfig
.setDbSchemaValidation(hbm2dll
);
102 markupConfig
.setObservers(observerList
);
103 markupConfig
.setReplaceStandardKeyTitles(replaceStandardKeyTitles
);
106 markupConfig
.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
108 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
111 if (includeVol13_large
){
112 System
.out
.println("\nStart import from ("+ fmSource13_large
.toString() + ") ...");
113 source
= fmSource13_large
;
114 markupConfig
.setSource(source
);
115 myImport
.invoke(markupConfig
);
116 System
.out
.println("End import from ("+ fmSource13_large
.toString() + ")...");
120 if (includeVol13_small
){
121 System
.out
.println("\nStart import from ("+ fmSource13_small
.toString() + ") ...");
122 source
= fmSource13_small
;
123 markupConfig
.setSource(source
);
124 myImport
.invoke(markupConfig
);
125 System
.out
.println("End import from ("+ fmSource13_small
.toString() + ")...");
131 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
132 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
136 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
137 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
138 for(PolytomousKey key
: keys
){
139 key
.print(System
.out
);
140 System
.out
.println();
142 myImport
.getCdmAppController().commitTransaction(tx
);
147 private Reference
getSourceReference(String string
) {
148 Reference result
= ReferenceFactory
.newGeneric();
149 result
.setTitleCache(string
);
153 private FeatureTree
makeFeatureNode(ITermService service
){
154 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
156 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
157 result
.setTitleCache("Flora Malesiana Presentation Feature Tree");
158 FeatureNode root
= result
.getRoot();
161 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
162 root
.addChild(newNode
);
164 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
166 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
167 newNode
= FeatureNode
.NewInstance(Feature
.ANATOMY());
168 addFeataureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
170 newNode
= addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
171 addFeataureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
173 newNode
= addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
176 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
177 root
.addChild(newNode
);
179 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
180 root
.addChild(newNode
);
181 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
183 newNode
= FeatureNode
.NewInstance(Feature
.USES());
184 root
.addChild(newNode
);
186 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
188 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
189 root
.addChild(newNode
);
194 private static String
[] chomosomesList
= new String
[]{
199 private static String
[] habitatEcologyList
= new String
[]{
205 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
207 "Morphology and anatomy",
209 "Vegetative morphology and anatomy",
213 private static String
[] anatomySubfeatureList
= new String
[]{
218 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
226 "Fruits and embryology",
228 "Chromosome numbers",
229 "Phytochemistry and Chemotaxonomy",
233 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
235 "Iridoid glucosides",
237 "Storage products of seeds",
243 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
252 private static String
[] descriptionFeatureList
= new String
[]{
263 "Flowering branchlets",
270 "flower-bearing stems",
278 "Young inflorescences",
279 "Male inflorescences",
280 "Female inflorescences",
320 "Infructescences", //order not consistent (sometimes before "Flowers")
343 public FeatureNode
addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
344 FeatureNode lastChild
= null;
346 for (String featureString
: featureStringList
){
348 featureUuid
= transformer
.getFeatureUuid(featureString
);
349 Feature feature
= (Feature
)termService
.find(featureUuid
);
350 if (feature
!= null){
351 FeatureNode child
= FeatureNode
.NewInstance(feature
);
352 root
.addChild(child
);
356 } catch (UndefinedTransformerMethodException e
) {
357 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
367 public static void main(String
[] args
) {
368 FloraMalesianaVol13Activator me
= new FloraMalesianaVol13Activator();
369 me
.doImport(cdmDestination
);