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();
62 public static final UUID featureTreeUuid
= UUID
.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
65 static final UUID classificationUuid
= UUID
.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
68 static final CHECK check
= CHECK
.CHECK_AND_IMPORT
;
70 static boolean doPrintKeys
= false;
73 static final boolean doTaxa
= true;
75 private boolean includeVol13_small
= true;
76 private boolean includeVol13_large
= false;
78 private IIoObserver observer
= new LoggingIoObserver();
79 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
82 private void doImport(ICdmDataSource cdmDestination
){
83 observerList
.add(observer
);
86 URI source
= fmSource13_small
;
87 MarkupImportConfigurator markupConfig
= MarkupImportConfigurator
.NewInstance(source
, cdmDestination
);
88 markupConfig
.setClassificationUuid(classificationUuid
);
89 markupConfig
.setDoTaxa(doTaxa
);
90 markupConfig
.setCheck(check
);
91 markupConfig
.setDoPrintKeys(doPrintKeys
);
92 markupConfig
.setDbSchemaValidation(hbm2dll
);
93 markupConfig
.setObservers(observerList
);
95 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
98 markupConfig
.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
100 if (includeVol13_small
){
101 System
.out
.println("\nStart import from ("+ fmSource13_small
.toString() + ") ...");
102 source
= fmSource13_small
;
103 markupConfig
.setSource(source
);
104 myImport
.invoke(markupConfig
);
105 System
.out
.println("End import from ("+ fmSource13_small
.toString() + ")...");
109 if (includeVol13_large
){
110 System
.out
.println("\nStart import from ("+ fmSource13_large
.toString() + ") ...");
111 source
= fmSource13_large
;
112 markupConfig
.setSource(source
);
113 myImport
.invoke(markupConfig
);
114 System
.out
.println("End import from ("+ fmSource13_large
.toString() + ")...");
117 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
118 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
122 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
123 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
124 for(PolytomousKey key
: keys
){
125 key
.print(System
.out
);
126 System
.out
.println();
128 myImport
.getCdmAppController().commitTransaction(tx
);
133 private Reference
getSourceReference(String string
) {
134 Reference result
= ReferenceFactory
.newGeneric();
135 result
.setTitleCache(string
);
139 private FeatureTree
makeFeatureNode(ITermService service
){
140 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
142 FeatureTree result
= FeatureTree
.NewInstance(featureTreeUuid
);
143 result
.setTitleCache("Flora Malesiana Presentation Feature Tree");
144 FeatureNode root
= result
.getRoot();
147 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
148 root
.addChild(newNode
);
150 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
152 addFeataureNodesByStringList(generellDescriptionsList
, root
, transformer
, service
);
155 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
156 root
.addChild(newNode
);
158 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
159 root
.addChild(newNode
);
160 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
162 newNode
= FeatureNode
.NewInstance(Feature
.USES());
163 root
.addChild(newNode
);
165 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
167 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
168 root
.addChild(newNode
);
173 private static String
[] chomosomesList
= new String
[]{
178 private static String
[] habitatEcologyList
= new String
[]{
184 private static String
[] generellDescriptionsList
= new String
[]{
186 "Morphology and anatomy",
188 "Vegetative morphology and anatomy",
194 "Fruits and embryology",
198 "Chromosome numbers",
199 "Phytochemistry and Chemotaxonomy",
204 private static String
[] descriptionFeatureList
= new String
[]{
213 "Flowering branchlets",
220 "flower-bearing stems",
228 "Young inflorescences",
266 "Infructescences", //order not consistent (sometimes before "Flowers")
290 public void addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
292 for (String featureString
: featureStringList
){
294 featureUuid
= transformer
.getFeatureUuid(featureString
);
295 Feature feature
= (Feature
)termService
.find(featureUuid
);
296 if (feature
!= null){
297 FeatureNode child
= FeatureNode
.NewInstance(feature
);
298 root
.addChild(child
);
301 } catch (UndefinedTransformerMethodException e
) {
302 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
311 public static void main(String
[] args
) {
312 FloraMalesianaVol13Activator me
= new FloraMalesianaVol13Activator();
313 me
.doImport(cdmDestination
);