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.
9 package eu
.etaxonomy
.cdm
.app
.eflora
;
11 import java
.util
.HashSet
;
12 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.logging
.log4j
.LogManager
;
17 import org
.apache
.logging
.log4j
.Logger
;
18 import org
.springframework
.transaction
.TransactionStatus
;
20 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
21 import eu
.etaxonomy
.cdm
.common
.URI
;
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
.PolytomousKey
;
34 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
35 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
36 import eu
.etaxonomy
.cdm
.model
.term
.TermNode
;
37 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
43 public class FloraMalesianaActivator
extends EfloraActivatorBase
{
45 private static Logger logger
= LogManager
.getLogger();
47 //database validation status (create, update, validate ...)
48 static DbSchemaValidation hbm2dll
= DbSchemaValidation
.CREATE
;
50 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_preview();
51 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_flora_malesiana_production();
52 static final ICdmDataSource cdmDestination
= CdmDestinations
.localH2();
53 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql();
54 // static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
56 private final boolean includeBase
= false;
60 //habitat: 6 syso, + ???
61 private final boolean includeVol04
= includeBase
;
64 private final boolean includeVol05
= includeBase
;
68 private final boolean includeVol06
= includeBase
;
71 //no syso, 120 lifecycle, few of them references! and figureRef?
72 private final boolean includeVol07_1
= includeBase
;
74 //keys: 1 nothofagus; 4 quercus
75 //12 syso, no uncovered, >>100 lifecycle, >10 references, figureRefs?
76 private final boolean includeVol07_2
= includeBase
;
78 //430 syso (10 subheadings),no uncovered, 43 figureRef, references and lifecycle
79 private final boolean includeVol07_3_09_1
= includeBase
;
81 //no syso, 14 lifecycle, 1 reference
82 private final boolean includeVol07_4
= includeBase
;
85 //no syso, 5 lifecycle
86 private final boolean includeVol08_1
= includeBase
;
88 //keys: 23 S. Moore -> Symplocos Moore (handle manually before import)
89 //4syso, <= uncovered, <150 lifecycle, figureRef and references
90 private final boolean includeVol08_2
= includeBase
;
93 private final boolean includeVol08_3
= includeBase
;
95 //184 syso!! (30 subheadings), <=3 uncovered, <50 lifecycle and figureRef
96 private final boolean includeVol09
= includeBase
;
98 //no syso, <= 5 uncovered, <=50 lifecycle
99 private final boolean includeVol10_1
= includeBase
;
101 //6 syso, <=3 uncovered, <50 lifecycle
102 private final boolean includeVol10_2
= includeBase
;
104 //2 syso habitats, 2 fast, many lifcycle
105 private final boolean includeVol10_3
= includeBase
;
107 //no syso, 1 uncovered, 1 figureRef, 10 lifecycle
108 private final boolean includeVol10_4
= includeBase
;
110 //keys: 1 manually (a sect. botrycephalae)
111 //no syso, <= 10 uncovered, < 100 lifecycle
112 private final boolean includeVol11_1
= includeBase
;
114 //keys: 2 cultivar groups (a cultivar group aggregatum; b cultivar group common onion)
115 //no syso, 1 uncovered, 1 lifecycle, 2 references
116 private final boolean includeVol11_2
= includeBase
;
119 //no syso habitat, <10 uncovered, > 100 lifecycles
120 private final boolean includeVol11_3
= includeBase
;
122 //keys: 10 apostrophs
123 //habitat: no syso, 200 - 400 uncovered, different types
124 private final boolean includeVol12
= includeBase
;
126 //keys: 1 manual (Loranthaceae)
127 //no syso, 1 uncovered habitat
128 private final boolean includeVol13
= includeBase
;
130 //no syso habitat, 100-150 uncovered, most of them flowering and fruiting lifecycle
131 private final boolean includeVol14
= includeBase
;
133 //no syso, 5 uncovered, 2 of them epiphytic
134 private final boolean includeVol15
= includeBase
;
136 //no syso, <= 60 uncovered, very different types
137 private final boolean includeVol16
= includeBase
;
140 //no syso, medium # uncovered habitat (some or)
141 private final boolean includeVol17
= includeBase
;
143 //no syso habitat, <20 uncovered
144 private final boolean includeVol18
= includeBase
;
146 //no syso habitat, <= 50 uncovered, mostly untagged lifecycle, some errors
147 private final boolean includeVol19
= includeBase
;
149 //no syso, < 20 uncovered, mostly untagged lifecycle
150 private final boolean includeVol20
= includeBase
;
152 //no syso, no covered, medium # lifecycle and very few references
153 private final boolean includeVol21
= ! includeBase
;
157 //2 manually, 9 non standard(?), 2 hybrids(?)
158 //no syso habitat, only figureRef and references as habitat issues
159 private final boolean includeVol2_1
= includeBase
;
162 //no syso, no habitat issue
163 private final boolean includeVol2_2
= includeBase
;
165 //no syso, 10-15 uncovered, 2 unexpected attributes: extra
166 private final boolean includeVol2_3
= includeBase
;
169 private final boolean includeVol2_4
= includeBase
;
172 static final URI fmSource04
= EfloraSources
.fm_04();
173 static final URI fmSource05
= EfloraSources
.fm_05();
174 static final URI fmSource06
= EfloraSources
.fm_06();
175 static final URI fmSource07_1
= EfloraSources
.fm_07_1();
176 static final URI fmSource07_2
= EfloraSources
.fm_07_2();
177 static final URI fmSource07_3_09_1
= EfloraSources
.fm_07_3_09_1();
178 static final URI fmSource07_4
= EfloraSources
.fm_07_4();
180 static final URI fmSource08_1
= EfloraSources
.fm_08_1();
181 static final URI fmSource08_2
= EfloraSources
.fm_08_2();
182 static final URI fmSource08_3
= EfloraSources
.fm_08_3();
184 static final URI fmSource09
= EfloraSources
.fm_09();
186 static final URI fmSource10_1
= EfloraSources
.fm_10_1();
187 static final URI fmSource10_2
= EfloraSources
.fm_10_2();
188 static final URI fmSource10_3
= EfloraSources
.fm_10_3();
189 static final URI fmSource10_4
= EfloraSources
.fm_10_4();
192 static final URI fmSource11_1
= EfloraSources
.fm_11_1();
193 static final URI fmSource11_2
= EfloraSources
.fm_11_2();
194 static final URI fmSource11_3
= EfloraSources
.fm_11_3();
195 static final URI fmSource12_1
= EfloraSources
.fm_12();
196 static final URI fmSource13
= EfloraSources
.fm_13();
197 static final URI fmSource14
= EfloraSources
.fm_14();
198 static final URI fmSource15
= EfloraSources
.fm_15();
199 static final URI fmSource16
= EfloraSources
.fm_16();
200 static final URI fmSource17
= EfloraSources
.fm_17();
201 static final URI fmSource17_1
= EfloraSources
.fm_17_1();
202 static final URI fmSource17_2
= EfloraSources
.fm_17_2();
203 static final URI fmSource18
= EfloraSources
.fm_18();
204 static final URI fmSource19
= EfloraSources
.fm_19();
205 static final URI fmSource20
= EfloraSources
.fm_20();
206 static final URI fmSource21
= EfloraSources
.fm_21();
208 static final URI fmSource_Ser2_01
= EfloraSources
.fm_ser2_1();
209 static final URI fmSource_Ser2_02
= EfloraSources
.fm_ser2_2();
210 static final URI fmSource_Ser2_03
= EfloraSources
.fm_ser2_3();
211 static final URI fmSource_Ser2_04
= EfloraSources
.fm_ser2_4();
213 private final boolean h2ForCheck
= true;
215 static final boolean reuseState
= true; //when running multiple imports
218 public static final UUID featureTreeUuid
= UUID
.fromString("168df0c6-6429-484c-b26f-ded1f7e44bd9");
219 private static final String featureTreeTitle
= "Flora Malesiana Presentation Feature Tree";
222 static final UUID classificationUuid
= UUID
.fromString("ca4e4bcb-a1d1-4124-a358-a3d3c41dd450");
223 static final String classificationTitle
= "Flora Malesiana";
226 static CHECK check
= CHECK
.IMPORT_WITHOUT_CHECK
;
228 static boolean doPrintKeys
= false;
231 static final boolean doTaxa
= true;
234 private final boolean replaceStandardKeyTitles
= false;
236 private final IIoObserver observer
= new LoggingIoObserver();
237 private final Set
<IIoObserver
> observerList
= new HashSet
<IIoObserver
>();
240 private void doImport(ICdmDataSource cdmDestination
){
241 observerList
.add(observer
);
242 if (h2ForCheck
&& cdmDestination
.getDatabaseType().equals(CdmDestinations
.localH2().getDatabaseType())){
243 check
= CHECK
.CHECK_ONLY
;
247 // URI source = fmSource13_small;
250 MarkupImportConfigurator markupConfig
= MarkupImportConfigurator
.NewInstance(source
, cdmDestination
);
251 markupConfig
.setClassificationUuid(classificationUuid
);
252 markupConfig
.setClassificationName(classificationTitle
);
253 markupConfig
.setDoTaxa(doTaxa
);
254 markupConfig
.setCheck(check
);
255 markupConfig
.setDoPrintKeys(doPrintKeys
);
256 markupConfig
.setDbSchemaValidation(hbm2dll
);
257 markupConfig
.setObservers(observerList
);
258 markupConfig
.setReplaceStandardKeyTitles(replaceStandardKeyTitles
);
259 markupConfig
.setReuseExistingState(reuseState
);
261 markupConfig
.setSourceReference(getSourceReference("Flora Malesiana - Vol. 13"));
263 CdmDefaultImport
<MarkupImportConfigurator
> myImport
= new CdmDefaultImport
<MarkupImportConfigurator
>();
266 doSource(includeVol04
, fmSource04
, "Flora Malesiana - vol. 4", markupConfig
, myImport
);
268 doSource(includeVol05
, fmSource05
, "Flora Malesiana - vol. 5", markupConfig
, myImport
);
270 doSource(includeVol06
, fmSource06
, "Flora Malesiana - vol. 6", markupConfig
, myImport
);
272 doSource(includeVol07_1
, fmSource07_1
, "Flora Malesiana - vol. 7, pt.1", markupConfig
, myImport
);
274 doSource(includeVol07_2
, fmSource07_2
, "Flora Malesiana - vol. 7, pt.2", markupConfig
, myImport
);
276 doSource(includeVol07_3_09_1
, fmSource07_3_09_1
, "Flora Malesiana - vol. 7, pt.3 and vol. 9 pt.1", markupConfig
, myImport
);
278 doSource(includeVol07_4
, fmSource07_4
, "Flora Malesiana - vol. 7, pt.4", markupConfig
, myImport
);
281 doSource(includeVol08_1
, fmSource08_1
, "Flora Malesiana - vol. 8, pt.1", markupConfig
, myImport
);
284 doSource(includeVol08_2
, fmSource08_2
, "Flora Malesiana - vol. 8, pt.2", markupConfig
, myImport
);
287 doSource(includeVol08_3
, fmSource08_3
, "Flora Malesiana - vol. 8, pt.3", markupConfig
, myImport
);
290 doSource(includeVol09
, fmSource09
, "Flora Malesiana - vol. 9", markupConfig
, myImport
);
293 doSource(includeVol10_1
, fmSource10_1
, "Flora Malesiana - vol. 10, pt.1", markupConfig
, myImport
);
296 doSource(includeVol10_2
, fmSource10_2
, "Flora Malesiana - vol. 10, pt.2", markupConfig
, myImport
);
299 doSource(includeVol10_3
, fmSource10_3
, "Flora Malesiana - vol. 10, pt.3", markupConfig
, myImport
);
302 doSource(includeVol10_4
, fmSource10_4
, "Flora Malesiana - vol. 10, pt.4", markupConfig
, myImport
);
305 doSource(includeVol11_1
, fmSource11_1
, "Flora Malesiana - vol. 11, pt.1", markupConfig
, myImport
);
308 doSource(includeVol11_2
, fmSource11_2
, "Flora Malesiana - vol. 11, pt.2", markupConfig
, myImport
);
311 doSource(includeVol11_3
, fmSource11_3
, "Flora Malesiana - vol. 11, pt.3", markupConfig
, myImport
);
314 doSource(includeVol12
, fmSource12_1
, "Flora Malesiana - vol. 12", markupConfig
, myImport
);
317 doSource(includeVol13
, fmSource13
, "Flora Malesiana - vol. 13", markupConfig
, myImport
);
320 doSource(includeVol14
, fmSource14
, "Flora Malesiana - vol. 14", markupConfig
, myImport
);
323 doSource(includeVol15
, fmSource15
, "Flora Malesiana - vol. 15", markupConfig
, myImport
);
326 doSource(includeVol16
, fmSource16
, "Flora Malesiana - vol. 16", markupConfig
, myImport
);
329 doSource(includeVol17
, fmSource17
, "Flora Malesiana - vol. 17, part I and II", markupConfig
, myImport
);
332 // doSource(includeVol17_1, fmSource17_1, "Flora Malesiana - vol. 17, part I", markupConfig, myImport);
335 // doSource(includeVol17_2, fmSource17_2, "Flora Malesiana - vol. 17, part II", markupConfig, myImport);
338 doSource(includeVol18
, fmSource18
, "Flora Malesiana - vol. 18", markupConfig
, myImport
);
341 doSource(includeVol19
, fmSource19
, "Flora Malesiana - vol. 19", markupConfig
, myImport
);
344 doSource(includeVol20
, fmSource20
, "Flora Malesiana - vol. 20", markupConfig
, myImport
);
347 doSource(includeVol21
, fmSource21
, "Flora Malesiana - vol. 21", markupConfig
, myImport
);
350 doSource(includeVol2_1
, fmSource_Ser2_01
, "Flora Malesiana - Ser.2, vol. 1", markupConfig
, myImport
);
353 doSource(includeVol2_2
, fmSource_Ser2_02
, "Flora Malesiana - Ser.2, vol. 2", markupConfig
, myImport
);
356 doSource(includeVol2_3
, fmSource_Ser2_03
, "Flora Malesiana - Ser.2, vol. 3", markupConfig
, myImport
);
359 doSource(includeVol2_4
, fmSource_Ser2_04
, "Flora Malesiana - Ser.2, vol. 4", markupConfig
, myImport
);
362 makeAutomatedFeatureTree(myImport
.getCdmAppController(), markupConfig
.getState(),
363 featureTreeUuid
, featureTreeTitle
);
367 TermTree
<Feature
> tree
= makeFeatureNode(myImport
.getCdmAppController().getTermService());
368 myImport
.getCdmAppController().getTermTreeService().saveOrUpdate(tree
);
372 TransactionStatus tx
= myImport
.getCdmAppController().startTransaction();
373 List
<PolytomousKey
> keys
= myImport
.getCdmAppController().getPolytomousKeyService().list(PolytomousKey
.class, null, null, null, null);
374 for(PolytomousKey key
: keys
){
375 key
.print(System
.out
);
376 System
.out
.println();
378 myImport
.getCdmAppController().commitTransaction(tx
);
383 private void doSource(boolean doInclude
, URI source
, String sourceTitle
, MarkupImportConfigurator markupConfig
,
384 CdmDefaultImport
<MarkupImportConfigurator
> myImport
) {
386 System
.out
.println("\nStart import from ("+ source
.toString() + ") ...");
387 markupConfig
.setSource(source
);
388 markupConfig
.setSourceReference(getSourceReference(sourceTitle
));
389 myImport
.invoke(markupConfig
);
390 System
.out
.println("End import from ("+ source
.toString() + ")...");
394 private Reference
getSourceReference(String string
) {
395 Reference result
= ReferenceFactory
.newGeneric();
396 result
.setTitleCache(string
, true);
400 private TermTree
<Feature
> makeFeatureNode(ITermService service
){
401 FloraMalesianaTransformer transformer
= new FloraMalesianaTransformer();
403 TermTree
<Feature
> result
= TermTree
.NewFeatureInstance(UUID
.randomUUID());
404 result
.setTitleCache("Flora Malesiana Presentation Feature Tree - Old", true);
405 TermNode
<Feature
> root
= result
.getRoot();
407 TermNode
<Feature
> newNode
= root
.addChild(Feature
.DESCRIPTION());
409 addFeatureNodesByStringList(descriptionFeatureList
, newNode
, transformer
, service
);
411 addFeatureNodesByStringList(generellDescriptionsUpToAnatomyList
, root
, transformer
, service
);
412 newNode
= root
.addChild(Feature
.ANATOMY()); //not sure if this is correct, but it looked like the node was orphaned before
413 addFeatureNodesByStringList(anatomySubfeatureList
, newNode
, transformer
, service
);
415 newNode
= addFeatureNodesByStringList(generellDescriptionsFromAnatomyToPhytoChemoList
, root
, transformer
, service
);
416 addFeatureNodesByStringList(phytoChemoSubFeaturesList
, newNode
, transformer
, service
);
418 newNode
= addFeatureNodesByStringList(generellDescriptionsFromPhytoChemoList
, root
, transformer
, service
);
421 newNode
= root
.addChild(Feature
.DISTRIBUTION());
423 newNode
= root
.addChild(Feature
.ECOLOGY());
424 addFeatureNodesByStringList(habitatEcologyList
, root
, transformer
, service
);
426 newNode
= root
.addChild(Feature
.USES());
428 addFeatureNodesByStringList(chomosomesList
, root
, transformer
, service
);
430 newNode
= root
.addChild(Feature
.CITATION());
435 private static String
[] chomosomesList
= new String
[]{
439 private static String
[] habitatEcologyList
= new String
[]{
444 private static String
[] generellDescriptionsUpToAnatomyList
= new String
[]{
446 "Morphology and anatomy",
448 "Vegetative morphology and anatomy",
451 private static String
[] anatomySubfeatureList
= new String
[]{
456 private static String
[] generellDescriptionsFromAnatomyToPhytoChemoList
= new String
[]{
464 "Fruits and embryology",
466 "Chromosome numbers",
467 "Phytochemistry and Chemotaxonomy",
470 private static String
[] phytoChemoSubFeaturesList
= new String
[]{
472 "Iridoid glucosides",
474 "Storage products of seeds",
479 private static String
[] generellDescriptionsFromPhytoChemoList
= new String
[]{
487 private static String
[] descriptionFeatureList
= new String
[]{
498 "Flowering branchlets",
505 "flower-bearing stems",
513 "Young inflorescences",
514 "Male inflorescences",
515 "Female inflorescences",
555 "Infructescences", //order not consistent (sometimes before "Flowers")
575 public TermNode
<Feature
> addFeatureNodesByStringList(String
[] featureStringList
,
576 TermNode
<Feature
> root
, IInputTransformer transformer
, ITermService termService
){
577 TermNode
<Feature
> lastChild
= null;
579 for (String featureString
: featureStringList
){
581 featureUuid
= transformer
.getFeatureUuid(featureString
);
582 Feature feature
= (Feature
)termService
.find(featureUuid
);
583 if (feature
!= null){
584 root
.addChild(feature
);
588 } catch (UndefinedTransformerMethodException e
) {
589 logger
.error("getFeatureUuid is not implemented in transformer. Features could not be added");
594 public static void main(String
[] args
) {
595 FloraMalesianaActivator me
= new FloraMalesianaActivator();
596 me
.doImport(cdmDestination
);