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 FloraMalesianaVol13Activator
{
45 private static final Logger logger
= Logger
.getLogger(FloraMalesianaVol13Activator
.class);
47 //database validation status (create, update, validate ...)
48 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
49 static final URI fmSource13_small
= EfloraSources
.fm_13_small_families();
50 static final URI fmSource13_large
= EfloraSources
.fm_13_large_families();
51 static final URI fmSource12
= EfloraSources
.fm_12();
52 static final URI fmSource2_2
= EfloraSources
.fm_2_2();
56 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_andreasM3();
57 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
58 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
59 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2();
60 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
61 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
63 private boolean includeVol13_small
= false;
64 private boolean includeVol13_large
= false;
65 private boolean includeVol12
= false;
66 private boolean includeVol2_2
= true;
68 private boolean h2ForCheck
= true;
72 public static final UUID featureTreeUuid
= UUID
.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
75 static final UUID classificationUuid
= UUID
.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
78 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
80 static boolean doPrintKeys
= false;
83 static final boolean doTaxa
= true;
86 private boolean replaceStandardKeyTitles
= false;
88 private IIoObserver observer
= new LoggingIoObserver();
89 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
92 private void doImport(ICdmDataSource cdmDestination
){
93 observerList
.add(observer
);
94 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
95 check
= CHECK
.CHECK_ONLY
;
99 URI source
= fmSource13_small
;
100 MarkupImportConfigurator markupConfig
= MarkupImportConfigurator
.NewInstance(source
, cdmDestination
);
101 markupConfig
.setClassificationUuid(classificationUuid
);
102 markupConfig
.setDoTaxa(doTaxa
);
103 markupConfig
.setCheck(check
);
104 markupConfig
.setDoPrintKeys(doPrintKeys
);
105 markupConfig
.setDbSchemaValidation(hbm2dll
);
106 markupConfig
.setObservers(observerList
);
107 markupConfig
.setReplaceStandardKeyTitles(replaceStandardKeyTitles
);
110 markupConfig
.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
112 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
115 if (includeVol13_large
){
116 System
.out
.println("\nStart import from ("+ fmSource13_large
.toString() + ") ...");
117 source
= fmSource13_large
;
118 markupConfig
.setSource(source
);
119 myImport
.invoke(markupConfig
);
120 System
.out
.println("End import from ("+ fmSource13_large
.toString() + ")...");
124 if (includeVol13_small
){
125 System
.out
.println("\nStart import from ("+ fmSource13_small
.toString() + ") ...");
126 source
= fmSource13_small
;
127 markupConfig
.setSource(source
);
128 myImport
.invoke(markupConfig
);
129 System
.out
.println("End import from ("+ fmSource13_small
.toString() + ")...");
135 System
.out
.println("\nStart import from ("+ source
.toString() + ") ...");
136 markupConfig
.setSource(source
);
137 myImport
.invoke(markupConfig
);
138 System
.out
.println("End import from ("+ source
.toString() + ")...");
142 source
= fmSource2_2
;
143 System
.out
.println("\nStart import from ("+ source
.toString() + ") ...");
144 markupConfig
.setSource(source
);
145 myImport
.invoke(markupConfig
);
146 System
.out
.println("End import from ("+ source
.toString() + ")...");
152 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
153 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
157 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
158 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
159 for(PolytomousKey key
: keys
){
160 key
.print(System
.out
);
161 System
.out
.println();
163 myImport
.getCdmAppController().commitTransaction(tx
);
168 private Reference
getSourceReference(String string
) {
169 Reference result
= ReferenceFactory
.newGeneric();
170 result
.setTitleCache(string
);
174 private FeatureTree
makeFeatureNode(ITermService service
){
175 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
177 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
178 result
.setTitleCache("Flora Malesiana Presentation Feature Tree");
179 FeatureNode root
= result
.getRoot();
182 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
183 root
.addChild(newNode
);
185 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
187 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
188 newNode
= FeatureNode
.NewInstance(Feature
.ANATOMY());
189 addFeataureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
191 newNode
= addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
192 addFeataureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
194 newNode
= addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
197 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
198 root
.addChild(newNode
);
200 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
201 root
.addChild(newNode
);
202 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
204 newNode
= FeatureNode
.NewInstance(Feature
.USES());
205 root
.addChild(newNode
);
207 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
209 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
210 root
.addChild(newNode
);
215 private static String
[] chomosomesList
= new String
[]{
220 private static String
[] habitatEcologyList
= new String
[]{
226 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
228 "Morphology and anatomy",
230 "Vegetative morphology and anatomy",
234 private static String
[] anatomySubfeatureList
= new String
[]{
239 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
247 "Fruits and embryology",
249 "Chromosome numbers",
250 "Phytochemistry and Chemotaxonomy",
254 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
256 "Iridoid glucosides",
258 "Storage products of seeds",
264 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
273 private static String
[] descriptionFeatureList
= new String
[]{
284 "Flowering branchlets",
291 "flower-bearing stems",
299 "Young inflorescences",
300 "Male inflorescences",
301 "Female inflorescences",
341 "Infructescences", //order not consistent (sometimes before "Flowers")
364 public FeatureNode
addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
365 FeatureNode lastChild
= null;
367 for (String featureString
: featureStringList
){
369 featureUuid
= transformer
.getFeatureUuid(featureString
);
370 Feature feature
= (Feature
)termService
.find(featureUuid
);
371 if (feature
!= null){
372 FeatureNode child
= FeatureNode
.NewInstance(feature
);
373 root
.addChild(child
);
377 } catch (UndefinedTransformerMethodException e
) {
378 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
388 public static void main(String
[] args
) {
389 FloraMalesianaVol13Activator me
= new FloraMalesianaVol13Activator();
390 me
.doImport(cdmDestination
);