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
;
43 public class FloraMalesianaActivator
extends EfloraActivatorBase
{
44 private static final Logger logger
= Logger
.getLogger(FloraMalesianaActivator
.class);
46 //database validation status (create, update, validate ...)
47 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
49 static final URI fmSource12_1
= EfloraSources
.fm_12_1();
50 static final URI fmSource12_2
= EfloraSources
.fm_12_2();
51 static final URI fmSource13
= EfloraSources
.fm_13();
52 static final URI fmSource14
= EfloraSources
.fm_14();
53 static final URI fmSource15
= EfloraSources
.fm_15();
54 static final URI fmSource16
= EfloraSources
.fm_16();
55 static final URI fmSource17_1
= EfloraSources
.fm_17_1();
56 static final URI fmSource17_2
= EfloraSources
.fm_17_2();
57 static final URI fmSource18
= EfloraSources
.fm_18();
58 static final URI fmSource19
= EfloraSources
.fm_19();
59 static final URI fmSource20
= EfloraSources
.fm_20();
61 static final URI fmSource_Ser2_02
= EfloraSources
.fm_ser2_2();
62 static final URI fmSource_Ser2_03
= EfloraSources
.fm_ser2_3();
65 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
66 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
67 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2();
68 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
69 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
71 private boolean includeBase
= true;
72 private boolean includeVol12_1
= includeBase
;
73 private boolean includeVol12_2
= includeBase
;
74 private boolean includeVol13
= includeBase
;
75 private boolean includeVol14
= includeBase
;
76 private boolean includeVol15
= includeBase
;
77 private boolean includeVol16
= includeBase
;
78 private boolean includeVol17_1
= includeBase
;
79 private boolean includeVol17_2
= includeBase
;
80 private boolean includeVol18
= includeBase
;
81 private boolean includeVol19
= includeBase
;
82 private boolean includeVol20
= includeBase
;
83 private boolean includeVol2_2
= includeBase
;
84 private boolean includeVol2_3
= includeBase
;
86 private boolean h2ForCheck
= false;
88 static final boolean reuseState
= true; //when running multiple imports
92 public static final UUID featureTreeUuid
= UUID
.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
93 private static final String featureTreeTitle
= "Flora Malesiana Presentation Feature Tree";
96 static final UUID classificationUuid
= UUID
.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
97 static final String classificationTitle
= "Flora Malesiana";
100 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
102 static boolean doPrintKeys
= false;
105 static final boolean doTaxa
= true;
108 private boolean replaceStandardKeyTitles
= false;
110 private IIoObserver observer
= new LoggingIoObserver();
111 private Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
114 private void doImport(ICdmDataSource cdmDestination
){
115 observerList
.add(observer
);
116 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
117 check
= CHECK
.CHECK_ONLY
;
121 // URI source = fmSource13_small;
124 MarkupImportConfigurator markupConfig
= MarkupImportConfigurator
.NewInstance(source
, cdmDestination
);
125 markupConfig
.setClassificationUuid(classificationUuid
);
126 markupConfig
.setClassificationName(classificationTitle
);
127 markupConfig
.setDoTaxa(doTaxa
);
128 markupConfig
.setCheck(check
);
129 markupConfig
.setDoPrintKeys(doPrintKeys
);
130 markupConfig
.setDbSchemaValidation(hbm2dll
);
131 markupConfig
.setObservers(observerList
);
132 markupConfig
.setReplaceStandardKeyTitles(replaceStandardKeyTitles
);
133 markupConfig
.setReuseExistingState(reuseState
);
135 markupConfig
.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
137 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
142 doSource(includeVol16
, fmSource16
, "Flora Malesiana - vol. 16", markupConfig
, myImport
);
146 doSource(includeVol12_1
, fmSource12_1
, "Flora Malesiana - vol. 12, pt.1", markupConfig
, myImport
);
149 doSource(includeVol12_2
, fmSource12_2
, "Flora Malesiana - vol. 12, pt.2", markupConfig
, myImport
);
152 doSource(includeVol13
, fmSource13
, "Flora Malesiana - vol. 13", markupConfig
, myImport
);
155 doSource(includeVol14
, fmSource14
, "Flora Malesiana - vol. 14", markupConfig
, myImport
);
158 doSource(includeVol15
, fmSource15
, "Flora Malesiana - vol. 15", markupConfig
, myImport
);
160 doSource(includeVol17_1
, fmSource17_1
, "Flora Malesiana - vol. 17, part I", markupConfig
, myImport
);
163 doSource(includeVol17_2
, fmSource17_2
, "Flora Malesiana - vol. 17, part II", markupConfig
, myImport
);
166 doSource(includeVol18
, fmSource18
, "Flora Malesiana - vol. 18", markupConfig
, myImport
);
169 doSource(includeVol19
, fmSource19
, "Flora Malesiana - vol. 19", markupConfig
, myImport
);
172 doSource(includeVol20
, fmSource20
, "Flora Malesiana - vol. 20", markupConfig
, myImport
);
175 doSource(includeVol2_2
, fmSource_Ser2_02
, "Flora Malesiana - Ser.2, vol. 2", markupConfig
, myImport
);
178 doSource(includeVol2_3
, fmSource_Ser2_03
, "Flora Malesiana - Ser.2, vol. 3", markupConfig
, myImport
);
180 makeAutomatedFeatureTree(myImport
.getCdmAppController(), markupConfig
.getState(),
181 featureTreeUuid
, featureTreeTitle
);
185 FeatureTree tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
186 myImport
.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree
);
190 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
191 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
192 for(PolytomousKey key
: keys
){
193 key
.print(System
.out
);
194 System
.out
.println();
196 myImport
.getCdmAppController().commitTransaction(tx
);
201 private void doSource(boolean doInclude
, URI source
, String sourceTitle
, MarkupImportConfigurator markupConfig
,
202 CdmDefaultImport
<MarkupImportConfigurator
> myImport
) {
204 System
.out
.println("\nStart import from ("+ source
.toString() + ") ...");
205 markupConfig
.setSource(source
);
206 markupConfig
.setSourceReference(getSourceReference(sourceTitle
));
207 myImport
.invoke(markupConfig
);
208 System
.out
.println("End import from ("+ source
.toString() + ")...");
212 private Reference
<?
> getSourceReference(String string
) {
213 Reference
<?
> result
= ReferenceFactory
.newGeneric();
214 result
.setTitleCache(string
);
218 private FeatureTree
makeFeatureNode(ITermService service
){
219 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
221 FeatureTree result
= FeatureTree
.NewInstance(UUID
.randomUUID());
222 result
.setTitleCache("Flora Malesiana Presentation Feature Tree - Old");
223 FeatureNode root
= result
.getRoot();
226 newNode
= FeatureNode
.NewInstance(Feature
.DESCRIPTION());
227 root
.addChild(newNode
);
229 addFeataureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
231 addFeataureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
232 newNode
= FeatureNode
.NewInstance(Feature
.ANATOMY());
233 addFeataureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
235 newNode
= addFeataureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
236 addFeataureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
238 newNode
= addFeataureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
241 newNode
= FeatureNode
.NewInstance(Feature
.DISTRIBUTION());
242 root
.addChild(newNode
);
244 newNode
= FeatureNode
.NewInstance(Feature
.ECOLOGY());
245 root
.addChild(newNode
);
246 addFeataureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
248 newNode
= FeatureNode
.NewInstance(Feature
.USES());
249 root
.addChild(newNode
);
251 addFeataureNodesByStringList(chomosomesList
, root
, transformer
, service
);
253 newNode
= FeatureNode
.NewInstance(Feature
.CITATION());
254 root
.addChild(newNode
);
259 private static String
[] chomosomesList
= new String
[]{
264 private static String
[] habitatEcologyList
= new String
[]{
270 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
272 "Morphology and anatomy",
274 "Vegetative morphology and anatomy",
278 private static String
[] anatomySubfeatureList
= new String
[]{
283 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
291 "Fruits and embryology",
293 "Chromosome numbers",
294 "Phytochemistry and Chemotaxonomy",
298 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
300 "Iridoid glucosides",
302 "Storage products of seeds",
308 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
317 private static String
[] descriptionFeatureList
= new String
[]{
328 "Flowering branchlets",
335 "flower-bearing stems",
343 "Young inflorescences",
344 "Male inflorescences",
345 "Female inflorescences",
385 "Infructescences", //order not consistent (sometimes before "Flowers")
408 public FeatureNode
addFeataureNodesByStringList(String
[] featureStringList
, FeatureNode root
, IInputTransformer transformer
, ITermService termService
){
409 FeatureNode lastChild
= null;
411 for (String featureString
: featureStringList
){
413 featureUuid
= transformer
.getFeatureUuid(featureString
);
414 Feature feature
= (Feature
)termService
.find(featureUuid
);
415 if (feature
!= null){
416 FeatureNode child
= FeatureNode
.NewInstance(feature
);
417 root
.addChild(child
);
421 } catch (UndefinedTransformerMethodException e
) {
422 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
432 public static void main(String
[] args
) {
433 FloraMalesianaActivator me
= new FloraMalesianaActivator();
434 me
.doImport(cdmDestination
);